From c46507d937492d4921b70697fe4416881d4e9164 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Fri, 27 Nov 2015 11:22:09 -0800 Subject: [PATCH] Fix .gitignore (and add incorrectly ignored file!) --- .gitignore | 18 +++--- util/pygments-lexer/wren/__init__.py | 82 ++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 util/pygments-lexer/wren/__init__.py diff --git a/.gitignore b/.gitignore index bb1afd09..316ac38a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,23 @@ # Build outputs. -bin/ -lib/ -wren +/bin +/lib +/wren # Intermediate files. -build/ -deps/ -.sass-cache/ +/build +/deps +/.sass-cache +*.pyc # I leave a temporary Wren script at the top level so that I can quickly test # stuff. -scratch.wren +/scratch.wren # The baseline file is machine-specific, so doesn't get checked in. -test/benchmark/baseline.txt +/test/benchmark/baseline.txt # XCode user-specific stuff. xcuserdata/ -*.xccheckout # Allow Visual Studio project files. !wren/ diff --git a/util/pygments-lexer/wren/__init__.py b/util/pygments-lexer/wren/__init__.py new file mode 100644 index 00000000..8e14238a --- /dev/null +++ b/util/pygments-lexer/wren/__init__.py @@ -0,0 +1,82 @@ +import re +from pygments import highlight +from pygments.lexers import PythonLexer +from pygments.formatters import HtmlFormatter + +from pygments.lexer import RegexLexer +from pygments.token import * + +class WrenLexer(RegexLexer): + name = 'Wren' + aliases = ['wren'] + filenames = ['*.wren'] + + flags = re.MULTILINE | re.DOTALL + + tokens = { + 'root': [ + # Whitespace. + (r'\s+', Text), + (r'[,\\\[\]{}]', Punctuation), + + # Push a parenthesized state so that we know the corresponding ')' + # is for a parenthesized expression and not interpolation. + (r'\(', Punctuation, ('parenthesized', 'root')), + + # In this state, we don't know whether a closing ')' is for a + # parenthesized expression or the end of an interpolation. So, do + # a non-consuming match and let the parent state (either + # 'parenthesized' or 'interpolation' decide. + (r'(?=\))', Text, '#pop'), + + # Keywords. + (r'(break|class|construct|else|for|foreign|if|import|in|is|' + r'return|static|super|var|while)\b', Keyword), + + (r'(true|false|null)\b', Keyword.Constant), + + (r'this\b', Name.Builtin), + + # Comments. + (r'/\*', Comment.Multiline, 'comment'), + (r'//.*?$', Comment.Single), + + # Names and operators. + (r'[~!$%^&*\-=+\\|/?<>\.:]+', Operator), + (r'[A-Z][a-zA-Z_0-9]+', Name.Variable.Global), + (r'__[a-zA-Z_0-9]+', Name.Variable.Class), + (r'_[a-zA-Z_0-9]+', Name.Variable.Instance), + (r'[a-z][a-zA-Z_0-9]+', Name), + + # Numbers. + (r'\d+\.\d+([eE]-?\d+)?', Number.Float), + (r'0x[0-9a-fA-F]+', Number.Hex), + (r'\d+', Number.Integer), + + # Strings. + (r'L?"', String, 'string'), + ], + 'comment': [ + (r'/\*', Comment.Multiline, '#push'), + (r'\*/', Comment.Multiline, '#pop'), + (r'.', Comment.Multiline), # All other characters. + ], + 'string': [ + (r'"', String, '#pop'), + (r'\\[\\%0abfnrtv"\']', String.Escape), # Escape. + (r'\\x[a-fA-F0-9]{2}', String.Escape), # Byte escape. + (r'\\u[a-fA-F0-9]{4}', String.Escape), # Unicode escape. + (r'\\U[a-fA-F0-9]{8}', String.Escape), # Long Unicode escape. + + (r'%\(', String.Interpol, ('interpolation', 'root')), + (r'.', String), # All other characters. + ], + 'parenthesized': [ + # We only get to this state when we're at a ')'. + (r'\)', Punctuation, '#pop'), + ], + 'interpolation': [ + # We only get to this state when we're at a ')'. + (r'\)', String.Interpol, '#pop'), + ], + }