Permalink
Browse files

Merge pull request #63 from tmm1/toml

Add TOML custom lexer
  • Loading branch information...
2 parents 4fee47a + b8fd4da commit 2216328bccbdb0a8b6b7fcea277e86aaed31c950 @tnm tnm committed Feb 25, 2013
View
BIN lexers
Binary file not shown.
@@ -14,7 +14,7 @@
from pygments.token import Text, Name, Number, String, Comment, Punctuation, \
Other, Keyword, Operator, Literal
-__all__ = ['Dasm16Lexer', 'PuppetLexer', 'AugeasLexer']
+__all__ = ['Dasm16Lexer', 'PuppetLexer', 'AugeasLexer', "TOMLLexer"]
class Dasm16Lexer(RegexLexer):
"""
@@ -360,3 +360,42 @@ class AugeasLexer(RegexLexer):
(r'[\*\)]', Comment.Multiline)
],
}
+
+class TOMLLexer(RegexLexer):
+ """
+ Lexer for TOML, a simple language for config files
+ """
+
+ name = 'TOML'
+ aliases = ['toml']
+ filenames = ['*.toml']
+
+ tokens = {
+ 'root': [
+
+ # Basics, comments, strings
+ (r'\s+', Text),
+ (r'#.*?$', Comment.Single),
+ (r'"(\\\\|\\"|[^"])*"', String),
+ (r'(true|false)$', Keyword.Constant),
+ ('[a-zA-Z_][a-zA-Z0-9_\-]*', Name),
+
+ # Datetime
+ (r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z', Number.Integer),
+
+ # Numbers
+ (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?', Number.Float),
+ (r'\d+[eE][+-]?[0-9]+j?', Number.Float),
+ (r'\-?\d+', Number.Integer),
+
+ # Punctuation
+ (r'[]{}:(),;[]', Punctuation),
+ (r'\.', Punctuation),
+
+ # Operators
+ (r'=', Operator)
+
+ ]
+ }
+
+
@@ -273,6 +273,7 @@
'SspLexer': ('pygments.lexers.templates', 'Scalate Server Page', ('ssp',), ('*.ssp',), ('application/x-ssp',)),
'StanLexer': ('pygments.lexers.math', 'Stan', ('stan',), ('*.stan',), ()),
'SystemVerilogLexer': ('pygments.lexers.hdl', 'systemverilog', ('systemverilog', 'sv'), ('*.sv', '*.svh'), ('text/x-systemverilog',)),
+ 'TOMLLexer': ('pygments.lexers.github', 'TOML', ('toml',), ('*.toml',), ()),
'TclLexer': ('pygments.lexers.agile', 'Tcl', ('tcl',), ('*.tcl',), ('text/x-tcl', 'text/x-script.tcl', 'application/x-tcl')),
'TcshLexer': ('pygments.lexers.shell', 'Tcsh', ('tcsh', 'csh'), ('*.tcsh', '*.csh'), ('application/x-csh',)),
'TeaTemplateLexer': ('pygments.lexers.templates', 'Tea', ('tea',), ('*.tea',), ('text/x-tea',)),
@@ -14,7 +14,7 @@
from pygments.token import Text, Name, Number, String, Comment, Punctuation, \
Other, Keyword, Operator, Literal
-__all__ = ['Dasm16Lexer', 'PuppetLexer', 'AugeasLexer']
+__all__ = ['Dasm16Lexer', 'PuppetLexer', 'AugeasLexer', "TOMLLexer"]
class Dasm16Lexer(RegexLexer):
"""
@@ -360,3 +360,42 @@ class AugeasLexer(RegexLexer):
(r'[\*\)]', Comment.Multiline)
],
}
+
+class TOMLLexer(RegexLexer):
+ """
+ Lexer for TOML, a simple language for config files
+ """
+
+ name = 'TOML'
+ aliases = ['toml']
+ filenames = ['*.toml']
+
+ tokens = {
+ 'root': [
+
+ # Basics, comments, strings
+ (r'\s+', Text),
+ (r'#.*?$', Comment.Single),
+ (r'"(\\\\|\\"|[^"])*"', String),
+ (r'(true|false)$', Keyword.Constant),
+ ('[a-zA-Z_][a-zA-Z0-9_\-]*', Name),
+
+ # Datetime
+ (r'\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z', Number.Integer),
+
+ # Numbers
+ (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?j?', Number.Float),
+ (r'\d+[eE][+-]?[0-9]+j?', Number.Float),
+ (r'\-?\d+', Number.Integer),
+
+ # Punctuation
+ (r'[]{}:(),;[]', Punctuation),
+ (r'\.', Punctuation),
+
+ # Operators
+ (r'=', Operator)
+
+ ]
+ }
+
+

0 comments on commit 2216328

Please sign in to comment.