mirror of
https://github.com/declaresub/pygments-xojo.git
synced 2026-05-15 14:15:53 -06:00
Initial commit.
Signed-off-by: Charles <charles@declareSub.com>
This commit is contained in:
commit
cc2fce0f0f
10 changed files with 179 additions and 0 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
*.egg-info
|
||||
__pycache__
|
||||
*.venv
|
||||
.tox
|
||||
*.pyc
|
||||
4
README.md
Normal file
4
README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Pygments-Xojo
|
||||
|
||||
Pygments-Xojo implements Xojo language markup for [Pygments](http://pygments.org/), the
|
||||
Python syntax highlighter.
|
||||
24
make_virtualenv.bash
Executable file
24
make_virtualenv.bash
Executable file
|
|
@ -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
|
||||
2
pytest.ini
Normal file
2
pytest.ini
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[pytest]
|
||||
norecursedirs = .tox *.venv
|
||||
4
requirements.txt
Normal file
4
requirements.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#packages listed here are for local testing use.
|
||||
|
||||
pylint
|
||||
pytest
|
||||
35
setup.py
Normal file
35
setup.py
Normal file
|
|
@ -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}
|
||||
)
|
||||
5
tox.ini
Normal file
5
tox.ini
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[tox]
|
||||
envlist = py27, p34
|
||||
[testenv]
|
||||
deps = -rrequirements.txt
|
||||
commands = py.test
|
||||
5
xojolexer/__init__.py
Normal file
5
xojolexer/__init__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""This version is also read by setup.py."""
|
||||
|
||||
__version__ = '0.0.0'
|
||||
12
xojolexer/tests/test_xojo.py
Normal file
12
xojolexer/tests/test_xojo.py
Normal file
|
|
@ -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()
|
||||
|
||||
83
xojolexer/xojo.py
Normal file
83
xojolexer/xojo.py
Normal file
|
|
@ -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'),
|
||||
],
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue