--- a/eric6/ThirdParty/Pygments/pygments/lexers/grammar_notation.py Tue Apr 21 19:44:19 2020 +0200 +++ b/eric6/ThirdParty/Pygments/pygments/lexers/grammar_notation.py Tue Apr 21 19:47:10 2020 +0200 @@ -5,7 +5,7 @@ Lexers for grammer notations like BNF. - :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ @@ -15,7 +15,7 @@ from pygments.token import Comment, Keyword, Literal, Name, Number, \ Operator, Punctuation, String, Text -__all__ = ['BnfLexer', 'AbnfLexer', 'JsgfLexer'] +__all__ = ['BnfLexer', 'AbnfLexer', 'JsgfLexer', 'PegLexer'] class BnfLexer(RegexLexer): @@ -211,3 +211,60 @@ (r'.', Comment.Multiline), ], } + + +class PegLexer(RegexLexer): + """ + This lexer is for `Parsing Expression Grammars + <https://bford.info/pub/lang/peg.pdf>`_ (PEG). + + Various implementations of PEG have made different decisions + regarding the syntax, so let's try to be accommodating: + + * `<-`, `←`, `:`, and `=` are all accepted as rule operators. + + * Both `|` and `/` are choice operators. + + * `^`, `↑`, and `~` are cut operators. + + * A single `a-z` character immediately before a string, or + multiple `a-z` characters following a string, are part of the + string (e.g., `r"..."` or `"..."ilmsuxa`). + + .. versionadded:: 2.6 + """ + + name = 'PEG' + aliases = ['peg'] + filenames = ['*.peg'] + mimetypes = ['text/x-peg'] + + tokens = { + 'root': [ + # Comments + (r'#.*', Comment.Single), + + # All operators + (r'<-|[←:=/|&!?*+^↑~]', Operator), + + # Other punctuation + (r'[()]', Punctuation), + + # Keywords + (r'\.', Keyword), + + # Character classes + (r'(\[)([^\]]*(?:\\.[^\]\\]*)*)(\])', + bygroups(Punctuation, String, Punctuation)), + + # Single and double quoted strings (with optional modifiers) + (r'[a-z]?"[^"\\]*(?:\\.[^"\\]*)*"[a-z]*', String.Double), + (r"[a-z]?'[^'\\]*(?:\\.[^'\\]*)*'[a-z]*", String.Single), + + # Nonterminals are not whitespace, operators, or punctuation + (r'[^\s<←:=/|&!?*+\^↑~()\[\]"\'#]+', Name.Class), + + # Fallback + (r'.', Text), + ], + }