Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add TOML custom lexer #63

Merged
merged 2 commits into from

2 participants

@tnm
Collaborator

Adds a simple lexer for https://github.com/mojombo/toml

@tnm tnm merged commit 2216328 into from
@tnm tnm deleted the branch
@nathany

Any plans to submit this to Pygments proper?

@tnm
Collaborator

@nathany — Totally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 25, 2013
  1. @tnm

    Add custom TOML lexer

    tnm authored
  2. @tnm

    Update lexers

    tnm authored
This page is out of date. Refresh to see the latest.
View
BIN  lexers
Binary file not shown
View
41 vendor/custom_lexers/github.py
@@ -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)
+
+ ]
+ }
+
+
View
1  vendor/pygments-main/pygments/lexers/_mapping.py
@@ -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',)),
View
41 vendor/pygments-main/pygments/lexers/github.py
@@ -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)
+
+ ]
+ }
+
+
Something went wrong with that request. Please try again.