diff options
author | Andy Li <andy@onthewings.net> | 2012-12-16 03:44:35 +0800 |
---|---|---|
committer | Andy Li <andy@onthewings.net> | 2012-12-16 03:44:35 +0800 |
commit | 33342de19c0946e740713c2cd3e8946f0736f7d7 (patch) | |
tree | 37ee000680889aa02779a4910faeb424f0139de2 | |
parent | f0109675cf3aec0bfdc88df0ba39074e5bde94a3 (diff) | |
download | pygments-33342de19c0946e740713c2cd3e8946f0736f7d7.tar.gz |
Support haxe3 pattern matching.
-rw-r--r-- | pygments/lexers/web.py | 10 | ||||
-rw-r--r-- | tests/examplefiles/example.hx | 14 |
2 files changed, 22 insertions, 2 deletions
diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py index 3aae0b89..95b7a104 100644 --- a/pygments/lexers/web.py +++ b/pygments/lexers/web.py @@ -1535,7 +1535,7 @@ class HaxeLexer(ExtendedRegexLexer): 'switch': [ include('spaces'), - (r'\(', Text, ('#pop', 'switch-body', 'bracket-open', 'parenthesis')), + (r'\(', Text, ('#pop', 'switch-body', 'bracket-open', 'expr')), ], 'switch-body': [ @@ -1547,7 +1547,7 @@ class HaxeLexer(ExtendedRegexLexer): 'case': [ include('spaces'), (r':', Punctuation, '#pop'), - (r'', Text, ('#pop', 'case-sep', 'expr')), + (r'', Text, ('#pop', 'case-sep', 'case-guard', 'expr')), ], 'case-sep': [ @@ -1556,6 +1556,12 @@ class HaxeLexer(ExtendedRegexLexer): (r',', Punctuation, ('#pop', 'case')), ], + 'case-guard': [ + include('spaces'), + (r'(?:if)\b', Keyword, ('#pop', 'parenthesis')), + (r'', Text, '#pop'), + ], + # optional multiple expr under a case 'case-block': [ include('spaces'), diff --git a/tests/examplefiles/example.hx b/tests/examplefiles/example.hx index 9695dbf8..11c74fab 100644 --- a/tests/examplefiles/example.hx +++ b/tests/examplefiles/example.hx @@ -55,6 +55,20 @@ var point = { "x" : 1, "y" : -5 }; var a, b : Bool, c : Int = 0; } +//haxe3 pattern matching +switch(e.expr) { + case EConst(CString(s)) if (StringTools.startsWith(s, "foo")): + "1"; + case EConst(CString(s)) if (StringTools.startsWith(s, "bar")): + "2"; + case EConst(CInt(i)) if (switch(Std.parseInt(i) * 2) { case 4: true; case _: false; }): + "3"; + case EConst(_): + "4"; + case _: + "5"; +} + class Test <T:Void->Void> { private function new():Void { |