exalted_math 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +10 -12
- data/VERSION +1 -1
- data/exalted_math.gemspec +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -5,35 +5,33 @@ implement simple (or not so simple) parsing of mathematics for Exalted character
|
|
5
5
|
sheets. Although I'm sure it could be used for other simple math situations.
|
6
6
|
It consists of two parts; parser and abstract syntax tree. The parser
|
7
7
|
constructs the abstract syntax tree as it parses the input string. The AST can
|
8
|
-
then be used to compute the value of the expression with a given context.
|
9
|
-
AST also
|
10
|
-
array class, which makes it very easy to serialize.
|
8
|
+
then be used to compute the value of the expression with a given context.
|
9
|
+
The AST can also simply itself, factoring out constant operations in some cases.
|
11
10
|
|
12
11
|
== Examples
|
13
12
|
|
14
|
-
@parser =
|
13
|
+
@parser = ExaltedMath::MathsParser.new
|
15
14
|
|
16
15
|
# simple maths
|
17
|
-
# The
|
18
|
-
#
|
19
|
-
# The second value is the AST, or failure message if it failed
|
16
|
+
# The parser returns the AST
|
17
|
+
# it raises a ParseFailedError in the case of error
|
20
18
|
@parser.ast('3 + 4')
|
21
|
-
#=>
|
19
|
+
#=> simple_ast
|
22
20
|
|
23
21
|
# symbolic values
|
24
22
|
@parser.ast('Essence * 4')
|
25
|
-
#=>
|
23
|
+
#=> symbolic_ast
|
26
24
|
|
27
25
|
# complex maths
|
28
26
|
@parser.ast('(Essence * 4) + Willpower + highest[2](Compassion,Conviction,Temperance,Valor)')
|
29
|
-
#=>
|
27
|
+
#=> complex_ast
|
30
28
|
|
31
29
|
# evaluate the Ast
|
32
|
-
|
30
|
+
simple_ast.value
|
33
31
|
#=> 7
|
34
32
|
|
35
33
|
# evaluate a more complex Ast
|
36
|
-
|
34
|
+
symbolic_ast.value({'essence' => 4})
|
37
35
|
#=> 16
|
38
36
|
|
39
37
|
== Syntax
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/exalted_math.gemspec
CHANGED