Commits

preevs  committed ead8d13

Add lexers for Gosu source files and Gosu templates

  • Participants
  • Parent commits 2f2a9d7

Comments (0)

Files changed (2)

File pygments/lexers/_mapping.py

     'GnuplotLexer': ('pygments.lexers.other', 'Gnuplot', ('gnuplot',), ('*.plot', '*.plt'), ('text/x-gnuplot',)),
     'GoLexer': ('pygments.lexers.compiled', 'Go', ('go',), ('*.go',), ('text/x-gosrc',)),
     'GoodDataCLLexer': ('pygments.lexers.other', 'GoodData-CL', ('gooddata-cl',), ('*.gdc',), ('text/x-gooddata-cl',)),
+    'GosuLexer': ('pygments.lexers.compiled', 'Gosu', ('gosu',), ('*.gs', '*.gsx', '*.gsp'), ('text/x-gosu',)),
+    'GosuTemplateLexer': ('pygments.lexers.compiled', 'Gosu Template', ('gst',), ('*.gst',), ('text/x-gosu',)),
     'GroffLexer': ('pygments.lexers.text', 'Groff', ('groff', 'nroff', 'man'), ('*.[1234567]', '*.man'), ('application/x-troff', 'text/troff')),
     'HamlLexer': ('pygments.lexers.web', 'Haml', ('haml', 'HAML'), ('*.haml',), ('text/x-haml',)),
     'HaskellLexer': ('pygments.lexers.functional', 'Haskell', ('haskell', 'hs'), ('*.hs',), ('text/x-haskell',)),

File pygments/lexers/compiled.py

            'ScalaLexer', 'DylanLexer', 'OcamlLexer', 'ObjectiveCLexer',
            'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer',
            'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer',
-           'Modula2Lexer', 'BlitzMaxLexer']
+           'Modula2Lexer', 'BlitzMaxLexer', 'GosuLexer', 'GosuTemplateLexer']
 
 
 class CLexer(RegexLexer):
             (r'[^"]+', String.Double),
         ],
     }
+
+class GosuLexer(RegexLexer):
+    """
+    For `Gosu <http://gosu-lang.org/>`_ source code.
+    """
+
+    name = 'Gosu'
+    aliases = ['gosu']
+    filenames = ['*.gs', '*.gsx', '*.gsp']
+    mimetypes = ['text/x-gosu']
+
+    flags = re.MULTILINE | re.DOTALL
+
+    #: optional Comment or Whitespace
+    _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
+
+    tokens = {
+        'root': [
+            # method names
+            (r'^(\s*(?:[a-zA-Z_][a-zA-Z0-9_\.\[\]]*\s+)+?)' # modifiers etc.
+             r'([a-zA-Z_][a-zA-Z0-9_]*)'                    # method name
+             r'(\s*)(\()',                                  # signature start
+             bygroups(using(this), Name.Function, Text, Operator)),
+            (r'[^\S\n]+', Text),
+            (r'//.*?\n', Comment.Single),
+            (r'/\*.*?\*/', Comment.Multiline),
+            (r'@[a-zA-Z_][a-zA-Z0-9_\.]*', Name.Decorator),
+            (r'(in|as|typeof|statictypeof|typeis|typeas|if|else|foreach|'
+             r'for|index|while|do|continue|break|return|try|catch|finally|this|throw|'
+             r'new|switch|case|default|eval|super|outer|classpath|using)\b',
+             Keyword),
+            (r'(var|delegate|construct|function|private|internal|protected|public|'
+             r'abstract|override|final|static|extends|transient|implements|represents|'
+             r'readonly)\b', Keyword.Declaration),
+            (r'(property\s+)(get|set|)', Keyword.Declaration),
+            (r'(boolean|byte|char|double|float|int|long|short|void|block)\b',
+             Keyword.Type),
+            (r'(package)(\s+)', bygroups(Keyword.Namespace, Text)),
+            (r'(true|false|null|NaN|Infinity)\b', Keyword.Constant),
+            (r'(class|interface|enhancement|enum)(\s+)', bygroups(Keyword.Declaration, Text), 'class'),
+            (r'(uses)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
+            (r'"', String, 'string'),
+            (r'(\??[\.#])([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)),
+            (r'(:)([a-zA-Z_][a-zA-Z0-9_]*)', bygroups(Operator, Name.Attribute)),
+            (r'[a-zA-Z_\$][a-zA-Z0-9_]*', Name),
+            (r'and|or|not|[\\~\^\*!%&\[\]\(\)\{\}<>\|+=:;,./?-]', Operator),
+            (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
+            (r'[0-9]+', Number.Integer),
+            (r'\n', Text)
+        ],
+        'templateText': [
+          (r'(\\<)|(\\\$)', String),
+          (r'(<%@\s+)(extends|params)', bygroups(Operator, Name.Decorator), 'stringTemplate'),
+          (r'(<%)|(<%=)', Operator, 'stringTemplate'),
+          (r'\$\{', Operator, 'stringTemplateShorthand'),
+          (r'.+?', String)
+        ],
+        'string': [
+          (r'"', String, '#pop'),
+          include('templateText')
+        ],
+        'stringTemplate': [
+          (r'"', String, 'string'),
+          (r'%>', Operator, '#pop'),
+          include('root')          
+        ],
+        'stringTemplateShorthand': [
+          (r'"', String, 'string'),
+          (r'\{', Operator, 'stringTemplateShorthand'),
+          (r'\}', Operator, '#pop'),
+          include('root')
+        ],
+        'class': [
+            (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
+        ],
+        'import': [
+            (r'[a-zA-Z0-9_.]+\*?', Name.Namespace, '#pop')
+        ],
+    }
+
+class GosuTemplateLexer(GosuLexer):
+    """
+    For `Gosu <http://gosu-lang.org/>`_ source code.
+    """
+
+    name = 'Gosu Template'
+    aliases = ['gst']
+    filenames = ['*.gst']
+
+    def get_tokens_unprocessed(self, text):
+        stack = ['templateText']
+        for item in GosuLexer.get_tokens_unprocessed(self, text, stack):
+            yield item