Tim Hatch avatar Tim Hatch committed 2ca4eea

Style rework for Koka lexer.

Comments (0)

Files changed (2)

pygments/lexers/_mapping.py

     'JuliaConsoleLexer': ('pygments.lexers.math', 'Julia console', ('jlcon',), (), ()),
     'JuliaLexer': ('pygments.lexers.math', 'Julia', ('julia', 'jl'), ('*.jl',), ('text/x-julia', 'application/x-julia')),
     'KconfigLexer': ('pygments.lexers.other', 'Kconfig', ('kconfig', 'menuconfig', 'linux-config', 'kernel-config'), ('Kconfig', '*Config.in*', 'external.in*', 'standard-modules.in'), ('text/x-kconfig',)),
-    'KokaLexer':('pygments.lexers.functional', 'Koka', ('koka'), ('*.kk','*.kki'), ('text/x-koka')),    
+    'KokaLexer': ('pygments.lexers.functional', 'Koka', ('koka',), ('*.kk', '*.kki'), ('text/x-koka',)),
     'KotlinLexer': ('pygments.lexers.jvm', 'Kotlin', ('kotlin',), ('*.kt',), ('text/x-kotlin',)),
     'LassoCssLexer': ('pygments.lexers.templates', 'CSS+Lasso', ('css+lasso',), (), ('text/css+lasso',)),
     'LassoHtmlLexer': ('pygments.lexers.templates', 'HTML+Lasso', ('html+lasso',), (), ('text/html+lasso', 'application/x-httpd-lasso', 'application/x-httpd-lasso[89]')),

pygments/lexers/functional.py

 __all__ = ['RacketLexer', 'SchemeLexer', 'CommonLispLexer', 'HaskellLexer',
            'LiterateHaskellLexer', 'SMLLexer', 'OcamlLexer', 'ErlangLexer',
            'ErlangShellLexer', 'OpaLexer', 'CoqLexer', 'NewLispLexer',
-           'ElixirLexer', 'ElixirConsoleLexer', 'KokaLexer' ]
+           'ElixirLexer', 'ElixirConsoleLexer', 'KokaLexer']
 
 
 class RacketLexer(RegexLexer):
 
 class KokaLexer(RegexLexer):
     """
-    Lexer for the Koka language.
+    Lexer for the `Koka <http://research.microsoft.com/en-us/projects/koka/>`_
+    language.
+
+    *New in Pygments 1.6.*
     """
 
     name = 'Koka'
         'include', 'inline',
         'rec',
         'try', 'yield', 'enum',
-        'interface', 'instance'
+        'interface', 'instance',
     ]
 
     # keywords that are followed by a type
     typeStartKeywords = [
-        'type','cotype','rectype','alias','struct','enum'
+        'type', 'cotype', 'rectype', 'alias', 'struct', 'enum',
     ]
 
     # keywords valid in a type
     typekeywords = [
-        'forall', 'exists', 'some', 'with'      
+        'forall', 'exists', 'some', 'with',
     ]
 
     # builtin names and special names
         'for', 'while', 'repeat',
         'foreach', 'foreach-indexed', 
         'error', 'catch', 'finally',
-        'cs', 'js', 'file', 'ref', 'assigned'
+        'cs', 'js', 'file', 'ref', 'assigned',
     ]
 
     # symbols that can be in an operator
 
     # main lexer
     tokens = {
-        'root': [       
+        'root': [
             include('whitespace'),
 
             # go into type mode
-            (r'::?'+sboundary, Keyword.Type, 'type'),
-            (r'alias'+boundary, Keyword,'alias-type'),
-            (r'struct'+boundary, Keyword,'struct-type'),
-            (r'(%s)' % '|'.join(typeStartKeywords)+boundary, Keyword, 'type'),
+            (r'::?' + sboundary, Keyword.Type, 'type'),
+            (r'alias' + boundary, Keyword, 'alias-type'),
+            (r'struct' + boundary, Keyword, 'struct-type'),
+            (r'(%s)' % '|'.join(typeStartKeywords) + boundary, Keyword, 'type'),
 
-            # special sequences of tokens (we use ?: for non-capturing group as required by 'bygroups')
-            (r'(module)(\s*)((?:interface)?)(\s*)((?:[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*\.)*[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)'
-                , bygroups(Keyword,Text,Keyword,Text,Name.Namespace)),
-            (r'(import)(\s+)((?:[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*\.)*[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)(\s*)((?:as)?)((?:[A-Z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)?)'
-                , bygroups(Keyword,Text,Name.Namespace,Text,Keyword,Name.Namespace)),
+            # special sequences of tokens (we use ?: for non-capturing group as
+            # required by 'bygroups')
+            (r'(module)(\s*)((?:interface)?)(\s*)'
+             r'((?:[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*\.)*'
+             r'[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)',
+             bygroups(Keyword, Text, Keyword, Text, Name.Namespace)),
+            (r'(import)(\s+)((?:[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*\.)*[a-z]'
+             r'(?:[a-zA-Z0-9_]|\-[a-zA-Z])*)(\s*)((?:as)?)'
+             r'((?:[A-Z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)?)',
+             bygroups(Keyword, Text, Name.Namespace, Text, Keyword,
+                      Name.Namespace)),
 
             # keywords
             (r'(%s)' % '|'.join(typekeywords) + boundary, Keyword.Type),
             (r'\-' + sboundary, Generic.Strong),
 
             # names
-            (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?=\.)',Name.Namespace),            
-            (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?!\.)',Name.Class),
-            (r'[a-z]([a-zA-Z0-9_]|\-[a-zA-Z])*',Name),
-            (r'_([a-zA-Z0-9_]|\-[a-zA-Z])*',Name.Variable),
+            (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?=\.)', Name.Namespace),
+            (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?!\.)', Name.Class),
+            (r'[a-z]([a-zA-Z0-9_]|\-[a-zA-Z])*', Name),
+            (r'_([a-zA-Z0-9_]|\-[a-zA-Z])*', Name.Variable),
 
             # literal string
             (r'@"', String.Double, 'litstring'),
-            
+
             # operators
             (symbols, Operator),
             (r'`', Operator),
             (r'[\{\}\(\)\[\];,]', Punctuation),
 
-            # literals. No check for literal characters with too many characters in it.
+            # literals. No check for literal characters with len > 1
             (r'[0-9]+\.[0-9]+([eE][\-\+]?[0-9]+)?', Number.Float),
             (r'0[xX][0-9a-fA-F]+', Number.Hex),
             (r'[0-9]+', Number.Integer),
 
         # type started by struct
         'struct-type': [
-            (r'(?=\((?!,*\)))',Punctuation,'#pop'),
+            (r'(?=\((?!,*\)))',Punctuation, '#pop'),
             include('type')
         ],
 
         # type started by colon
         'type': [
-            (r'[\(\[<]', Keyword.Type, 'type-nested' ),
+            (r'[\(\[<]', Keyword.Type, 'type-nested'),
             include('type-content')
         ],
 
         # type nested in brackets: can contain parameters, comma etc.
         'type-nested': [
-            (r'[\)\]>]', Keyword.Type, '#pop' ),
-            (r'[\(\[<]', Keyword.Type, 'type-nested' ),
-            (r'[,]', Keyword.Type),
-            (r'([a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)(\s*)(:)(?![:])',bygroups(Name.Variable,Text,Keyword.Type)),  # parameter name            
-            include('type-content')            
+            (r'[\)\]>]', Keyword.Type, '#pop'),
+            (r'[\(\[<]', Keyword.Type, 'type-nested'),
+            (r',', Keyword.Type),
+            (r'([a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)(\s*)(:)(?!:)',
+             bygroups(Name.Variable,Text,Keyword.Type)),  # parameter name
+            include('type-content')
         ],
 
         # shared contents of a type
 
             # keywords
             (r'(%s)' % '|'.join(typekeywords) + boundary, Keyword.Type),
-            (r'(?=((%s)' % '|'.join(keywords) + boundary + '))', Keyword, '#pop'),  # need to match because names overlap..
+            (r'(?=((%s)' % '|'.join(keywords) + boundary + '))',
+             Keyword, '#pop'),  # need to match because names overlap...
 
             # kinds
             (r'[EPH]' + boundary, Keyword.Type),
-            (r'[\*\!]', Keyword.Type),            
+            (r'[*!]', Keyword.Type),
 
             # type names
-            (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?=\.)',Name.Namespace),            
-            (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?!\.)',Name.Class),
-            (r'[a-z][0-9]*(?![a-zA-Z_\-])',Keyword.Type),            # Generic.Emph
-            (r'_([a-zA-Z0-9_]|\-[a-zA-Z])*',Keyword.Type),           # Generic.Emph
-            (r'[a-z]([a-zA-Z0-9_]|\-[a-zA-Z])*',Keyword.Type),
-            
+            (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?=\.)', Name.Namespace),
+            (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?!\.)', Name.Class),
+            (r'[a-z][0-9]*(?![a-zA-Z_\-])', Keyword.Type),   # Generic.Emph
+            (r'_([a-zA-Z0-9_]|\-[a-zA-Z])*', Keyword.Type),  # Generic.Emph
+            (r'[a-z]([a-zA-Z0-9_]|\-[a-zA-Z])*', Keyword.Type),
+
             # type keyword operators
             (r'::|\->|[\.:|]', Keyword.Type),
 
             (r'[^/\*]+', Comment.Multiline),
             (r'/\*', Comment.Multiline, '#push'),
             (r'\*/', Comment.Multiline, '#pop'),
-            (r'[\*/]', Comment.Multiline),            
+            (r'[\*/]', Comment.Multiline),
         ],
         'litstring': [
             (r'[^"]+', String.Double),
             (r'\\[abfnrtv0\\\"\'\?]', String.Escape),
             (r'\\x[0-9a-fA-F]{2}', String.Escape),
             (r'\\u[0-9a-fA-F]{4}', String.Escape),
+            # Yes, \U literals are 6 hex digits.
             (r'\\U[0-9a-fA-F]{6}', String.Escape)
-        ]        
+        ]
     }
 
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.