panini 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.0
1
+ 1.1.1
@@ -8,10 +8,14 @@ module Panini
8
8
  @nonterminals = []
9
9
  end
10
10
 
11
- # Returns the grammar's start symbol. This will always be the first
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.
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "panini"
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mjbellantoni"]
@@ -52,8 +52,19 @@ describe "Grammar#start" do
52
52
  end
53
53
  end
54
54
 
55
- it "returns the first nonterminal" do
56
- @g.start.should == @nonterminals[0]
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.0
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: -1665720431960213425
108
+ hash: 3016262755013279233
109
109
  segments:
110
110
  - 0
111
111
  version: "0"