diff options
author | Georg Brandl <georg@python.org> | 2014-03-24 07:36:43 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-03-24 07:36:43 +0100 |
commit | 4506c64add175aec620041c42f06505208efc02c (patch) | |
tree | 7073987e3e10a6f1e908916f32a1a353c9a8156b | |
parent | 88a617097cd61d3568a1a5717d2ed7bf2d182876 (diff) | |
parent | 5cb22b30f482466d27cfd0a0023b59899a9497f4 (diff) | |
download | pygments-4506c64add175aec620041c42f06505208efc02c.tar.gz |
Merged in crazymaster/pygments-main (pull request #295)
Add alias for elisp
-rw-r--r-- | pygments/lexers/__init__.py | 3 | ||||
-rw-r--r-- | pygments/lexers/compiled.py | 38 | ||||
-rw-r--r-- | pygments/lexers/functional.py | 7 | ||||
-rw-r--r-- | pygments/lexers/text.py | 2 | ||||
-rw-r--r-- | tests/examplefiles/example.inf | 22 | ||||
-rw-r--r-- | tests/test_basic_api.py | 9 |
6 files changed, 53 insertions, 28 deletions
diff --git a/pygments/lexers/__init__.py b/pygments/lexers/__init__.py index 7bcf3bf0..caedd479 100644 --- a/pygments/lexers/__init__.py +++ b/pygments/lexers/__init__.py @@ -82,6 +82,9 @@ def get_lexer_by_name(_alias, **options): """ Get a lexer by an alias. """ + if not _alias: + raise ClassNotFound('no lexer for alias %r found' % _alias) + # lookup builtin lexers for module_name, name, aliases, _, _ in itervalues(LEXERS): if _alias.lower() in aliases: diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 2fba337d..db69fdc6 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -1423,7 +1423,7 @@ def objective(baselexer): (r'^([-+])(\s*)' # method marker r'(\(.*?\))?(\s*)' # return type r'([a-zA-Z$_][a-zA-Z0-9$_]*:?)', # begin of method name - bygroups(Keyword, Text, using(this), + bygroups(Punctuation, Text, using(this), Text, Name.Function), 'method'), inherit, @@ -1448,6 +1448,8 @@ def objective(baselexer): return 1.0 elif '@"' in text: # strings return 0.8 + elif re.search('@[0-9]+', text): + return 0.7 elif _oc_message.search(text): return 0.8 return 0 @@ -4015,7 +4017,6 @@ class Inform6Lexer(RegexLexer): Operator, '_expression'), (r'(has|hasnt|in|notin|ofclass|or|provides)\b', Operator.Word, '_expression'), - (r'(from|near|to)\b', Keyword, '_expression'), (r'sp\b', Name), (r'\?~?', Name.Label, 'label?'), (r'[@{]', Error), @@ -4034,6 +4035,10 @@ class Inform6Lexer(RegexLexer): (r':', Punctuation, '#pop'), include('expression') ], + '_keyword-expression': [ + (r'(from|near|to)\b', Keyword, '_expression'), + include('expression') + ], '_list-expression': [ (r',', Punctuation, '#pop'), include('expression') @@ -4086,13 +4091,16 @@ class Inform6Lexer(RegexLexer): # Other built-in symbols (r'(?i)(call|copy|create|DEBUG|destroy|DICT_CHAR_SIZE|' r'DICT_ENTRY_BYTES|DICT_IS_UNICODE|DICT_WORD_SIZE|false|' - r'FLOAT_INFINITY|FLOAT_NAN|FLOAT_NINFINITY|Grammar__Version|' - r'INDIV_PROP_START|INFIX|infix__watching|MODULE_MODE|name|' - r'nothing|NUM_ATTR_BYTES|print|print_to_array|recreate|remaining|' - r'self|sender|STRICT_MODE|sw__var|sys__glob0|sys__glob1|' - r'sys__glob2|sys_statusline_flag|TARGET_GLULX|TARGET_ZCODE|' - r'temp__global2|temp__global3|temp__global4|temp_global|true|' - r'USE_MODULES|WORDSIZE)\b', Name.Builtin, '#pop'), + r'FLOAT_INFINITY|FLOAT_NAN|FLOAT_NINFINITY|GOBJFIELD_CHAIN|' + r'GOBJFIELD_CHILD|GOBJFIELD_NAME|GOBJFIELD_PARENT|' + r'GOBJFIELD_PROPTAB|GOBJFIELD_SIBLING|GOBJ_EXT_START|' + r'GOBJ_TOTAL_LENGTH|Grammar__Version|INDIV_PROP_START|INFIX|' + r'infix__watching|MODULE_MODE|name|nothing|NUM_ATTR_BYTES|print|' + r'print_to_array|recreate|remaining|self|sender|STRICT_MODE|' + r'sw__var|sys__glob0|sys__glob1|sys__glob2|sys_statusline_flag|' + r'TARGET_GLULX|TARGET_ZCODE|temp__global2|temp__global3|' + r'temp__global4|temp_global|true|USE_MODULES|WORDSIZE)\b', + Name.Builtin, '#pop'), # Other values (_name, Name, '#pop') ], @@ -4325,9 +4333,9 @@ class Inform6Lexer(RegexLexer): include('_whitespace'), (r'\]', Punctuation, '#pop'), (r'[;{}]', Punctuation), - (r'(box|break|continue|default|give|inversion|move|new_line|quit|' - r'read|remove|return|rfalse|rtrue|spaces|string|until)\b', - Keyword, 'default'), + (r'(box|break|continue|default|give|inversion|new_line|quit|read|' + r'remove|return|rfalse|rtrue|spaces|string|until)\b', Keyword, + 'default'), (r'(do|else)\b', Keyword), (r'(font|style)\b', Keyword, ('default', 'miscellaneous-keyword?')), @@ -4335,13 +4343,15 @@ class Inform6Lexer(RegexLexer): (r'(if|switch|while)', Keyword, ('expression', '_expression', '(?')), (r'(jump|save|restore)\b', Keyword, ('default', 'label?')), - (r'objectloop\b', Keyword, ('expression', 'variable?', '(?')), + (r'objectloop\b', Keyword, + ('_keyword-expression', 'variable?', '(?')), (r'print(_ret)?\b|(?=[%s])' % _dquote, Keyword, 'print-list'), (r'\.', Name.Label, 'label?'), (r'@', Keyword, 'opcode'), (r'#(?![agrnw]\$|#)', Punctuation, 'directive'), (r'<', Punctuation, 'default'), - (r'', Text, 'default') + (r'(move\b)?', Keyword, + ('default', '_keyword-expression', '_expression')) ], 'miscellaneous-keyword?': [ include('_whitespace'), diff --git a/pygments/lexers/functional.py b/pygments/lexers/functional.py index 5552cd46..122114fa 100644 --- a/pygments/lexers/functional.py +++ b/pygments/lexers/functional.py @@ -996,7 +996,7 @@ class HaskellLexer(RegexLexer): ], 'character': [ # Allows multi-chars, incorrectly. - (r"[^\\']", String.Char), + (r"[^\\']'", String.Char, '#pop'), (r"\\", String.Escape, 'escape'), ("'", String.Char, '#pop'), ], @@ -2532,7 +2532,7 @@ class NixLexer(RegexLexer): ('(%s)' % '|'.join(re.escape(entry) + '\\b' for entry in builtins), Name.Builtin), - (r'\b(true|false)\b', Name.Constant), + (r'\b(true|false|null)\b', Name.Constant), # operators ('(%s)' % '|'.join(re.escape(entry) for entry in operators), @@ -2559,7 +2559,8 @@ class NixLexer(RegexLexer): (r'[a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9%/?:@&=+$,\\_.!~*\'-]+', Literal), # names of variables - (r'[a-zA-Z_][a-zA-Z0-9_\'-]*', String.Symbol), + (r'[a-zA-Z0-9-_]+\s*=', String.Symbol), + (r'[a-zA-Z_][a-zA-Z0-9_\'-]*', Text), ], 'comment': [ diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py index 8de786c2..1bab62f3 100644 --- a/pygments/lexers/text.py +++ b/pygments/lexers/text.py @@ -842,7 +842,7 @@ class VimLexer(RegexLexer): # TODO: regexes can have other delims (r'/(\\\\|\\/|[^\n/])*/', String.Regex), (r'"(\\\\|\\"|[^\n"])*"', String.Double), - (r"'(\\\\|\\'|[^\n'])*'", String.Single), + (r"'(''|[^\n'])*'", String.Single), # Who decided that doublequote was a good comment character?? (r'(?<=\s)"[^\-:.%#=*].*', Comment), diff --git a/tests/examplefiles/example.inf b/tests/examplefiles/example.inf index bc163de9..73cdd087 100644 --- a/tests/examplefiles/example.inf +++ b/tests/examplefiles/example.inf @@ -8,8 +8,8 @@ Switches d2SDq; Constant Story "Informal Testing"; Constant Headline "^Not a game.^";!% This is a comment, not ICL. -Release 1; -Serial "140128"; +Release 2; +Serial "140308"; Version 5; Ifndef TARGET_ZCODE; @@ -58,6 +58,7 @@ Array table buffer 260; Attribute reversed; Attribute opaque alias locked; +Constant to reversed; Property long additive additive long alias; Property long long long wingspan alias alias; @@ -271,7 +272,7 @@ Extend only 'feel' 'touch' replace * noun -> Feel; 1, 9: box "Testing oneself is best when done alone." " -- Jimmy Carter"; - 2, 6, 3 to 5: + 2, 6, to, 3 to 5, to to to: <Take pigeon>; #Ifdef VN_1633; <Jump, person>; @@ -357,13 +358,16 @@ Extend only 'feel' 'touch' replace * noun -> Feel; [ FeelSub; print_ret (The) noun, " feels normal."; ]; -Global to; -[ ReverseSub; - to = parent(noun); +[ ReverseSub from; + from = parent(noun); move noun to parent(second); - move second to to; - give noun reversed; - give second reversed; + if (from == to) + move second to to; + else + move second to from; + give noun to; + from = to; + give second from; "You swap ", (the) noun, " and ", (the) second, "."; ]; diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index e89b5c31..be7a4747 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -16,7 +16,7 @@ from pygments import lexers, formatters, filters, format from pygments.token import _TokenType, Text from pygments.lexer import RegexLexer from pygments.formatters.img import FontNotFound -from pygments.util import text_type, StringIO, xrange +from pygments.util import text_type, StringIO, xrange, ClassNotFound import support @@ -138,6 +138,13 @@ def test_get_lexers(): for mimetype in mimetypes: assert cls == lexers.get_lexer_for_mimetype(mimetype).__class__.__name__ + try: + lexers.get_lexer_by_name(None) + except ClassNotFound: + pass + else: + raise Exception + def test_formatter_public_api(): ts = list(lexers.PythonLexer().get_tokens("def f(): pass")) |