Ivan Inozemtsev avatar Ivan Inozemtsev committed c107c47

Fixed few bugs in fantom lexer

Comments (0)

Files changed (2)

pygments/lexers/_mapping.py

     'FSharpLexer': ('pygments.lexers.dotnet', 'FSharp', ('fsharp',), ('*.fs', '*.fsi'), ('text/x-fsharp',)),
     'FactorLexer': ('pygments.lexers.agile', 'Factor', ('factor',), ('*.factor',), ('text/x-factor',)),
     'FancyLexer': ('pygments.lexers.agile', 'Fancy', ('fancy', 'fy'), ('*.fy', '*.fancypack'), ('text/x-fancysrc',)),
+    'FantomLexer': ('pygments.lexers.compiled', 'Fantom', ('fan',), ('*.fan',), ()),
     'FelixLexer': ('pygments.lexers.compiled', 'Felix', ('felix', 'flx'), ('*.flx', '*.flxh'), ('text/x-felix',)),
     'FortranLexer': ('pygments.lexers.compiled', 'Fortran', ('fortran',), ('*.f', '*.f90', '*.F', '*.F90'), ('text/x-fortran',)),
     'GLShaderLexer': ('pygments.lexers.compiled', 'GLSL', ('glsl',), ('*.vert', '*.frag', '*.geo'), ('text/x-glslsrc',)),

pygments/lexers/compiled.py

     def s(str):
         return Template(str).substitute(
             dict (
-                pod = r'[\"\"\w\.]+',
+                pod = r'[\"\w\.]+',
                 eos = r'\n|;',
                 id = r'[a-zA-Z_][a-zA-Z0-9_]*',
                 type = r'(?:\[|[a-zA-Z_]|\|)[:\w_\[\]\|\->\?]*?' # all chars which can be part of type definition. Starts with either letter, or [ (maps), or | (funcs)
     tokens = {
         'comments' : [
             (r'(?s)/\*.*?\*/', Comment.Multiline),               #Multiline
-            (r'//.*?\n', Comment),                               #Single line
+            (r'//.*?\n', Comment.Single),                        #Single line
             #todo: highlight references in fandocs
-            (r'\*\*.*?\n', Comment.Special)                      #Fandoc
+            (r'\*\*.*?\n', Comment.Special),                     #Fandoc
+            (r'#.*\n', Comment.Single)                           #Shell-style comment
         ],
         'literals' : [
-            (r'-?[\d_]+(ns|ms|sec|min|hr|day)', Number),         #Duration
-            (r'-?[\d_]*\.[\d_]+(ns|ms|sec|min|hr|day)', Number), #Duration with dot
-            (r'-?(\d+)?\.\d+(f|F|d|D)?', Number.Float),          #Float/Decimal
-            (r'-?0x[0-9a-fA-F_]+', Number.Hex),                  #Hex
-            (r'-?[\d_]+', Number.Integer),                       #Int
+            (r'\b-?[\d_]+(ns|ms|sec|min|hr|day)', Number),         #Duration
+            (r'\b-?[\d_]*\.[\d_]+(ns|ms|sec|min|hr|day)', Number), #Duration with dot
+            (r'\b-?(\d+)?\.\d+(f|F|d|D)?', Number.Float),          #Float/Decimal
+            (r'\b-?0x[0-9a-fA-F_]+', Number.Hex),                  #Hex
+            (r'\b-?[\d_]+', Number.Integer),                       #Int
             (r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char),    #Char
             (r'"', Punctuation, 'insideStr'),                    #Opening quote
             (r'`', Punctuation, 'insideUri'),                    #Opening accent
-            (r'\b(true|false|null)\b', Keyword.Constant),              #Bool & null
+            (r'\b(true|false|null)\b', Keyword.Constant),        #Bool & null
             (r'(?:(\w+)(::))?(\w+)(<\|)(.*?)(\|>)',              #DSL
              bygroups(Name.Namespace, Punctuation, Name.Class, 
                       Punctuation, String, Punctuation)),
-            (r'(\w+)?(::)?(\w+)?(#)(\w+)?',                      #Type/slot literal
+            (r'(?:(\w+)(::))?(\w+)?(#)(\w+)?',                      #Type/slot literal
              bygroups(Name.Namespace, Punctuation, Name.Class,
                       Punctuation, Name.Function)),
             (r'\[,\]', Literal),                                 # Empty list
             (s(r'($type)(\[,\])'),                               # Typed empty list
              bygroups(using(this, state = 'inType'), Literal)),
             (r'\[:\]', Literal),                                 # Empty Map
-            (r'($type)(\[:\])', 
+            (s(r'($type)(\[:\])'), 
              bygroups(using(this, state = 'inType'), Literal)),
         ],
         'insideStr' : [
             
         ],
         'operators' : [
-            (r'\+\+|--|\+|-|\*|/|\|\||&&|<=>|<=|<|>=|>|=|!', Operator)
+            (r'\+\+|\-\-|\+|\-|\*|/|\|\||&&|<=>|<=|<|>=|>|=|!|\[|\]', Operator)
         ],
         'inType' : [
-#            include('types'),
             (r'[\[\]\|\->:\?]', Punctuation),
             (s(r'$id'), Name.Class),
             (r'', Text, '#pop'),
             include('literals'),
             include('otherKeywords'),
             include('operators'),
-#            include('types'),
             (r'using\b', Keyword.Namespace, 'using'),          #Using stmt
             (r'@\w+', Name.Decorator, 'facet'),                  #Symbol
             (r'(class|mixin)(\s+)(\w+)',                         
              bygroups(Keyword, Text, Name.Class), 'inheritance'),#Inheritance list
 
 
-            #Type var := val
+            ### Type var := val
             (s(r'($type)([ \t]+)($id)(\s*)(:=)'),
              bygroups(using(this, state = 'inType'), Text, 
                       Name.Variable, Text, Operator)),           
              bygroups(Name.Variable, Text, Operator)),
 
             ### .someId( or ->someId( ###
-            (s(r'(\.|(?:->))($id)(\s*)(\()'),
+            (s(r'(\.|(?:\->))($id)(\s*)(\()'),
              bygroups(Operator, Name.Function, Text, Punctuation),
              'insideParen'),
             
             ### .someId  or ->someId 
-            (s(r'(\.|(?:->))($id)'),
+            (s(r'(\.|(?:\->))($id)'),
              bygroups(Operator, Name.Function)),
              
             ### new makeXXX ( ####
              bygroups(using(this, state = 'inType'), Text,
                       Name.Function, Text, Punctuation), 'insideMethodDeclArgs'),
 
-            #### ArgType argName, #####
+            ### ArgType argName, #####
             (s(r'($type)(\s+)($id)(\s*)(,)'),
              bygroups(using(this, state= 'inType'), Text, Name.Variable,
                       Text, Punctuation)),
             #### ArgType argName) ####
             ## Covered in 'insideParen' state
 
+            ### ArgType argName -> ArgType| ###
+            (s(r'($type)(\s+)($id)(\s*)(\->)(\s*)($type)(\|)'),
+             bygroups(using(this, state= 'inType'), Text, Name.Variable,
+                      Text, Punctuation, Text, using(this, state = 'inType'),
+                      Punctuation)),
+
+            ### ArgType argName|  ###
+            (s(r'($type)(\s+)($id)(\s*)(\|)'),
+             bygroups(using(this, state= 'inType'), Text, Name.Variable,
+                      Text, Punctuation)),
+
+            ### Type var
+            (s(r'($type)([ \t]+)($id)'),
+             bygroups(using(this, state='inType'), Text,
+                      Name.Variable)),
+
             (r'\(', Punctuation, 'insideParen'),
             (r'\{', Punctuation, 'insideBrace'),
             (r'.', Text)
         'facetFields': [
             include('comments'),
             include('literals'),
+            include('operators'),
             (r'\s+', Text),
             (r'(\s*)(\w+)(\s*)(=)', bygroups(Text, Name, Text, Operator)),
-            (r'}', Punctuation, '#pop')
+            (r'}', Punctuation, '#pop'),
+            (r'.', Text)
         ],
-        
-            
     }
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.