Commits

Martin Contento committed 816f160

applied several fixes hinted on in pull request 117

- uppercase hex numbers
- lowercase keywords like Or/And etc.
- added preprocessor variables (differnt from preprocess keywords)
- made preprocess keywords cleverer by not capturing the while line

Comments (0)

Files changed (2)

pygments/lexers/compiled.py

     tokens = {
         'root': [
             #Text
-            (r'\n', Text),
-            (r'\r', Text),
-            (r'\t+', Text),  
             (r'\s+', Text),
             # Comments
             (r"'.*", Comment),
             (r'(?i)^#rem\b', Comment.Multiline, 'comment'),
-            (r'(?i)^(?:#If|#ElseIf|#Else|#End|#EndIf|#Print|#Error)\s?.*$', Comment.Preproc),
+            # preprocessor directives
+            (r'(?i)^(?:#If|#ElseIf|#Else|#EndIf|#End|#Print|#Error)\b', Comment.Preproc),
+            # preprocessor variable (any line starting with '#' that is not a directive)
+            (r'^#', Comment.Preproc, 'variables'),
             # String
             ('"', String.Double, 'string'),
             # Numbers
             (r'[0-9]+\.[0-9]*(?!\.)', Number.Float),
             (r'\.[0-9]+(?!\.)', Number.Float),
             (r'[0-9]+', Number.Integer),
-            (r'\$[0-9a-f]+', Number.Hex),
+            (r'\$[0-9a-fA-Z]+', Number.Hex),
             (r'\%[10]+', Number), # Binary
             # Native data types
             (r'\b%s\b' % keyword_type, Keyword.Type),
             (r'[\[\]]', Punctuation),
             # Other
             (r'<=|>=|<>|[*]=|/=|[+]=|-=|&=|~=|[|]=|[-&*/^+=<>]', Operator),
-            (r'Not|Mod|Shl|Shr|And|Or', Operator.Word),
+            (r'(?i)(?:Not|Mod|Shl|Shr|And|Or)', Operator.Word),
             (r'[\(\){}!#,.:]', Punctuation),
             # catch the rest
             (r'%s\b' % name_constant, Name.Constant),

tests/examplefiles/example.monkey

 ' sample class from the documentation
 Class Game Extends App
 
+    Function New()
+    End
+
     Function DrawSpiral(clock)
         Local w=DeviceWidth/2
         For Local i#=0 Until w*1.5 Step .2
 Global text:String[]=["Hello","There","World"]
 Global worstCase:worst.List<String[]>
 
+' string type
+Global string1:String = "Hello world"
+Global string2$ = "Hello world"
+
 ' escape characers in strings
-Global string1 := "Hello~zWorld"
-Global string2 := "~qHello World~q"
-Global string3 := "~tIndented~n"
-Global string3 := "tilda is wavey... ~~"
+Global string3 := "Hello~zWorld"
+Global string4 := "~qHello World~q"
+Global string5 := "~tIndented~n"
+Global string6 := "tilda is wavey... ~~"
+
+' string pseudofunctions
+Print "  Hello World  ~n".Trim()    ' prints "Hello World"
+Print "Hello World".ToUpper()       ' prints "HELLO WORLD"
+
+' Boolean shorttype
+Global boolVariable1:Bool = True
+Global boolVariable2? = False
+
+' number formats
+Global hexNum1:Int = $3d0dead
+Global hexNum2% = $CAFEBABE
+
+Global floatNum1:Float = 3.141516
+Global floatNum2# = 3.141516
+Global floatNum3 := .141516
+
+' preprocessor keywords
+#If TARGET = "android"
+DoStuff()
+#ElseIf TARGET = "ios"
+DoOtherStuff()
+#End
+
+' preprocessor variable
+#SOMETHING = True
+#Print SOMETHING
+#If SOMETHING
+#End