summaryrefslogtreecommitdiff
path: root/pygments/lexers/grammar_notation.py
diff options
context:
space:
mode:
authorhhsprings <xwhhsprings@gmail.com>2015-11-05 18:12:54 +0900
committerhhsprings <xwhhsprings@gmail.com>2015-11-05 18:12:54 +0900
commit666244c83ca89846209c6ae3ad5917b900423c8d (patch)
treea7b7578e38cf4996eb9c91a71f6659e06922d089 /pygments/lexers/grammar_notation.py
parentbb42aa11ad8c91127e9b87d196e8088cf90f4c26 (diff)
downloadpygments-666244c83ca89846209c6ae3ad5917b900423c8d.tar.gz
Add the lexer for original BNF.
Diffstat (limited to 'pygments/lexers/grammar_notation.py')
-rw-r--r--pygments/lexers/grammar_notation.py57
1 files changed, 50 insertions, 7 deletions
diff --git a/pygments/lexers/grammar_notation.py b/pygments/lexers/grammar_notation.py
index 65475646..43171387 100644
--- a/pygments/lexers/grammar_notation.py
+++ b/pygments/lexers/grammar_notation.py
@@ -9,17 +9,60 @@
:license: BSD, see LICENSE for details.
"""
-import re
+from pygments.lexer import RegexLexer, bygroups
+from pygments.token import Punctuation, Text, Comment, Operator, \
+ Keyword, Name, Literal
-from pygments.lexer import RegexLexer, DelegatingLexer, \
- include, bygroups, using, words
-from pygments.token import Punctuation, Other, Text, Comment, Operator, \
- Keyword, Name, String, Number, Whitespace, Literal
+__all__ = ['BnfLexer', 'AbnfLexer']
-__all__ = ['AbnfLexer']
+class BnfLexer(RegexLexer):
+ """
+ This lexer is for grammer 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 distinct `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
+ space (no `spaces`, just space, i.e., ASCII \x020).
+ 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 distinct 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),
+ ],
+ }
-# EBNF shold be moved here, i think.
class AbnfLexer(RegexLexer):
"""