Commits

Jiyin Yiyong  committed a52eb6d

add syntax for Cirru

  • Participants
  • Parent commits 2d8a717

Comments (0)

Files changed (3)

File pygments/lexers/_mapping.py

     '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'), ()),

File pygments/lexers/web.py

            'ObjectiveJLexer', 'CoffeeScriptLexer', 'LiveScriptLexer',
            'DuelLexer', 'ScamlLexer', 'JadeLexer', 'XQueryLexer',
            'DtdLexer', 'DartLexer', 'LassoLexer', 'QmlLexer', 'TypeScriptLexer',
-           'KalLexer']
+           'KalLexer', 'CirruLexer']
 
 
 class JavascriptLexer(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),
+            (r'\\', String),
+            (r'"', String, '#pop'),
+        ],
+        'function': [
+            (r'[\w-][^\s\(\)\"]*', Name.Function, '#pop'),
+            (r'\)', Operator, '#pop'),
+            (r'(?=\n)', Text.Whitespace, '#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.Whitespace, '#pop'),
+            (r'\n', Text.Whitespace, '#pop'),
+            (r'"', String, 'string'),
+            (r'\s+', Text.Whitespace),
+            (r'[\d\.]+', Number),
+            (r'[\w-][^\"\(\)\s]*', Name.Variable),
+        ],
+        'root': [
+            (r'^\s*', Text.Whitespace, ('line', 'function')),
+            (r'^\s+$', Text.Whitespace),
+        ]
+    }

File tests/examplefiles/scope.cirru

+
+-- 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 content\nand")
+
+demo ((((()))))
+
+"eval" $ string "eval"