Created
May 19, 2009 12:31
-
-
Save ldfallas/114067 to your computer and use it in GitHub Desktop.
First(incomplete) test of creating a Pygments lexer definition for Newspeak
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
class NewspeakLexer(RegexLexer): | |
""" | |
For `Newspeak <http://newspeaklanguage.org/>` syntax. | |
""" | |
name = 'Newspeak' | |
filenames = ['*.ns2'] | |
aliases = ['newspeak', ] | |
mimetypes = ['text/x-newspeak'] | |
tokens = { | |
'root' : [ | |
(r'\b(Newsqueak2)\b',Keyword.Declaration), | |
(r"'[^']*'",String), | |
(r'\b(class)(\s+)([a-zA-Z0-9_]+)(\s*)',bygroups(Keyword.Declaration,Text,Name.Class,Text)), | |
(r'\b(mixin|self|super|private|public|protected|nil|true|false)\b',Keyword), | |
(r'([a-zA-Z0-9_]+\:)(\s*)([a-zA-Z_]\w+)',bygroups(Name.Function,Text,Name.Variable)), | |
(r'([a-zA-Z0-9_]+)(\s*)(=)',bygroups(Name.Attribute,Text,Operator)), | |
(r'<[a-zA-Z0-9_]+>',Comment.Special), | |
include('expressionstat'), | |
include('whitespace') | |
], | |
'expressionstat': [ | |
(r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), | |
(r'\d+', Number.Integer), | |
(r'(:\w+)',Name.Variable), | |
(r'(\w+)(::)',bygroups(Name.Variable,Operator)), | |
(r'(\w+:)',bygroups(Name.Function)), | |
(r'(\w+)',bygroups(Name.Variable)), | |
(r'(\(|\))',Punctuation), | |
(r'(\[|\])',Punctuation), | |
(r'(\{|\})',Punctuation), | |
(r'(\^|\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-|:)',Operator), | |
(r'\.|;',Punctuation), | |
include('whitespace'), | |
include('literals'), | |
], | |
'literals': [ | |
(r'\$.',String), | |
(r"'[^']*'",String), | |
(r"#'[^']*'",String.Symbol), | |
(r"#(\w+:)",String.Symbol), | |
(r"#\w+",String.Symbol), | |
(r"#(\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-)+",String.Symbol) | |
], | |
'whitespace' : [ | |
(r'\n',Text), | |
(r'\s+',Text), | |
(r'"[^"]*"',Comment) | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment