Skip to content

Commit c0a66d0

Browse files
committed
Added ANTLR grammar
1 parent c23df9f commit c0a66d0

8 files changed

Lines changed: 626 additions & 427 deletions

File tree

README.rst

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The source files for the docs, a small `Sphinx`_ project, are kept in the 'docs
4545

4646
These can be built if needed:
4747

48-
``$ python setup.py build_docs``
48+
``python setup.py build_docs``
4949

5050
Prerequisites
5151
~~~~~~~~~~~~~
@@ -60,19 +60,30 @@ All other dependencies are indicated on the requirements.txt file.
6060

6161
These can be installed with:
6262

63-
``$ pip install --upgrade -r requirements.txt``
63+
``pip install --upgrade -r requirements.txt``
64+
65+
Building the grammar
66+
~~~~~~~~~~~~~~~~~~~~
67+
68+
First of all install ANTLR `as told here <https://github.com/antlr/antlr4/blob/master/doc/getting-started.md/>`_.
69+
70+
Afterwards, follow `these indications <https://github.com/antlr/antlr4/blob/master/doc/python-target.md/>`_.
71+
72+
The command to generate the parser will be:
73+
74+
``antlr4 -Dlanguage=Python2 DiceNotation.g4 DiceNotationLexer.g4``
6475

6576
Installing
6677
~~~~~~~~~~
6778

6879
The project is offered as a `Pypi package`_, and using pip is the preferred way
6980
to install it. For this use the following command;
7081

71-
``$ pip3 install dice-notation``
82+
``pip install dice-notation``
7283

7384
If needed, manual installation is possible:
7485

75-
``$ python setup.py install``
86+
``python setup.py install``
7687

7788
Usage
7889
-----
@@ -100,13 +111,13 @@ Testing
100111

101112
The tests included with the project can be run with:
102113

103-
``$ python setup.py test``
114+
``python setup.py test``
104115

105116
This will delegate the execution to tox.
106117

107118
It is possible to run just one of the test profiles, in this case the py36 profile:
108119

109-
``$ python setup.py test -p "py36"``
120+
``python setup.py test -p "py36"``
110121

111122
Collaborate
112123
-----------
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Generated from DiceNotationLexer.g4 by ANTLR 4.7.2
2+
# encoding: utf-8
3+
from __future__ import print_function
4+
from antlr4 import *
5+
from io import StringIO
6+
import sys
7+
8+
9+
10+
def serializedATN():
11+
with StringIO() as buf:
12+
buf.write(u"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2")
13+
buf.write(u"\t;\b\1\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t")
14+
buf.write(u"\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\3\2\3\2")
15+
buf.write(u"\3\3\6\3\35\n\3\r\3\16\3\36\3\4\3\4\5\4#\n\4\3\5\3\5")
16+
buf.write(u"\5\5\'\n\5\3\6\3\6\3\7\3\7\3\b\3\b\3\t\3\t\3\n\3\n\3")
17+
buf.write(u"\13\3\13\3\f\6\f\66\n\f\r\f\16\f\67\3\f\3\f\2\2\r\3\3")
18+
buf.write(u"\5\4\7\5\t\6\13\2\r\2\17\2\21\2\23\7\25\b\27\t\3\2\4")
19+
buf.write(u"\4\2FFff\4\2\13\f\17\17\2:\2\3\3\2\2\2\2\5\3\2\2\2\2")
20+
buf.write(u"\7\3\2\2\2\2\t\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27")
21+
buf.write(u"\3\2\2\2\3\31\3\2\2\2\5\34\3\2\2\2\7\"\3\2\2\2\t&\3\2")
22+
buf.write(u"\2\2\13(\3\2\2\2\r*\3\2\2\2\17,\3\2\2\2\21.\3\2\2\2\23")
23+
buf.write(u"\60\3\2\2\2\25\62\3\2\2\2\27\65\3\2\2\2\31\32\t\2\2\2")
24+
buf.write(u"\32\4\3\2\2\2\33\35\4\62;\2\34\33\3\2\2\2\35\36\3\2\2")
25+
buf.write(u"\2\36\34\3\2\2\2\36\37\3\2\2\2\37\6\3\2\2\2 #\5\13\6")
26+
buf.write(u"\2!#\5\r\7\2\" \3\2\2\2\"!\3\2\2\2#\b\3\2\2\2$\'\5\17")
27+
buf.write(u"\b\2%\'\5\21\t\2&$\3\2\2\2&%\3\2\2\2\'\n\3\2\2\2()\7")
28+
buf.write(u"-\2\2)\f\3\2\2\2*+\7/\2\2+\16\3\2\2\2,-\7,\2\2-\20\3")
29+
buf.write(u"\2\2\2./\7\61\2\2/\22\3\2\2\2\60\61\7*\2\2\61\24\3\2")
30+
buf.write(u"\2\2\62\63\7+\2\2\63\26\3\2\2\2\64\66\t\3\2\2\65\64\3")
31+
buf.write(u"\2\2\2\66\67\3\2\2\2\67\65\3\2\2\2\678\3\2\2\289\3\2")
32+
buf.write(u"\2\29:\b\f\2\2:\30\3\2\2\2\7\2\36\"&\67\3\b\2\2")
33+
return buf.getvalue()
34+
35+
36+
class DiceNotationLexer(Lexer):
37+
38+
atn = ATNDeserializer().deserialize(serializedATN())
39+
40+
decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
41+
42+
DSEPARATOR = 1
43+
DIGIT = 2
44+
ADDOPERATOR = 3
45+
MULTOPERATOR = 4
46+
LPAREN = 5
47+
RPAREN = 6
48+
WS = 7
49+
50+
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
51+
52+
modeNames = [ u"DEFAULT_MODE" ]
53+
54+
literalNames = [ u"<INVALID>",
55+
u"'('", u"')'" ]
56+
57+
symbolicNames = [ u"<INVALID>",
58+
u"DSEPARATOR", u"DIGIT", u"ADDOPERATOR", u"MULTOPERATOR", u"LPAREN",
59+
u"RPAREN", u"WS" ]
60+
61+
ruleNames = [ u"DSEPARATOR", u"DIGIT", u"ADDOPERATOR", u"MULTOPERATOR",
62+
u"ADD", u"SUB", u"MULT", u"DIV", u"LPAREN", u"RPAREN",
63+
u"WS" ]
64+
65+
grammarFileName = u"DiceNotationLexer.g4"
66+
67+
def __init__(self, input=None, output=sys.stdout):
68+
super(DiceNotationLexer, self).__init__(input, output=output)
69+
self.checkVersion("4.7.2")
70+
self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
71+
self._actions = None
72+
self._predicates = None
73+
74+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Generated from DiceNotation.g4 by ANTLR 4.7.2
2+
from antlr4 import *
3+
4+
# This class defines a complete listener for a parse tree produced by DiceNotationParser.
5+
class DiceNotationListener(ParseTreeListener):
6+
7+
# Enter a parse tree produced by DiceNotationParser#notation.
8+
def enterNotation(self, ctx):
9+
pass
10+
11+
# Exit a parse tree produced by DiceNotationParser#notation.
12+
def exitNotation(self, ctx):
13+
pass
14+
15+
16+
# Enter a parse tree produced by DiceNotationParser#addOp.
17+
def enterAddOp(self, ctx):
18+
pass
19+
20+
# Exit a parse tree produced by DiceNotationParser#addOp.
21+
def exitAddOp(self, ctx):
22+
pass
23+
24+
25+
# Enter a parse tree produced by DiceNotationParser#multOp.
26+
def enterMultOp(self, ctx):
27+
pass
28+
29+
# Exit a parse tree produced by DiceNotationParser#multOp.
30+
def exitMultOp(self, ctx):
31+
pass
32+
33+
34+
# Enter a parse tree produced by DiceNotationParser#operand.
35+
def enterOperand(self, ctx):
36+
pass
37+
38+
# Exit a parse tree produced by DiceNotationParser#operand.
39+
def exitOperand(self, ctx):
40+
pass
41+
42+
43+
# Enter a parse tree produced by DiceNotationParser#dice.
44+
def enterDice(self, ctx):
45+
pass
46+
47+
# Exit a parse tree produced by DiceNotationParser#dice.
48+
def exitDice(self, ctx):
49+
pass
50+
51+
52+
# Enter a parse tree produced by DiceNotationParser#number.
53+
def enterNumber(self, ctx):
54+
pass
55+
56+
# Exit a parse tree produced by DiceNotationParser#number.
57+
def exitNumber(self, ctx):
58+
pass
59+
60+

0 commit comments

Comments
 (0)