summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTinnet Coronam <tinnet@coronam.net>2012-10-13 14:03:15 +0200
committerTinnet Coronam <tinnet@coronam.net>2012-10-13 14:03:15 +0200
commit6625e4e91a96bae48addc17851e6a1332bc2ac91 (patch)
tree5f6ef8d42357f1d2310296f5104e2537f2dbfaca
parent520215091a7b8e4dad1da581b76d10e1d8faf67c (diff)
downloadpygments-6625e4e91a96bae48addc17851e6a1332bc2ac91.tar.gz
added basic monkey lexer
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/monkey.py84
2 files changed, 85 insertions, 0 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index ad44fd4b..a60670dc 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -166,6 +166,7 @@ LEXERS = {
'ModelicaLexer': ('pygments.lexers.other', 'Modelica', ('modelica',), ('*.mo',), ('text/x-modelica',)),
'Modula2Lexer': ('pygments.lexers.compiled', 'Modula-2', ('modula2', 'm2'), ('*.def', '*.mod'), ('text/x-modula2',)),
'MoinWikiLexer': ('pygments.lexers.text', 'MoinMoin/Trac Wiki markup', ('trac-wiki', 'moin'), (), ('text/x-trac-wiki',)),
+ 'MonkeyLexer': ('pygments.lexers.monkey', 'Monkey', ('monkey',), ('*.monkey',), ()),
'MoonScriptLexer': ('pygments.lexers.agile', 'MoonScript', ('moon', 'moonscript'), ('*.moon',), ('text/x-moonscript', 'application/x-moonscript')),
'MscgenLexer': ('pygments.lexers.other', 'Mscgen', ('mscgen', 'msc'), ('*.msc',), ()),
'MuPADLexer': ('pygments.lexers.math', 'MuPAD', ('mupad',), ('*.mu',), ()),
diff --git a/pygments/lexers/monkey.py b/pygments/lexers/monkey.py
new file mode 100644
index 00000000..ad80801c
--- /dev/null
+++ b/pygments/lexers/monkey.py
@@ -0,0 +1,84 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.lexers.monkey
+ ~~~~~~~~~~~~~~~~~~~~~~
+
+ Lexer for the monkey language
+
+ :copyright: Copyright 2012
+ :license: BSD, see LICENSE for details.
+"""
+import re
+
+from pygments.lexer import RegexLexer, DelegatingLexer, bygroups, include, \
+ using, this
+from pygments.token import Punctuation, \
+ Text, Comment, Operator, Keyword, Name, String, Number, Literal, Other
+from pygments.util import get_choice_opt
+from pygments import unistring as uni
+
+from pygments.lexers.web import XmlLexer
+
+__all__ = ['MonkeyLexer']
+
+
+class MonkeyLexer(RegexLexer):
+ """
+ For
+ `Monkey <https://en.wikipedia.org/wiki/Monkey_(programming_language)>`_
+ source code.
+ """
+
+ name = 'Monkey'
+ aliases = ['monkey']
+ filenames = ['*.monkey']
+ mimetypes = [] # (?)
+
+ tokens = {
+ 'root': [
+ (r'\n', Text),
+ (r'\s+', Text),
+ (r"[\s\t]*'.*?$", Comment),
+ (r'^#rem\s(.|\n)*?\n#end$', Comment.Multiline),
+ (r'#If\s.*?|#ElseIf\s.*?|#ElseIf\s.*?|#End|#Print\s.*?|#Error\s.*?', Comment.Preproc),
+ (r'(?<!\.)(Int|Float|String|Bool|Object|Array|Void)\b', Keyword.Type),
+ (r'(\d+\.\d*|\d*\.\d+)([fF][+-]?[0-9]+)?', Number.Float),
+ (r'\d+([SILDFR]|US|UI|UL)?', Number.Integer),
+ (r'&H[0-9a-f]+([SILDFR]|US|UI|UL)?', Number.Integer),
+ (r'&O[0-7]+([SILDFR]|US|UI|UL)?', Number.Integer),
+ (r'(Import)\s+', Keyword.Namespace),
+ (r'(Strict|Import|End|Return|If|Else)\s+', Keyword.Declaration),
+ (r'(?<!\.)(Function|Method)(\s+)', bygroups(Keyword, Text), 'funcname'),
+ (r'(?<!\.)(Class)(\s+)', bygroups(Keyword, Text), 'classname'),
+ (r'New\s+', Keyword.Declaration, 'classname'),
+ (r'(?<!\.)(Local|Field)(\s+)', Keyword, 'variables'),
+ (r'[a-zA-Z_][a-zA-Z0-9_]*[%&@!#$]?', Name),
+ (r'&=|[*]=|/=|\\=|\^=|\+=|-=|<<=|>>=|<<|>>|:=|'
+ r'<=|>=|<>|[-&*/\\^+=<>]',
+ Operator),
+ (r'[\(\){}!#,.:]', Punctuation),
+ ('"', String, 'string'),
+ #(r'[A-Z][a-zA-Z0-9_]+(?=\()', Name.Function),
+ (r'[a-zA-Z_]\w*', Name.Other),
+ ],
+ 'funcname': [
+ (r'[A-Z][a-zA-Z0-9_]*', Name.Function),
+ (r':', Punctuation, 'classname'),
+ (r'\(', Punctuation, 'variables'),
+ (r'\)', Punctuation, '#pop'),
+ ],
+ 'classname': [
+ (r'[A-Z][a-zA-Z0-9_]*', Name.Class, '#pop'),
+ ],
+ 'variables': [
+ (r'[a-z_][a-z0-9_]*?', Name.Variable),
+ (r':', Punctuation, 'classname'),
+ (r',\s?', Punctuation, '#push'),
+ (r'', Text, '#pop'),
+ ],
+ 'string': [
+ (r'""', String),
+ (r'"C?', String, '#pop'),
+ (r'[^"]+', String),
+ ],
+ } \ No newline at end of file