Commits

Rob Simmons committed 3abb8ed

Teach the datatype, type, exeption, raise, fun, val, functor, open, signature, and structure keywords what always comes after them

Comments (0)

Files changed (2)

pygments/lexers/functional.py

     filenames = ['*.sml', '*.sig', '*.fun',]
     mimetypes = ['text/x-standard-ml']
 
+    # From the core language
     corekeywords = [
-      'abstype', 'and', 'andalso', 'as', 'case', 'datatype', 'do', 'else',
-      'end', 'exception', 'fn', 'fun', 'handle', 'if', 'in', 'infix', 
-      'infixr', 'let', 'local', 'nonfix', 'of', 'op', 'open', 'orelse',
-      'raise', 'rec', 'then', 'type', 'val', 'with', 'withtype', 'while'
+      'abstype', 'and', 'andalso', 'as', 'case', 'do', 'else',
+      'end', 'fn', 'handle', 'if', 'in', 'infix', 
+      'infixr', 'let', 'local', 'nonfix', 'of', 'op', 'orelse',
+      'rec', 'then', 'val', 'with', 'withtype', 'while'
     ]
-    sigkeywords = [
-      'eqtype', 'functor', 'include', 'sharing', 'sig', 'signature', 
-      'struct', 'structure', 'where'
-    ]
+
+    # From the module system
+    sigkeywords = [ 'eqtype', 'include', 'sharing', 'sig', 'struct', 'where' ]
+
+    # Reserved keywords that change the state
+    datatype_kw = [ 'datatype', 'type' ]
+    exn_kw = [ 'exception', 'raise' ]
+    fun_kw = [ 'fun' ]
+    val_kw = [ 'val' ]
+    struct_kw = [ 'functor', 'open', 'signature', 'structure' ]
 
     # It doesn't work to have keyopts overlap with symbolic identifiers
     keyopts = [
             (r'false|true|\(\)|\[\]', Keyword.Pseudo),
             (r'\b(%s)\b' % '|'.join(corekeywords), Keyword.Reserved),
             (r'\b(%s)\b' % '|'.join(sigkeywords), Keyword.Reserved),
+            (r'\b(%s)\b' % '|'.join(struct_kw), Keyword.Reserved, 'sdecs'),
+            (r'\b(%s)\b' % '|'.join(datatype_kw), Keyword.Reserved, 'tname'),
+            (r'\b(%s)\b' % '|'.join(fun_kw), Keyword.Reserved, 'fname'),
+            (r'\b(%s)\b' % '|'.join(exn_kw), Keyword.Reserved, 'ename'),
             (r'\b(%s)\b' % '|'.join(primitives), Keyword.Type),
             (r'\(\*', Comment.Multiline, 'comment'),
             (r'%s' % '|'.join(keyopts), Operator),
             # or symbolic: any non-empty sequence of the following symbols
             (r'(%s)' % symbols, Name), 
         ],
+        'fname': [
+            (r'\s', Text),
+            (r'(%s)' % alphanums, Name.Function, '#pop'),
+            (r'', Text, '#pop'),
+        ],
+        'ename': [
+            (r'\s', Text),
+            (r'(%s)' % alphanums, Name.Exception, '#pop'),
+            (r'', Text, '#pop'),
+        ],
+        'tname': [
+            (r'\s', Text),
+            (r'(\(|,|\))', Operator),
+            (r'\'[0-9a-zA-Z_\']*', Name.Decorator),
+            (r'(%s)' % alphanums, Keyword.Type, '#pop'),
+            (r'', Text, '#pop'),
+        ],
+        'sdecs': [
+            (r'\s', Text),
+            (r'(%s)' % alphanums, Name.Namespace),
+            (r'', Text, '#pop'),
+        ],
         'comment': [
             (r'[^(*)]', Comment.Multiline),
             (r'\(\*', Comment.Multiline, '#push'),

tests/examplefiles/example.sml

   end  
 end
 
+infixr +!+ 
+fun (a +!+ b) = (op +) (a, b)
+
 open baz
 
 val$$$ = fn x => fn y => fn z => fn w => w
 val z = #4 w
 val z = # ##= w
 
+fun f x y 0 = 4
+  | f x y z = 4 
+
+exception Foo of int
 datatype ('0, 'b, '_, ') fo'o = Bar | baZ12' | dsfa_fad | #@$
+   | and bar = Bee
+
+fun q x = raise Foo x
 
 val _ = 123
 val _ = 0001