diff options
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/web.py | 55 | ||||
-rw-r--r-- | tests/examplefiles/scope.cirru | 37 |
3 files changed, 92 insertions, 1 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 0ab08f22..28457a64 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -61,6 +61,7 @@ LEXERS = { 'CheetahJavascriptLexer': ('pygments.lexers.templates', 'JavaScript+Cheetah', ('js+cheetah', 'javascript+cheetah', 'js+spitfire', 'javascript+spitfire'), (), ('application/x-javascript+cheetah', 'text/x-javascript+cheetah', 'text/javascript+cheetah', 'application/x-javascript+spitfire', 'text/x-javascript+spitfire', 'text/javascript+spitfire')), 'CheetahLexer': ('pygments.lexers.templates', 'Cheetah', ('cheetah', 'spitfire'), ('*.tmpl', '*.spt'), ('application/x-cheetah', 'application/x-spitfire')), 'CheetahXmlLexer': ('pygments.lexers.templates', 'XML+Cheetah', ('xml+cheetah', 'xml+spitfire'), (), ('application/xml+cheetah', 'application/xml+spitfire')), + 'CirruLexer': ('pygments.lexers.web', 'Cirru', ('cirru',), ('*.cirru',), ('text/x-cirru',)), 'ClayLexer': ('pygments.lexers.compiled', 'Clay', ('clay',), ('*.clay',), ('text/x-clay',)), 'ClojureLexer': ('pygments.lexers.jvm', 'Clojure', ('clojure', 'clj'), ('*.clj',), ('text/x-clojure', 'application/x-clojure')), 'CobolFreeformatLexer': ('pygments.lexers.compiled', 'COBOLFree', ('cobolfree',), ('*.cbl', '*.CBL'), ()), diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py index 10522aa4..f270684a 100644 --- a/pygments/lexers/web.py +++ b/pygments/lexers/web.py @@ -28,7 +28,7 @@ __all__ = ['HtmlLexer', 'XmlLexer', 'JavascriptLexer', 'JsonLexer', 'CssLexer', 'ObjectiveJLexer', 'CoffeeScriptLexer', 'LiveScriptLexer', 'DuelLexer', 'ScamlLexer', 'JadeLexer', 'XQueryLexer', 'DtdLexer', 'DartLexer', 'LassoLexer', 'QmlLexer', 'TypeScriptLexer', - 'KalLexer'] + 'KalLexer', 'CirruLexer'] class JavascriptLexer(RegexLexer): @@ -4166,3 +4166,56 @@ class QmlLexer(RegexLexer): (r"'(\\\\|\\'|[^'])*'", String.Single), ] } + +class CirruLexer(RegexLexer): + """ + Syntax rules of Cirru can be found at: + http://grammar.cirru.org/ + + * using `()` to markup blocks, but limited in the same line + * using `""` to markup strings, allow `\` to escape + * using `$` as a shorthand for `()` till indentation end or `)` + * using indentations for create nesting + """ + + name = 'Cirru' + aliases = ['cirru'] + filenames = ['*.cirru', '*.cr'] + mimetypes = ['text/x-cirru'] + flags = re.MULTILINE + + tokens = { + 'string': [ + (r'[^"\\\n]', String), + (r'\\', String.Escape, 'escape'), + (r'"', String, '#pop'), + ], + 'escape': [ + (r'.', String.Escape, '#pop'), + ], + 'function': [ + (r'[\w-][^\s\(\)\"]*', Name.Function, '#pop'), + (r'\)', Operator, '#pop'), + (r'(?=\n)', Text, '#pop'), + (r'\(', Operator, '#push'), + (r'"', String, ('#pop', 'string')), + (r'\s+', Text.Whitespace), + ], + 'line': [ + (r'^\B', Text.Whitespace, 'function'), + (r'\$', Operator, 'function'), + (r'\(', Operator, 'function'), + (r'\)', Operator), + (r'(?=\n)', Text, '#pop'), + (r'\n', Text, '#pop'), + (r'"', String, 'string'), + (r'\s+', Text.Whitespace), + (r'[\d\.]+', Number), + (r'[\w-][^\"\(\)\s]*', Name.Variable), + (r'--', Comment.Single) + ], + 'root': [ + (r'^\s*', Text.Whitespace, ('line', 'function')), + (r'^\s+$', Text.Whitespace), + ] + }
\ No newline at end of file diff --git a/tests/examplefiles/scope.cirru b/tests/examplefiles/scope.cirru new file mode 100644 index 00000000..b17ff4ea --- /dev/null +++ b/tests/examplefiles/scope.cirru @@ -0,0 +1,37 @@ + +-- https://github.com/Cirru/cirru-gopher/blob/master/code/scope.cr + +set a (int 2) + +print (self) + +set c (child) + +under c + under parent + print a + +print $ get c a + +set c x (int 3) +print $ get c x + +set just-print $ code + print a + +print just-print + +eval (self) just-print +eval just-print + +print (string "string with space") +print (string "escapes \n \"\\") + +brackets ((((())))) + +"eval" $ string "eval" + +print (add $ (int 1) (int 2)) + +print $ unwrap $ + map (a $ int 1) (b $ int 2)
\ No newline at end of file |