commit cc2fce0f0ff1aa4f8de092e19fc5d78b1845b848 Author: Charles Date: Fri Jul 24 11:25:49 2015 -0400 Initial commit. Signed-off-by: Charles diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..47ded11 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.egg-info +__pycache__ +*.venv +.tox +*.pyc diff --git a/README.md b/README.md new file mode 100644 index 0000000..11294e5 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Pygments-Xojo + +Pygments-Xojo implements Xojo language markup for [Pygments](http://pygments.org/), the +Python syntax highlighter. \ No newline at end of file diff --git a/make_virtualenv.bash b/make_virtualenv.bash new file mode 100755 index 0000000..d38e5f6 --- /dev/null +++ b/make_virtualenv.bash @@ -0,0 +1,24 @@ +#! /bin/bash + + +# Creates virtual environments using the Python executables in $ENV_LIST. Existing +# environments are recreated. + +ENV_LIST="python2.7 python3.4" +ENV_EXT="venv" + +for ENV in $ENV_LIST; + do + ENV_DIR="$ENV.$ENV_EXT" + echo "Creating directory $ENV_DIR" + rm -rf "$ENV_DIR" + mkdir "$ENV_DIR" + echo "Initializing virtualenv." + virtualenv --python="$ENV" "$ENV_DIR" + source "$ENV_DIR/bin/activate" + echo "Installing this package." + pip install --process-dependency-links --editable . + echo "Installing additional packages from requirements.txt." + pip install -r requirements.txt + deactivate + done \ No newline at end of file diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..fc70814 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +norecursedirs = .tox *.venv diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..318af19 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +#packages listed here are for local testing use. + +pylint +pytest diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..05c2400 --- /dev/null +++ b/setup.py @@ -0,0 +1,35 @@ +from setuptools import setup +from setuptools.command.test import test as TestCommand +import os +import sys +import string +import io + + +class Tox(TestCommand): + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + def run_tests(self): + #import here, cause outside the eggs aren't loaded + import tox + errcode = tox.cmdline(self.test_args) + sys.exit(errcode) + +def package_version(): + with io.open('xojolexer/__init__.py', 'r', encoding='utf-8') as f: + for sourceline in f: + if sourceline.strip().startswith('__version__'): + return sourceline.split('=', 1)[1].strip(string.whitespace + '"\'') + else: + raise Exception('Unable to read package version.') + +setup(name='xojolexer', + version=package_version(), + author='Charles Yeomans', + packages=['xojolexer'], + install_requires=['pygments'], + entry_points = {'pygments.lexers': ['xojo = xojolexer.xojo:XojoLexer']}, + cmdclass = {'test': Tox} + ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ac7e7f6 --- /dev/null +++ b/tox.ini @@ -0,0 +1,5 @@ +[tox] +envlist = py27, p34 +[testenv] +deps = -rrequirements.txt +commands = py.test \ No newline at end of file diff --git a/xojolexer/__init__.py b/xojolexer/__init__.py new file mode 100644 index 0000000..f78bbc0 --- /dev/null +++ b/xojolexer/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +"""This version is also read by setup.py.""" + +__version__ = '0.0.0' diff --git a/xojolexer/tests/test_xojo.py b/xojolexer/tests/test_xojo.py new file mode 100644 index 0000000..901bccc --- /dev/null +++ b/xojolexer/tests/test_xojo.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- + +"""Unit tests for xojo module.""" + +from __future__ import absolute_import +from xojolexer.xojo import XojoLexer + +def test_smoke(): + """A basic smoke test.""" + + assert XojoLexer() + \ No newline at end of file diff --git a/xojolexer/xojo.py b/xojolexer/xojo.py new file mode 100644 index 0000000..3bb08cf --- /dev/null +++ b/xojolexer/xojo.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +""" +pygments.lexers.basic +~~~~~~~~~~~~~~~~~~~~~ + +Lexer for the Xojo language. + +:copyright: Copyright 2015 Charles Yeomans. +:license: BSD, see LICENSE for details. +""" + +from __future__ import absolute_import +import re +from pygments.lexer import RegexLexer, words +from pygments.token import Keyword, Name, String, Literal, Number, Punctuation, Comment, \ + Operator, Text + +__all__ = ['XojoLexer'] + +class XojoLexer(RegexLexer): + """Lexer for Xojo.""" + + name = 'xojo' + aliases = ['xojo'] + flags = re.IGNORECASE | re.UNICODE + + #pylint: disable=bad-continuation + IDENTIFIER = r'[^\d\W]\w*' + BUILTINS = ('AddHandler', 'AddressOf', 'Array', 'Call', 'Ctype', 'CurrentMethodName', + 'GetTypeInfo', 'Raise', 'RaiseEvent', 'Redim', 'RemoveHandler', 'WeakAddressOf') + KEYWORDS = ('Aggregates', 'As', 'Assigns', 'Attributes', 'Break', 'ByRef', 'ByVal', + 'Case', 'Catch', 'Class', 'Continue', 'Declare', 'Delegate', 'Do', 'DownTo', 'Each', + 'Enum', 'Else', 'ElseIf', 'End', 'Event', 'Exception', 'Exit', 'Extends', 'Finally', + 'For', 'Function', 'Global', 'Handles', 'If', 'Implements', 'In', 'Inherits', 'Interface', + 'Lib', 'Loop', 'Module', 'Next', 'New', 'Namespace', 'Optional', 'ParamArray', 'Private', + 'Protected', 'Public', 'Return', 'Select', 'Selector', 'Soft', 'Step', 'Structure', + 'Sub', 'Then', 'To', 'Try', 'Until', 'Wend', 'While', 'With', 'WithEvents', + '#if', '#else', '#endif', '#pragma') + OPERATOR_WORDS = ('And', 'Is', 'IsA', 'Mod', 'Not', 'Or', 'Xor') + tokens = { + 'root': [ + (r'\ +', Text), + (words(('const', 'dim', 'static'), suffix=r'\b'), Keyword.Declaration), + (words(('false', 'nil', 'true'), suffix=r'\b'), Keyword.Constant), + (words(BUILTINS, suffix=r'\b'), Name.Builtin), + (words(('Using',), suffix=r'\b'), Keyword.Namespace, 'using_ns'), + (words(('GOTO',), suffix=r'\b'), Keyword.Reserved, 'goto'), + (words(('self', 'me', 'super'), suffix=r'\b'), Name.Builtin.Pseudo), + (words(KEYWORDS, suffix=r'\b'), Keyword.Reserved), + + # Literals + (r'"(""|[^"])*"', String), + (r'&u[0-9a-fA-F]+', Literal), + (r'[0-9]+', Number.Integer), + (r'&b[01]+', Number.Bin), + (r'&o[0-7]+', Number.Oct), + (r'&h[0-9a-fA-F]+', Number.Hex), + (r'&c[0-9a-fA-F]{8}', Literal), + (r'&c[0-9a-fA-F]{6}', Literal), + + # line continuation + (r'_(?!\w)', Punctuation), + (r"\'.*", Comment), + (r'//.*', Comment), + (r'REM\b.*', Comment), + + (r'[\=\+\-\*/^]{1,1}', Operator), + (words(OPERATOR_WORDS, prefix=r'\b', suffix=r'\b'), Operator.Word), + (r'[(),.:]', Punctuation), + (r'[^\d\W]\w*:', Name.Label), + (IDENTIFIER, Name.Variable), + ], + + 'using_ns': [ + (r'\ +', Text), + (r'[^\d\W]\w*(.[^\d\W]\w*)*', Name.Namespace, '#pop'), + ], + + 'goto': [ + (r'\ +', Text), + (IDENTIFIER, Name.Label, '#pop'), + ], + }