diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/compiled.py | 52 | ||||
-rw-r--r-- | tests/examplefiles/qsort.prolog | 13 | ||||
-rw-r--r-- | tests/examplefiles/sibling.prolog | 19 |
5 files changed, 86 insertions, 2 deletions
@@ -19,7 +19,8 @@ Version 1.1 * GLSL (#369) * Erlang shell - * (Ba)sh shell + * (Ba)sh shell (#349) + * Prolog (#373) Version 1.0 diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 4db345e7..0bbe91bc 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -112,6 +112,7 @@ LEXERS = { 'PerlLexer': ('pygments.lexers.agile', 'Perl', ('perl', 'pl'), ('*.pl', '*.pm'), ('text/x-perl', 'application/x-perl')), 'PhpLexer': ('pygments.lexers.web', 'PHP', ('php', 'php3', 'php4', 'php5'), ('*.php', '*.php[345]'), ('text/x-php',)), 'PovrayLexer': ('pygments.lexers.other', 'POVRay', ('pov',), ('*.pov', '*.inc'), ('text/x-povray',)), + 'PrologLexer': ('pygments.lexers.compiled', 'prolog', ('plog',), ('*.prolog', '*.pro'), ('text/x-prolog',)), 'Python3Lexer': ('pygments.lexers.agile', 'Python 3', ('python3', 'py3'), (), ('text/x-python3', 'application/x-python3')), 'Python3TracebackLexer': ('pygments.lexers.agile', 'Python 3.0 Traceback', ('py3tb',), ('*.py3tb',), ('text/x-python3-traceback',)), 'PythonConsoleLexer': ('pygments.lexers.agile', 'Python console session', ('pycon',), (), ('text/x-python-doctest',)), diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 525c84b0..cd96c1fa 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -29,7 +29,7 @@ from pygments.lexers.functional import OcamlLexer __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'JavaLexer', 'ScalaLexer', 'DylanLexer', 'OcamlLexer', 'ObjectiveCLexer', 'FortranLexer', - 'GLShaderLexer'] + 'GLShaderLexer', 'PrologLexer'] class CLexer(RegexLexer): @@ -1330,3 +1330,53 @@ class GLShaderLexer(RegexLexer): (r'\s+', Text), ], } + +class PrologLexer(RegexLexer): + name = 'prolog' + aliases = ['plog'] + filenames = ['*.prolog', '*.pro'] + mimetypes = ['text/x-prolog'] + + flags = re.UNICODE + + tokens = { + 'root': [ + (r'^#.*', Comment), + (r'/\*', Comment, 'nested-comment'), + (r'%.*', Comment), + (r'[0-9]+', Number), + (r'[\[\](){}|.,;!]', Punctuation), + (r':-|-->', Punctuation), + (r'"(?:\\x[0-9a-fA-F]+\\|\\u[0-9a-fA-F]{4}|\U[0-9a-fA-F]{8}|' + r'\\[0-7]+\\|\\[\w\W]|[^"]+)*"', String.Double), + (r"'(?:''|[^']+)*'", String.Atom), # quoted atom + # Needs to not be followed by an atom. + #(r'=(?=\s|[a-zA-Z\[])', Operator), + (r'(is|<|>|=<|>=|==|=:=|=|/|//|\*|\+|-)(?=\s|[a-zA-Z0-9\[])', Operator), + (r'(mod|div|not)\b', Operator), + (r'_', Keyword), # The don't-care variable + (r'([a-z]+)(:)', bygroups(Name.Namespace, Punctuation)), + (ur'([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]' + ur'[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*)' + ur'(\s*)(:-|-->)', + bygroups(Name.Function, Text, Operator)), # function defn + (ur'([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]' + ur'[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*)' + ur'(\s*)(\()', + bygroups(Name.Function, Text, Punctuation)), + (ur'[a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]' + ur'[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*', + String.Atom), # atom, characters + # This one includes ! + (ur'[#&*+\-./:<=>?@\\^~\u00a1-\u00bf\u2010-\u303f]+', + String.Atom), # atom, graphics + (r'[A-Z_][A-Za-z0-9]*', Name.Variable), + (u'\s+|[\u2000-\u200f\ufff0-\ufffe\uffef]', Text), + ], + 'nested-comment': [ + (r'\*/', Comment, '#pop'), + (r'/\*', Comment, '#push'), + (r'[^*/]+', Comment), + (r'[*/]', Comment), + ], + } diff --git a/tests/examplefiles/qsort.prolog b/tests/examplefiles/qsort.prolog new file mode 100644 index 00000000..d78de6f1 --- /dev/null +++ b/tests/examplefiles/qsort.prolog @@ -0,0 +1,13 @@ +partition([], _, [], []). +partition([X|Xs], Pivot, Smalls, Bigs) :- + ( X @< Pivot -> + Smalls = [X|Rest], + partition(Xs, Pivot, Rest, Bigs) + ; Bigs = [X|Rest], + partition(Xs, Pivot, Smalls, Rest) + ). + +quicksort([]) --> []. +quicksort([X|Xs]) --> + { partition(Xs, X, Smaller, Bigger) }, + quicksort(Smaller), [X], quicksort(Bigger). diff --git a/tests/examplefiles/sibling.prolog b/tests/examplefiles/sibling.prolog new file mode 100644 index 00000000..bc591502 --- /dev/null +++ b/tests/examplefiles/sibling.prolog @@ -0,0 +1,19 @@ +/* Comments /* can nest */ +still a comment +*/ + +:- module(maplist, maplist/3) + +assert(world:done). % asserts + +sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y). + +parent_child(X, Y) :- father_child(X, Y). +parent_child(X, Y) :- mother_child(X, Y). + +mother_child(trude, sally). + +father_child(tom, sally). +father_child(tom, erica). +father_child(mike, tom). + |