forked from pygments/pygments
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Smithy Lexer * Added Smithy Lexer auhtor * Documented Smithy as a supported language * Added Smithy test file and output
- Loading branch information
1 parent
a768fb9
commit dab6b73
Showing
6 changed files
with
1,560 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Smithy IDL lexer | ||
~~~~~~~~~~~~~~~~ | ||
Lexers for the Smithy IDL. | ||
""" | ||
|
||
import re | ||
|
||
from pygments.lexer import RegexLexer, default, include, bygroups | ||
from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ | ||
Number, Literal | ||
|
||
__all__ = ['SmithyLexer'] | ||
|
||
|
||
class SmithyLexer(RegexLexer): | ||
""" | ||
For Smithy IDL | ||
""" | ||
name = 'Smithy' | ||
filenames = ['*.smithy'] | ||
aliases = ['smithy', 'Smithy'] | ||
|
||
flags = re.MULTILINE | re.UNICODE | ||
unquoted = r'[A-Z-a-z0-9_\.#$-]+' | ||
identifier = r"[A-Z-a-z0-9_\.#$-]+" | ||
|
||
tokens = { | ||
'root': [ | ||
(r'///.*$', Comment.Multiline), | ||
(r'//.*$', Comment), | ||
(r'@[0-9a-zA-Z\.#-]*', Name.Decorator), | ||
(r'(=)', Name.Decorator), | ||
(r'^(\$version)(:)(.+)', bygroups(Keyword.Declaration, Name.Decorator, Name.Class)), | ||
(r'^(namespace)(\s+' + identifier + r')\b', bygroups(Keyword.Declaration, Name.Class)), | ||
(r'^(use|byte|short|integer|long|float|' | ||
r'document|double|bigInteger|bigDecimal|boolean|blob|string|timestamp)(\s+' + identifier + r')\b', | ||
bygroups(Keyword.Declaration, Name.Class)), | ||
(r'^(apply|list|map|set|structure|union|resource|operation|service|trait)(\s+' + identifier + r')', | ||
bygroups(Keyword.Declaration, Name.Class)), | ||
(r'^(metadata)(\s+.+)\s*(=)', | ||
bygroups(Keyword.Declaration, Name.Class, Name.Decorator)), | ||
(r"(true|false|null)", Keyword.Constant), | ||
(r"(-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)", Number), | ||
(identifier + ":", Name.Label), | ||
(identifier, Name.Variable.Class), | ||
(r'\[', Text, "#push"), | ||
(r'\]', Text, "#pop"), | ||
(r'\(', Text, "#push"), | ||
(r'\)', Text, "#pop"), | ||
(r'{', Text, "#push"), | ||
(r'}', Text, "#pop"), | ||
(r'"{3}(\\\\|\n|\\")*"{3}', String.Doc), | ||
(r'"(\\\\|\n|\\"|[^"])*"', String.Double), | ||
(r"'(\\\\|\n|\\'|[^'])*'", String.Single), | ||
(r'[:,\s]+', Text), | ||
] | ||
} |
Oops, something went wrong.