diff options
author | Tinnet Coronam <tinnet@coronam.net> | 2012-11-03 14:47:44 +0100 |
---|---|---|
committer | Tinnet Coronam <tinnet@coronam.net> | 2012-11-03 14:47:44 +0100 |
commit | 08da801c6f2babd0e98fb83983ee243c43fe4a8a (patch) | |
tree | c851ae2d21cd721e69cba209890760e684f4c7f0 | |
parent | 0687bc322f2a3d26396bb9ac398e19c72f6a20d5 (diff) | |
download | pygments-08da801c6f2babd0e98fb83983ee243c43fe4a8a.tar.gz |
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
-rw-r--r-- | pygments/lexers/compiled.py | 12 | ||||
-rw-r--r-- | tests/examplefiles/example.monkey | 44 |
2 files changed, 46 insertions, 10 deletions
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 3887197d..9a31713d 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -3079,21 +3079,21 @@ class MonkeyLexer(RegexLexer): 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), @@ -3124,7 +3124,7 @@ class MonkeyLexer(RegexLexer): (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), diff --git a/tests/examplefiles/example.monkey b/tests/examplefiles/example.monkey index e2cf9e79..c0567ed4 100644 --- a/tests/examplefiles/example.monkey +++ b/tests/examplefiles/example.monkey @@ -28,6 +28,9 @@ Global someVariable:Int = 4 ' 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 @@ -101,8 +104,41 @@ Global scores:Int[]=[10,20,30] 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
\ No newline at end of file |