panini 1.1.0 → 1.1.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 +11 -0
- data/VERSION +1 -1
- data/lib/grammar.rb +7 -3
- data/panini.gemspec +1 -1
- data/spec/grammar_spec.rb +13 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -54,6 +54,17 @@ Here's how the grammar from above is defined:
|
|
54
54
|
n_a.add_production(['a']) # A -> 'a'
|
55
55
|
n_b.add_production(['b']) # A -> 'b'
|
56
56
|
|
57
|
+
=== Start Symbols
|
58
|
+
|
59
|
+
In order to derive sentences, the grammar needs a start symbol. Any nonterminal in the grammar can be used as the start symbol. If a start symbol is not explicitly set, then the first nonterminal added to the grammar is used.
|
60
|
+
|
61
|
+
grammar = Panini::Grammar.new
|
62
|
+
|
63
|
+
nt_0 = grammar.add_nonterminal
|
64
|
+
nt_1 = grammar.add_nonterminal
|
65
|
+
|
66
|
+
grammar.start = nt_1
|
67
|
+
|
57
68
|
=== Derivators
|
58
69
|
|
59
70
|
Derivators are objects that take a Panini::Grammar and then apply the rules to generate a sentence. Creating the sentences
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
data/lib/grammar.rb
CHANGED
@@ -8,10 +8,14 @@ module Panini
|
|
8
8
|
@nonterminals = []
|
9
9
|
end
|
10
10
|
|
11
|
-
# Returns the grammar's start symbol. This will
|
12
|
-
# nonterminal added to the grammar.
|
11
|
+
# Returns the grammar's start symbol. This will be the first
|
12
|
+
# nonterminal added to the grammar if it hasn't been specified.
|
13
13
|
def start
|
14
|
-
@nonterminals[0]
|
14
|
+
@start ||= @nonterminals[0]
|
15
|
+
end
|
16
|
+
|
17
|
+
def start=(start)
|
18
|
+
@start = start
|
15
19
|
end
|
16
20
|
|
17
21
|
# Add a nonterminal to the grammar.
|
data/panini.gemspec
CHANGED
data/spec/grammar_spec.rb
CHANGED
@@ -52,8 +52,19 @@ describe "Grammar#start" do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
context "when a start symbol is not specified" do
|
56
|
+
it "returns the first nonterminal" do
|
57
|
+
@g.start.should == @nonterminals[0]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when a start symbol is specified" do
|
62
|
+
before(:each) do
|
63
|
+
@g.start = @nonterminals[1]
|
64
|
+
end
|
65
|
+
it "returns that nonterminal" do
|
66
|
+
@g.start.should == @nonterminals[1]
|
67
|
+
end
|
57
68
|
end
|
58
69
|
|
59
70
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: panini
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- mjbellantoni
|
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
requirements:
|
106
106
|
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
hash:
|
108
|
+
hash: 3016262755013279233
|
109
109
|
segments:
|
110
110
|
- 0
|
111
111
|
version: "0"
|