From 96dc20c6fb5ba32d879458de2dcf4d6cadfde0d4 Mon Sep 17 00:00:00 2001 From: Junichi Kobayashi Date: Thu, 26 Sep 2024 01:35:49 +0900 Subject: [PATCH] Add a integration test case --- spec/fixtures/integration/ielr.l | 34 ++++++ spec/lrama/state_spec.rb | 25 +--- spec/lrama/states_spec.rb | 200 ++++++++++++++++++++++++++++++- 3 files changed, 234 insertions(+), 25 deletions(-) create mode 100644 spec/fixtures/integration/ielr.l diff --git a/spec/fixtures/integration/ielr.l b/spec/fixtures/integration/ielr.l new file mode 100644 index 00000000..f4d782d6 --- /dev/null +++ b/spec/fixtures/integration/ielr.l @@ -0,0 +1,34 @@ +%option noinput nounput noyywrap never-interactive bison-bridge bison-locations + +%{ + +#include +#include +#include "bison-generated.h" +#include "bison-generated-lexer.h" + +%} + +%% + + +[abc] { + return yytext[0]; +} + +[\n|\r\n] { + return(YYEOF); +} + +[[:space:]] {} + +<> { + return(YYEOF); +} + +. { + fprintf(stderr, "Illegal character '%s'\n", yytext); + return(YYEOF); +} + +%% diff --git a/spec/lrama/state_spec.rb b/spec/lrama/state_spec.rb index df20b1df..0c6a994d 100644 --- a/spec/lrama/state_spec.rb +++ b/spec/lrama/state_spec.rb @@ -1,29 +1,6 @@ RSpec.describe Lrama::State do - let(:grammar) { <<-FILE } - %union { - int val; - } - - %token a - %token b - %token c - %define lr.type ielr - - %% - S: a A B a - | b A B b - A: a C D E - B: c - | // empty - C: D - D: a - E: a - | // empty - %% - FILE - - describe '#internal_dependencies' do + subject { state.internal_dependencies(*goto) } end end diff --git a/spec/lrama/states_spec.rb b/spec/lrama/states_spec.rb index c4d4cf0f..a717d14c 100644 --- a/spec/lrama/states_spec.rb +++ b/spec/lrama/states_spec.rb @@ -1795,9 +1795,207 @@ class go to state 5 grammar = Lrama::Parser.new(y, path).parse grammar.prepare grammar.validate! - states = Lrama::States.new(grammar, warning) + states = Lrama::States.new(grammar) states.compute states.compute_ielr + + io = StringIO.new + states.reporter.report(io, states: true) + + expect(io.string).to eq(<<~STR) + State 14 conflicts: 2 shift/reduce + + + State 0 + + 0 $accept: • S "end of file" + + a shift, and go to state 1 + b shift, and go to state 2 + + S go to state 3 + + + State 1 + + 1 S: a • A B a + + a shift, and go to state 4 + + A go to state 5 + + + State 2 + + 2 S: b • A B b + + a shift, and go to state 19 + + A go to state 6 + + + State 3 + + 0 $accept: S • "end of file" + + "end of file" shift, and go to state 7 + + + State 4 + + 3 A: a • C D E + + a shift, and go to state 8 + + C go to state 9 + D go to state 10 + + + State 5 + + 1 S: a A • B a + + c shift, and go to state 11 + + $default reduce using rule 5 (B) + + B go to state 12 + + + State 6 + + 2 S: b A • B b + + c shift, and go to state 11 + + $default reduce using rule 5 (B) + + B go to state 13 + + + State 7 + + 0 $accept: S "end of file" • + + $default accept + + + State 8 + + 7 D: a • + + $default reduce using rule 7 (D) + + + State 9 + + 3 A: a C • D E + + a shift, and go to state 8 + + D go to state 14 + + + State 10 + + 6 C: D • + + $default reduce using rule 6 (C) + + + State 11 + + 4 B: c • + + $default reduce using rule 4 (B) + + + State 12 + + 1 S: a A B • a + + a shift, and go to state 15 + + + State 13 + + 2 S: b A B • b + + b shift, and go to state 16 + + + State 14 + + 3 A: a C D • E + + a shift, and go to state 17 + + a reduce using rule 9 (E) + b reduce using rule 9 (E) + c reduce using rule 9 (E) + + E go to state 18 + + + State 15 + + 1 S: a A B a • + + $default reduce using rule 1 (S) + + + State 16 + + 2 S: b A B b • + + $default reduce using rule 2 (S) + + + State 17 + + 8 E: a • + + $default reduce using rule 8 (E) + + + State 18 + + 3 A: a C D E • + + $default reduce using rule 3 (A) + + + State 19 + + 3 A: a • C D E + + a shift, and go to state 8 + + C go to state 20 + D go to state 10 + + + State 20 + + 3 A: a C • D E + + a shift, and go to state 8 + + D go to state 21 + + + State 21 + + 3 A: a C D • E + + a shift, and go to state 17 + + $default reduce using rule 9 (E) + + E go to state 18 + + + STR end end end