Skip to content

Commit 6345ea4

Browse files
authored
Merge pull request #19 from Bernardo-MG/develop
Develop
2 parents e865553 + 99ca5fd commit 6345ea4

34 files changed

Lines changed: 1025 additions & 1155 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ __pycache__/
1010
# Distribution / packaging
1111
.Python
1212
env/
13+
venv/
1314
build/
1415
develop-eggs/
1516
dist/

.travis.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@
44
# Using Python for the project
55
language: python
66
python:
7-
- "3.4"
8-
- "3.5"
9-
# Python 3.6 is set to test and deploy the docs in the configuration matrix
10-
#- "3.6"
11-
# PyPy currently is not working with the required dependencies
12-
#- "pypy"
13-
#- "pypy3"
14-
env:
15-
- TEST_DOCS=true
7+
- "3.7"
8+
- "3.8"
169
matrix:
1710
include:
1811
# Tests and deploys docs, also runs coverage report
@@ -25,7 +18,7 @@ addons:
2518

2619
before_install:
2720
# Gets scripts
28-
- git clone -b v1.2.0 --single-branch https://github.com/Bernardo-MG/ci-shell-scripts.git ~/.scripts
21+
- git clone -b v1.2.2 --single-branch https://github.com/Bernardo-MG/ci-shell-scripts.git ~/.scripts
2922
# Sets scripts as executable
3023
- chmod -R +x ~/.scripts/*
3124
# Prepares CI environment
@@ -41,7 +34,7 @@ script:
4134
- ~/.scripts/python/run_tests.sh $DO_TEST_DOCS docs
4235
after_success:
4336
# Documentation deployment
44-
- ~/.scripts/sphinx/build-html.sh $DO_DEPLOY_DOCS docs
45-
- cd ~/sphinx/build/html
37+
- ~/.scripts/python/build_docs.sh $DO_DEPLOY_DOCS
38+
- cd ./build/sphinx/html
4639
- ~/.scripts/deploy/deploy-ssh.sh $DO_DEPLOY_DOCS_RELEASE $DEPLOY_DOCS_USERNAME $DEPLOY_DOCS_PASSWORD $DEPLOY_DOCS_HOST $DEPLOY_DOCS_PORT $DEPLOY_DOCS_PATH_RELEASE
4740
- ~/.scripts/deploy/deploy-ssh.sh $DO_DEPLOY_DOCS_DEVELOP $DEPLOY_DOCS_USERNAME $DEPLOY_DOCS_PASSWORD $DEPLOY_DOCS_HOST $DEPLOY_DOCS_PORT $DEPLOY_DOCS_PATH_DEVELOP

README.rst

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,49 @@ documentation sites:
4141
- The `latest docs`_ are always generated for the latest release, kept in the 'master' branch
4242
- The `development docs`_ are generated from the latest code in the 'develop' branch
4343

44-
You can also create the documentation from the source files, kept in the 'docs'
45-
folder, with the help of `Sphinx`_. For this use the makefile, or the make.bat
46-
file, contained on that folder.
44+
The source files for the docs, a small `Sphinx`_ project, are kept in the 'docs folder.
45+
46+
These can be built if needed:
47+
48+
``python setup.py build_docs``
4749

4850
Prerequisites
4951
~~~~~~~~~~~~~
5052

5153
The project has been tested in the following versions of the interpreter:
5254

53-
- Python 3.4
54-
- Python 3.5
5555
- Python 3.6
56+
- Python 3.7
57+
- Python 3.8
5658

5759
All other dependencies are indicated on the requirements.txt file.
5860

5961
These can be installed with:
6062

61-
``$ 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``
6275

6376
Installing
6477
~~~~~~~~~~
6578

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

69-
``$ pip3 install dice-notation``
82+
``pip install dice-notation``
7083

7184
If needed, manual installation is possible:
7285

73-
``$ python setup.py install``
86+
``python setup.py install``
7487

7588
Usage
7689
-----
@@ -87,7 +100,7 @@ And then use it to parse a dice notation expression::
87100
parser = DiceParser()
88101
dice = parser.parse('1d6+2')
89102

90-
The result can be accessed just by calling the 'roll' method as many times as
103+
The result can be accessed just by calling the 'value' method as many times as
91104
needed, which will generate a new random value each time it is called::
92105

93106
print(dice.roll())
@@ -98,13 +111,13 @@ Testing
98111

99112
The tests included with the project can be run with:
100113

101-
``$ python setup.py test``
114+
``python setup.py test``
102115

103116
This will delegate the execution to tox.
104117

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

107-
``$ python setup.py test -p "py36"``
120+
``python setup.py test -p "py38"``
108121

109122
Collaborate
110123
-----------

dice_notation/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
:license: MIT, see LICENSE for more details.
88
"""
99

10-
__version__ = '1.0.6'
10+
__version__ = '1.1.0'
1111
__license__ = 'MIT'

dice_notation/algebra.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from dice_notation.dice import Rollable
4+
5+
"""
6+
Algebraic classes.
7+
8+
These allow working with algebraic operations for dice notation.
9+
"""
10+
11+
__author__ = 'Benardo Martínez Garrido'
12+
__license__ = 'MIT'
13+
14+
15+
class BinaryOperation(Rollable):
16+
"""
17+
A binary operation. Matching an operator with two operands.
18+
"""
19+
20+
def __init__(self, left, right, operator, operation):
21+
super(BinaryOperation, self).__init__()
22+
self._left = left
23+
self._right = right
24+
self._operator = operator
25+
self._operation = operation
26+
27+
def __str__(self):
28+
return '%s%s%s' % (self._left, self._operator, self._right)
29+
30+
def __repr__(self):
31+
return '<class %s>(left=%r, right=%r, operator=%r)' % \
32+
(self.__class__.__name__, self._left, self._right, self._operator)
33+
34+
def roll(self):
35+
return self._operation(self._left.roll(), self._right.roll())
36+
37+
@property
38+
def left(self):
39+
"""
40+
The left operand.
41+
42+
:return: the left operand
43+
"""
44+
return self._left
45+
46+
@left.setter
47+
def left(self, left):
48+
self._left = left
49+
50+
@property
51+
def right(self):
52+
"""
53+
The right operand.
54+
55+
:return: the right operand
56+
"""
57+
return self._right
58+
59+
@right.setter
60+
def right(self, right):
61+
self._right = right
62+
63+
@property
64+
def operator(self):
65+
"""
66+
The operator.
67+
68+
:return: the operator
69+
"""
70+
return self._operator
71+
72+
@operator.setter
73+
def operator(self, operator):
74+
self._operator = operator
75+
76+
77+
class Number(Rollable):
78+
"""
79+
A numeric constant
80+
"""
81+
82+
def __init__(self, value):
83+
super(Number, self).__init__()
84+
self._value = value
85+
86+
def __str__(self):
87+
return '%s' % (self._value)
88+
89+
def __repr__(self):
90+
return '<class %s>(value=%r)' % \
91+
(self.__class__.__name__, self._value)
92+
93+
def roll(self):
94+
return self._value

dice_notation/dice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ def __init__(self, quantity, sides):
6767
self._sides = sides
6868

6969
def __str__(self):
70-
return '%sd%s' % (self.quantity, self.sides)
70+
return '%sd%s' % (self._quantity, self._sides)
7171

7272
def __repr__(self):
7373
return '<class %s>(quantity=%r, sides=%r)' % \
74-
(self.__class__.__name__, self.quantity, self.sides)
74+
(self.__class__.__name__, self._quantity, self._sides)
7575

7676
@property
7777
def quantity(self):
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+

0 commit comments

Comments
 (0)