diff options
-rw-r--r-- | pygments/lexers/compiled.py | 82 | ||||
-rw-r--r-- | tests/examplefiles/test.bmx | 145 |
2 files changed, 226 insertions, 1 deletions
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index a2543e27..c8c501d5 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -26,7 +26,7 @@ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'JavaLexer', 'ScalaLexer', 'DylanLexer', 'OcamlLexer', 'ObjectiveCLexer', 'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer', - 'Modula2Lexer'] + 'Modula2Lexer', 'BlitzMaxLexer'] class CLexer(RegexLexer): @@ -2363,3 +2363,83 @@ class Modula2Lexer(RegexLexer): token = Keyword.Pervasive # return result yield index, token, value + + +class BlitzMaxLexer(RegexLexer): + """ + For `BlitzMax <http://blitzbasic.com>`_ source code. + + *New in Pygments 1.4.* + """ + + name = 'BlitzMax' + aliases = ['blitzmax', 'bmax'] + filenames = ['*.bmx'] + mimetypes = ['text/x-bmx'] + + bmax_vopwords = r'\b(Shl|Shr|Sar|Mod)\b' + bmax_sktypes = r'@{1,2}|[!#$%]' + bmax_lktypes = r'\b(Int|Byte|Short|Float|Double|Long)\b' + bmax_name = r'[a-z_][a-z0-9_]*' + bmax_var = r'(%s)(?:(?:([ \t]*)(%s)|([ \t]*:[ \t]*\b(?:Shl|Shr|Sar|Mod)\b)|([ \t]*)([:])([ \t]*)(?:%s|(%s)))(?:([ \t]*)(Ptr))?)' % (bmax_name, bmax_sktypes, bmax_lktypes, bmax_name) + bmax_func = bmax_var + r'?((?:[ \t]|\.\.\n)*)([(])' + + flags = re.MULTILINE | re.IGNORECASE + tokens = { + 'root': [ + # Text + (r'[ \t]+', Text), + (r'\.\.\n', Text), # Line continuation + # Comments + (r"'.*?\n", Comment.Single), + (r'([ \t]*)\bRem\n(\n|.)*?\s*\bEnd([ \t]*)Rem', Comment.Multiline), + # Data types + ('"', String.Double, 'string'), + # Numbers + (r'[0-9]\.[0-9]*(?!\.)', Number.Float), + (r'[0-9]+', Number.Integer), + (r'\$[0-9a-f]+', Number.Hex), + (r'\%[10]+', Number), # Binary + # Other + (r'(?:(?:(:)?([ \t]*)(:?%s|([+\-*/&|~]))|Or|And|Not|[=<>^]))' % (bmax_vopwords), Operator), + (r'[(),.:\[\]]', Punctuation), + (r'(?:#[\w \t]*)', Name.Label), + (r'(?:\?[\w \t]*)', Comment.Preproc), + # Identifiers + (r'\b(New)\b([ \t]?)([(]?)(%s)' % (bmax_name), + bygroups(Keyword.Reserved, Text, Punctuation, Name.Class)), + (r'\b(Import|Framework|Module)([ \t]+)(%s\.%s)' % (bmax_name, bmax_name), bygroups(Keyword.Reserved, Text, Keyword.Namespace)), + (bmax_func, bygroups(Name.Function, Text, Keyword.Type, Operator, Text, Punctuation, Text, Keyword.Type, Name.Class, Text, Keyword.Type, Text, Punctuation)), + (bmax_var, bygroups(Name.Variable, Text, Keyword.Type, Operator, Text, Punctuation, Text, Keyword.Type, Name.Class, Text, Keyword.Type)), + (r'\b(Type|Extends)([ \t]+)(%s)' % (bmax_name), bygroups(Keyword.Reserved, Text, Name.Class)), + # Keywords + (r'\b(Ptr)\b', Keyword.Type), + (r'\b(Pi|True|False|Null|Self|Super)\b', Keyword.Constant), + (r'\b(Local|Global|Const|Field)\b', Keyword.Declaration), + (r'\b(TNullMethodException|TNullFunctionException|TNullObjectException|TArrayBoundsException|TRuntimeException)\b', Name.Exception), + (r'\b(Strict|SuperStrict|Module|ModuleInfo|' + r'End|Return|Continue|Exit|Public|Private|' + r'Var|VarPtr|Chr|Len|Asc|SizeOf|Sgn|Abs|Min|Max|' + r'New|Release|Delete|' + r'Incbin|IncbinPtr|IncbinLen|' + r'Framework|Include|Import|Extern|EndExtern|' + r'Function|EndFunction|' + r'Type|EndType|Extends|' + r'Method|EndMethod|' + r'Abstract|Final|' + r'If|Then|Else|ElseIf|EndIf|' + r'For|To|Next|Step|EachIn|' + r'While|Wend|EndWhile|' + r'Repeat|Until|Forever|' + r'Select|Case|Default|EndSelect|' + r'Try|Catch|EndTry|Throw|Assert|' + r'Goto|DefData|ReadData|RestoreData)\b', Keyword.Reserved), + # Final resolve (for variable names and such) + (r'(%s)' % (bmax_name), Name.Variable), + ], + 'string': [ + (r'""', String.Double), + (r'"C?', String.Double, '#pop'), + (r'[^"]+', String.Double), + ], + } diff --git a/tests/examplefiles/test.bmx b/tests/examplefiles/test.bmx new file mode 100644 index 00000000..17b9adae --- /dev/null +++ b/tests/examplefiles/test.bmx @@ -0,0 +1,145 @@ + +Rem +foobar +EndRem + +Rem + foobar! +End Rem + +Rem +End Rem + +SuperStrict + +Framework brl.blitz +Import brl.standardio + +'Import "blah.bmx" +'Import "blah/blah.bmx" +'Include "blurg/blurg.bmx" + +Const ca:Long = $10000000 ' Hex +Const cb:Int = %10101010 ' Binary +Global ga:String = "blargh" +Local a:Int = 124, b$ = "abcdef" +?Not Debug +Print(_name123(ga, a, 100.2)) +? + +Function _name123 : Float (zorp:String, ll:Int = False, blah#, waffles% = 100) + Return 235.7804 ' Single-line comment +End Function +Function TestString:String() +End Function +Function TestByte:Byte() +End Function + +Function hub(blah:String, .. + abc:Int = Pi) +End Function +Function Blar%() + Local aa !, ab @ ,ac @@, ad# ,ae$,af% ' Intentional mangling + Local ba:Double, bb :Byte, bc: Short,bd:Float,be: String,ff:Int = True +End Function + +?Win32 +abc() +?Linux +abc() +? + +Function abc() + Print "abc" ' I cannot find a way to parse these as function calls without messing something up + Print ' Anyhow, they're generally not used in this way + Goto Eww_Goto + #Eww_Goto +End Function + +Type TBlarf Abstract +End Type + +Type TFooBar +End Type + +New MyClass.TestMethod() +New(MyClass).TestMethod() +Local myinst:MyClass = New MyClass +myinst.TestMethod() + +Type MyClass Extends TFooBar + + Field m_foo:MyClass + Field m_bar:MyClass + + Rem + abc + def + End Rem + Method New() + Rem + abcdef + endrem + End Method + + Method TestMethod() ' foobar + m_foo = Self + m_bar = MyClass(m_foo) + m_foo.m_bar.m_foo.m_bar.Yell() + End Method + + Method Yell() + Print("huzzah!") + End Method + + Function Wakka$(foo:String) + Return foo + "bar" + End Function + +End Type + +Extern "c" + Function vesper!(a:Int) = "vesper@4" + Function bubbles@@(a%) +End Extern + +Print("blah " + .. + "blah " + .. + "blah.") + +Try + Throw("blar!") +Catch exception:String + Print("Caught: " + exception) +End Try + +For Local i:Int = 0 To 10 Step 1 + Print("Index: " + i) +Next +Local array:String[] = ["foo", "bar", "11", "22", "33"] +For Local value:String = EachIn array + Print("Value: " + value) +Next + +Local foobar:Int = Not (1 Or (2 And (4 Shl 5 Shr 6)) Sar 7) Mod (8+2) +Local az:Int = 1234567890 +az : + 1 +az: - 2 +az :* 3 +az:/ 4 +az:& 5 +az:| 6 +az: ~ 7 +az : Shl 8 +az: Shr 9 +az :Sar 10 +az:Mod 11 +az = ((10-5+2/4*2)>(((8^2)) < 2)) & 12|2 + +Function flub(fah Ptr, eah:Int Ptr, blu@@ Ptr) +End Function +Function Foob:Int Ptr(blar:Byte Ptr, Saffon@Ptr, blaus#Ptr) +End Function +Function zauus@Ptr() +End Function + |