spec/antelope/constructor_spec.rb in antelope-0.1.9 vs spec/antelope/constructor_spec.rb in antelope-0.1.10
- old
+ new
@@ -1,9 +1,9 @@
describe Generation::Constructor do
let(:grammar) { double("grammar") }
let(:terminal) { token(:TERMINAL) }
- let(:epsilon) { token(nil, nil, :epsilon) }
+ let(:epsilon) { token(:epsilon) }
subject { described_class.new(grammar) }
context "#nullable?" do
context "when given an epsilon token" do
@@ -71,11 +71,11 @@
expect(subject.first(terminal)).to eq [terminal].to_set
end
end
context "when given an array" do
- let(:terminal2) { token(:TERMINAL2) }
+ let(:terminal2) { token(:terminal, :TERMINAL2) }
it "generates a set" do
expect(subject.first([epsilon, terminal])).
to eq [terminal].to_set
expect(subject.first([terminal, terminal2])).
@@ -83,15 +83,18 @@
end
end
context "when given a nonterminal" do
let(:grammar) { with_recognizer }
- let(:nonterminal) { token(:e, nil, :nonterminal) }
+ let(:nonterminal) { token(:nonterminal, :e) }
+ before do
+ p grammar.terminals
+ end
it "generates a set" do
expect(subject.first(nonterminal)).
- to eq [token(:IDENT), token(:STAR, "*")].to_set
+ to eq [token(:terminal, :IDENT), token(:terminal, :STAR, "*")].to_set
end
end
context "when given a bad argument" do
it "raises an error" do
@@ -107,25 +110,27 @@
end
end
context "when given a nonterminal" do
let(:grammar) { with_recognizer }
- let(:nonterminal) { token(:l, nil, :nonterminal) }
+ let(:nonterminal) { token(:nonterminal, :l) }
before do
subject.productions.merge grammar.productions.values.flatten
end
it "generates a set" do
expect(subject.follow(nonterminal)).to eq [
- token(:EQUALS, "="),
- token(:"$")
+ token(:terminal, :EQUALS, "="),
+ token(:terminal, :"$end")
].to_set
end
end
end
- def token(name = nil, value = nil, type = :terminal)
+
+
+ def token(type, name = nil, value = nil, ttype = nil, id = nil)
type = Ace::Token.const_get(type.to_s.capitalize)
- type.new(name, value)
+ type.new(name, ttype, id, value)
end
end