Rob Simmons avatar Rob Simmons committed e8c01dc

Mostly just cleaning up code and improving comments.

Comments (0)

Files changed (1)

pygments/lexers/functional.py

             (r'~?\d+', Number.Integer),                        
         ],
 
-        # The class Lab is extended to include the numeric labels 1 2 3,
-        # i.e. any numeral not starting with 0
+        # "The class Lab is extended to include the numeric labels 1 2 3,
+        # i.e. any numeral not starting with 0"
         'labels': [
             (r'#\s*[1-9][0-9]*', Name.Label),
             (r'#\s*(%s)' % alphanums, Name.Label),
             (r'%s' % '|'.join(keyopts), Operator),
         ],
 
+        # Delimiters define scopes, and the scope is how the meaning of 
+        # the `|' is resolved - is it a case/handle expression, or function
+        # definition by cases?
         'delimiters': [
-            (r'\(|\[|{', Operator, '#push'),
+            (r'\(|\[|{', Operator, 'main'),
             (r'\)|\]|}', Operator, '#pop'),
             (r'\b(let|if|local)\b(?!\')', Operator, ('main', 'main')),
             (r'\b(while)\b(?!\')', Operator, 'main'),
         ],
 
         # Main parser
-        'root': [ (r'', Text, 'main') ], # Always ping-pong up to main
+        # Always ping-pong up to main - in a syntactically valid program, this
+        # rule should be called precisely once. This desing should prevent
+        # errors from being raised in files that have scoping errors.
+        'root': [ (r'', Text, 'main') ], 
 
-        # In this scope, I expect "|" to be followed by a function name
+        # In this scope, I expect "|" to not be followed by a function name
         'main': [            
             (r'\s', Text),
             (r'\(\*', Comment.Multiline, 'comment'),
             include('identifier'),
         ],
 
-        # In this scope, I expect "|" to not be followed by a function name
+        # In this scope, I expect "|" to be followed by a function name
         'main-fun': [
             (r'\s', Text),
             (r'\(\*', Comment.Multiline, 'comment'),
             (r'\(\*', Comment.Multiline, 'comment'),
             (r'(%s)' % alphanums, Name.Function, '#pop'),
             (r'(%s)' % symbols, Name.Function, '#pop'), 
-            (r'', Text, '#pop'), # Funky fun declaration? Just give up.
+
+            # Funky fun declaration? Just give up.
+            # This handles infix cases like "fun (x + y) = ..."
+            (r'', Text, '#pop'), 
         ],
 
         # Dealing with what comes after most of the module system keywords
         'datbind': [
             (r'\s', Text),
             (r'\(\*', Comment.Multiline, 'comment'),
+
             (r'\band\b', Keyword.Reserved, ('#pop', 'dname')), # start again
             (r'\bof\b', Keyword.Reserved), # Only reserved word here?
             (r'(?=\b(%s)\b)' % '|'.join(all_kw), Text, '#pop'), # Done
 
             (r'\|', Operator, 'datcon'),
             (r'%s' % '|'.join(keyopts), Operator),
-
             include('identifier'),
         ],
 
         'datcon': [
             (r'\s', Text),
             (r'\(\*', Comment.Multiline, 'comment'),
+
             (r'(%s)' % alphanums, Name.Class, '#pop'),
             (r'(%s)' % symbols, Name.Class, '#pop'), 
         ],
         'tyvarseq': [
             (r'\s', Text),
             (r'\(\*', Comment.Multiline, 'comment'),
+
             (r'\'[0-9a-zA-Z_\']*', Name.Decorator),
             (r',', Operator),
             (r'\)', Operator, '#pop'),
             (r'\*\)', Comment.Multiline, '#pop'),
             (r'[(*)]', Comment.Multiline),
         ],
+
         'char': stringy(String.Char),
         'string': stringy(String.Double),
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.