summaryrefslogtreecommitdiffstats
path: root/contrib/python/Pygments/py3/pygments/lexers/grammar_notation.py
diff options
context:
space:
mode:
authorilezhankin <[email protected]>2022-02-10 16:45:56 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:45:56 +0300
commit62a805381e41500fbc7914c37c71ab040a098f4e (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/python/Pygments/py3/pygments/lexers/grammar_notation.py
parent1d125034f06575234f83f24f08677955133f140e (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/Pygments/py3/pygments/lexers/grammar_notation.py')
-rw-r--r--contrib/python/Pygments/py3/pygments/lexers/grammar_notation.py242
1 files changed, 121 insertions, 121 deletions
diff --git a/contrib/python/Pygments/py3/pygments/lexers/grammar_notation.py b/contrib/python/Pygments/py3/pygments/lexers/grammar_notation.py
index 98190e963e9..ff57c999173 100644
--- a/contrib/python/Pygments/py3/pygments/lexers/grammar_notation.py
+++ b/contrib/python/Pygments/py3/pygments/lexers/grammar_notation.py
@@ -1,135 +1,135 @@
-"""
- pygments.lexers.grammar_notation
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
+"""
+ pygments.lexers.grammar_notation
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
Lexers for grammar notations like BNF.
-
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
- :license: BSD, see LICENSE for details.
-"""
-
+ :license: BSD, see LICENSE for details.
+"""
+
import re
-
+
from pygments.lexer import RegexLexer, bygroups, include, this, using, words
from pygments.token import Comment, Keyword, Literal, Name, Number, \
Operator, Punctuation, String, Text, Whitespace
-
+
__all__ = ['BnfLexer', 'AbnfLexer', 'JsgfLexer', 'PegLexer']
-
-class BnfLexer(RegexLexer):
- """
+
+class BnfLexer(RegexLexer):
+ """
This lexer is for grammar notations which are similar to
- original BNF.
-
- In order to maximize a number of targets of this lexer,
- let's decide some designs:
-
- * We don't distinguish `Terminal Symbol`.
-
- * We do assume that `NonTerminal Symbol` are always enclosed
- with arrow brackets.
-
- * We do assume that `NonTerminal Symbol` may include
- any printable characters except arrow brackets and ASCII 0x20.
- This assumption is for `RBNF <http://www.rfc-base.org/txt/rfc-5511.txt>`_.
-
- * We do assume that target notation doesn't support comment.
-
- * We don't distinguish any operators and punctuation except
- `::=`.
-
- Though these desision making might cause too minimal highlighting
- and you might be disappointed, but it is reasonable for us.
-
- .. versionadded:: 2.1
- """
-
- name = 'BNF'
- aliases = ['bnf']
- filenames = ['*.bnf']
- mimetypes = ['text/x-bnf']
-
- tokens = {
- 'root': [
- (r'(<)([ -;=?-~]+)(>)',
- bygroups(Punctuation, Name.Class, Punctuation)),
-
- # an only operator
- (r'::=', Operator),
-
- # fallback
- (r'[^<>:]+', Text), # for performance
- (r'.', Text),
- ],
- }
-
-
-class AbnfLexer(RegexLexer):
- """
- Lexer for `IETF 7405 ABNF
- <http://www.ietf.org/rfc/rfc7405.txt>`_
- (Updates `5234 <http://www.ietf.org/rfc/rfc5234.txt>`_)
- grammars.
-
- .. versionadded:: 2.1
- """
-
- name = 'ABNF'
- aliases = ['abnf']
- filenames = ['*.abnf']
- mimetypes = ['text/x-abnf']
-
- _core_rules = (
- 'ALPHA', 'BIT', 'CHAR', 'CR', 'CRLF', 'CTL', 'DIGIT',
- 'DQUOTE', 'HEXDIG', 'HTAB', 'LF', 'LWSP', 'OCTET',
- 'SP', 'VCHAR', 'WSP')
-
- tokens = {
- 'root': [
- # comment
- (r';.*$', Comment.Single),
-
- # quoted
- # double quote itself in this state, it is as '%x22'.
- (r'(%[si])?"[^"]*"', Literal),
-
- # binary (but i have never seen...)
- (r'%b[01]+\-[01]+\b', Literal), # range
- (r'%b[01]+(\.[01]+)*\b', Literal), # concat
-
- # decimal
- (r'%d[0-9]+\-[0-9]+\b', Literal), # range
- (r'%d[0-9]+(\.[0-9]+)*\b', Literal), # concat
-
- # hexadecimal
- (r'%x[0-9a-fA-F]+\-[0-9a-fA-F]+\b', Literal), # range
- (r'%x[0-9a-fA-F]+(\.[0-9a-fA-F]+)*\b', Literal), # concat
-
- # repetition (<a>*<b>element) including nRule
- (r'\b[0-9]+\*[0-9]+', Operator),
- (r'\b[0-9]+\*', Operator),
- (r'\b[0-9]+', Operator),
- (r'\*', Operator),
-
- # Strictly speaking, these are not keyword but
- # are called `Core Rule'.
- (words(_core_rules, suffix=r'\b'), Keyword),
-
- # nonterminals (ALPHA *(ALPHA / DIGIT / "-"))
+ original BNF.
+
+ In order to maximize a number of targets of this lexer,
+ let's decide some designs:
+
+ * We don't distinguish `Terminal Symbol`.
+
+ * We do assume that `NonTerminal Symbol` are always enclosed
+ with arrow brackets.
+
+ * We do assume that `NonTerminal Symbol` may include
+ any printable characters except arrow brackets and ASCII 0x20.
+ This assumption is for `RBNF <http://www.rfc-base.org/txt/rfc-5511.txt>`_.
+
+ * We do assume that target notation doesn't support comment.
+
+ * We don't distinguish any operators and punctuation except
+ `::=`.
+
+ Though these desision making might cause too minimal highlighting
+ and you might be disappointed, but it is reasonable for us.
+
+ .. versionadded:: 2.1
+ """
+
+ name = 'BNF'
+ aliases = ['bnf']
+ filenames = ['*.bnf']
+ mimetypes = ['text/x-bnf']
+
+ tokens = {
+ 'root': [
+ (r'(<)([ -;=?-~]+)(>)',
+ bygroups(Punctuation, Name.Class, Punctuation)),
+
+ # an only operator
+ (r'::=', Operator),
+
+ # fallback
+ (r'[^<>:]+', Text), # for performance
+ (r'.', Text),
+ ],
+ }
+
+
+class AbnfLexer(RegexLexer):
+ """
+ Lexer for `IETF 7405 ABNF
+ <http://www.ietf.org/rfc/rfc7405.txt>`_
+ (Updates `5234 <http://www.ietf.org/rfc/rfc5234.txt>`_)
+ grammars.
+
+ .. versionadded:: 2.1
+ """
+
+ name = 'ABNF'
+ aliases = ['abnf']
+ filenames = ['*.abnf']
+ mimetypes = ['text/x-abnf']
+
+ _core_rules = (
+ 'ALPHA', 'BIT', 'CHAR', 'CR', 'CRLF', 'CTL', 'DIGIT',
+ 'DQUOTE', 'HEXDIG', 'HTAB', 'LF', 'LWSP', 'OCTET',
+ 'SP', 'VCHAR', 'WSP')
+
+ tokens = {
+ 'root': [
+ # comment
+ (r';.*$', Comment.Single),
+
+ # quoted
+ # double quote itself in this state, it is as '%x22'.
+ (r'(%[si])?"[^"]*"', Literal),
+
+ # binary (but i have never seen...)
+ (r'%b[01]+\-[01]+\b', Literal), # range
+ (r'%b[01]+(\.[01]+)*\b', Literal), # concat
+
+ # decimal
+ (r'%d[0-9]+\-[0-9]+\b', Literal), # range
+ (r'%d[0-9]+(\.[0-9]+)*\b', Literal), # concat
+
+ # hexadecimal
+ (r'%x[0-9a-fA-F]+\-[0-9a-fA-F]+\b', Literal), # range
+ (r'%x[0-9a-fA-F]+(\.[0-9a-fA-F]+)*\b', Literal), # concat
+
+ # repetition (<a>*<b>element) including nRule
+ (r'\b[0-9]+\*[0-9]+', Operator),
+ (r'\b[0-9]+\*', Operator),
+ (r'\b[0-9]+', Operator),
+ (r'\*', Operator),
+
+ # Strictly speaking, these are not keyword but
+ # are called `Core Rule'.
+ (words(_core_rules, suffix=r'\b'), Keyword),
+
+ # nonterminals (ALPHA *(ALPHA / DIGIT / "-"))
(r'[a-zA-Z][a-zA-Z0-9-]*\b', Name.Class),
-
- # operators
- (r'(=/|=|/)', Operator),
-
- # punctuation
- (r'[\[\]()]', Punctuation),
-
- # fallback
+
+ # operators
+ (r'(=/|=|/)', Operator),
+
+ # punctuation
+ (r'[\[\]()]', Punctuation),
+
+ # fallback
(r'\s+', Whitespace),
- (r'.', Text),
- ],
- }
+ (r'.', Text),
+ ],
+ }
class JsgfLexer(RegexLexer):