Commits

Anonymous committed ff9e3a7

final(?) fixes, version seems to cover most things

- fixed multiline comment handling
- added string escape sequences
- simplified (and fixed) array handling

  • Participants
  • Parent commits 336bd30

Comments (0)

Files changed (2)

File pygments/lexers/monkey.py

              r'Exit|Continue)\s+', Keyword.Reserved),
             # not used yet
             (r'(?i)\b(?:Module|Inline)\b', Keyword.Reserved),
+            # Array
+            (r'[\[\]]', Punctuation),
             # Other
             (r'<=|>=|<>|[*]=|/=|[+]=|-=|&=|~=|[|]=|[-&*/^+=<>]', Operator),
             (r'Not|Mod|Shl|Shr|And|Or', Operator.Word),
-            (r'[\]]', Punctuation, "array"),
             (r'[\(\){}!#,.:]', Punctuation),
             # catch the rest
             (r'%s\b' % name_constant, Name.Constant),
             (r'%s\.' % name_module, Name.Namespace), 
             (r'%s\b' % keyword_type, Keyword.Type),
             (r'%s\b' % name_class, Name.Class),
-            (r'\s+(?!<)', Text,'#pop'),
-            (r'<', Punctuation),
-            (r'>', Punctuation),
-            (r'\[', Punctuation, 'array'),
-            (r'\n', Punctuation, '#pop'),
+            (r'\s+', Text),
+            # array (of given size)
+            (r'(\[)\s*(\d*)\s*(\])', bygroups(Punctuation, Number.Integer, Punctuation)),
+            # generic
+            (r'<', Punctuation, '#push'),
+            (r'>', Punctuation, '#pop'),
+            (r'\n', Text, '#pop'),
             (r'', Text, '#pop')
         ],
-        'array' : [
-            # direct access myArray[3] and size definition myArray:String[100]
-            (r'[0-9]+', Number.Integer),
-            # slicing myArray[1..2]
-            (r'\.\.', Punctuation),
-            (r'\]', Punctuation, '#pop'),
-            (r'\[', Punctuation),
-        ],
         'variables': [
             (r'%s\b' % name_constant, Name.Constant),
             (r'%s\b' % name_variable, Name.Variable),
             (r'', Text, '#pop')
         ],
         'string': [
-            (r'""', String.Double),
-            (r'"C?', String.Double, '#pop'),
-            (r'[^"]+', String.Double)
+            (r'[^"~]+', String.Double),
+            (r'~q|~n|~r|~r|~t|~z|~~', String.Escape),
+            (r'"', String.Double, '#pop'),
         ],
         'comment' : [
+            (r'(?i)^#rem.*?', Comment.Multiline, "#push"),
+            (r'(?i)^#end.*?', Comment.Multiline, "#pop"),
             (r'\n', Comment.Multiline),
-            (r'^[^#].*', Comment.Multiline),
-            (r'(?i)^#End.*?', Comment.Multiline, "#pop"),
-            (r'^#\w+\b.*', Comment.Multiline, "#push"),
             (r'.*', Comment.Multiline),
         ],
     }

File tests/examplefiles/example.monkey

 Strict
 
+' single line comment
+
 #rem
-this is a
+multi
+line
+comment
+#end
+
 #rem
 nested
+#rem
+multi
+line
 #end
 comment
-even other preproc keywords are nested within!
-#If TARGET
-#End
 #end
 
 Import mojo
 Const TWOCONST := 2
 Const THREECONST := 3, FOURCONST:Int = 4
 
+Global someVariable:Int = 4
+
+' sample class from the documentation
 Class Game Extends App
 
-    ' radial sprial with axis aligned phase
-
     Function DrawSpiral(clock)
         Local w=DeviceWidth/2
         For Local i#=0 Until w*1.5 Step .2
   Method Die () Abstract
 End
 
+' extending
 Class Hoodlum Extends Enemy
+    ' field
+    Field testField:Bool = True
+
+    ' naming class with modulepath
     Local currentNode:list.Node<Vector2D>
 
-  ' Must implement Die method...
-
-  Method Die ()
-    Print "B'oss, he-- he killed me, b'oss!"
-  End
-
+    Method Die ()
+        Print "B'oss, he-- he killed me, b'oss!"
+    End
 End
 
+' extending with generics
 Class VectorNode Extends Node<Vector2D>
 End
 
+' interfaces
 Interface Computer
   Method Boot ()
   Method Process ()
 Class PC Implements Computer
 End
 
-Function Main()
-    New Game()
-End
+' array syntax
+Global listOfStuff:String[42]
+Global lessStuff:String[5] = listOfStuff[4..8]
+Global oneStuff:String = listOfStuff[23]
+
+'a comma separated sequence
+Global scores:Int[]=[10,20,30]
+'a comma separated sequence
+Global text:String[]=["Hello","There","World"]
+Global worstCase:worst.List<String[]>
+
+' escape characers in strings
+Global string1 := "Hello~zWorld"
+Global string2 := "~qHello World~q"
+Global string3 := "~tIndented~n"
+Global string3 := "tilda is wavey... ~~"