Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Dec 19, 2023
1 parent 7c2c6d6 commit 50385f2
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 13 deletions.
12 changes: 12 additions & 0 deletions spec/fixtures/parameterizing_rules/user_defined_with_nest.y
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ static int yyerror(YYLTYPE *loc, const char *str);

%union {
int i;
char* s;
}

%token <i> number
%token <s> string

%rule nested_nested_option(X): /* empty */
| X
Expand All @@ -26,9 +28,19 @@ static int yyerror(YYLTYPE *loc, const char *str);
| nested_option(Y)
;

%rule nested_multi_option(X): /* empty */
| X
;

%rule multi_option(X, Y): /* empty */
| nested_multi_option(X)
| nested_multi_option(Y) X
;

%%

program : option(number)
| multi_option(number, string)
;

%%
Expand Down
112 changes: 99 additions & 13 deletions spec/lrama/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1383,11 +1383,14 @@
grammar = Lrama::Parser.new(y, path).parse

expect(grammar.nterms.sort_by(&:number)).to match_symbols([
Sym.new(id: T::Ident.new(s_value: "$accept"), alias_name: nil, number: 4, tag: nil, term: false, token_id: 0, nullable: false),
Sym.new(id: T::Ident.new(s_value: "program"), alias_name: nil, number: 5, tag: nil, term: false, token_id: 1, nullable: true),
Sym.new(id: T::Ident.new(s_value: "option_number"), alias_name: nil, number: 6, tag: nil, term: false, token_id: 2, nullable: true),
Sym.new(id: T::Ident.new(s_value: "nested_option_number"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 3, nullable: true),
Sym.new(id: T::Ident.new(s_value: "nested_nested_option_number"), alias_name: nil, number: 8, tag: nil, term: false, token_id: 4, nullable: true)
Sym.new(id: T::Ident.new(s_value: "$accept"), alias_name: nil, number: 5, tag: nil, term: false, token_id: 0, nullable: false),
Sym.new(id: T::Ident.new(s_value: "program"), alias_name: nil, number: 6, tag: nil, term: false, token_id: 1, nullable: true),
Sym.new(id: T::Ident.new(s_value: "option_number"), alias_name: nil, number: 7, tag: nil, term: false, token_id: 2, nullable: true),
Sym.new(id: T::Ident.new(s_value: "nested_option_number"), alias_name: nil, number: 8, tag: nil, term: false, token_id: 3, nullable: true),
Sym.new(id: T::Ident.new(s_value: "nested_nested_option_number"), alias_name: nil, number: 9, tag: nil, term: false, token_id: 4, nullable: true),
Sym.new(id: T::Ident.new(s_value: "multi_option_number_string"), alias_name: nil, number: 10, tag: nil, term: false, token_id: 5, nullable: true),
Sym.new(id: T::Ident.new(s_value: "nested_multi_option_number"), alias_name: nil, number: 11, tag: nil, term: false, token_id: 6, nullable: true),
Sym.new(id: T::Ident.new(s_value: "nested_multi_option_string"), alias_name: nil, number: 12, tag: nil, term: false, token_id: 7, nullable: true)
])

expect(grammar.rules).to eq([
Expand All @@ -1401,7 +1404,7 @@
token_code: nil,
nullable: false,
precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"),
lineno: 31,
lineno: 42,
),
Rule.new(
id: 1,
Expand All @@ -1410,7 +1413,7 @@
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 31,
lineno: 42,
),
Rule.new(
id: 2,
Expand All @@ -1419,7 +1422,7 @@
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 31,
lineno: 42,
),
Rule.new(
id: 3,
Expand All @@ -1428,7 +1431,7 @@
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 31,
lineno: 42,
),
Rule.new(
id: 4,
Expand All @@ -1439,7 +1442,7 @@
token_code: nil,
nullable: false,
precedence_sym: grammar.find_symbol_by_s_value!("number"),
lineno: 31,
lineno: 42,
),
Rule.new(
id: 5,
Expand All @@ -1450,7 +1453,7 @@
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 31,
lineno: 42,
),
Rule.new(
id: 6,
Expand All @@ -1461,7 +1464,7 @@
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 31,
lineno: 42,
),
Rule.new(
id: 7,
Expand All @@ -1472,7 +1475,90 @@
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 31,
lineno: 42,
),
Rule.new(
id: 8,
lhs: grammar.find_symbol_by_s_value!("multi_option_number_string"),
rhs: [],
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 43,
),
Rule.new(
id: 9,
lhs: grammar.find_symbol_by_s_value!("nested_multi_option_number"),
rhs: [],
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 43,
),
Rule.new(
id: 10,
lhs: grammar.find_symbol_by_s_value!("nested_multi_option_number"),
rhs: [
grammar.find_symbol_by_s_value!("number")
],
token_code: nil,
nullable: false,
precedence_sym: grammar.find_symbol_by_s_value!("number"),
lineno: 43,
),
Rule.new(
id: 11,
lhs: grammar.find_symbol_by_s_value!("multi_option_number_string"),
rhs: [
grammar.find_symbol_by_s_value!("nested_multi_option_number")
],
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 43,
),
Rule.new(
id: 12,
lhs: grammar.find_symbol_by_s_value!("nested_multi_option_string"),
rhs: [],
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 43,
),
Rule.new(
id: 13,
lhs: grammar.find_symbol_by_s_value!("nested_multi_option_string"),
rhs: [
grammar.find_symbol_by_s_value!("string")
],
token_code: nil,
nullable: false,
precedence_sym: grammar.find_symbol_by_s_value!("string"),
lineno: 43,
),
Rule.new(
id: 14,
lhs: grammar.find_symbol_by_s_value!("multi_option_number_string"),
rhs: [
grammar.find_symbol_by_s_value!("nested_multi_option_string"),
grammar.find_symbol_by_s_value!("number")
],
token_code: nil,
nullable: false,
precedence_sym: grammar.find_symbol_by_s_value!("number"),
lineno: 43,
),
Rule.new(
id: 15,
lhs: grammar.find_symbol_by_s_value!("program"),
rhs: [
grammar.find_symbol_by_s_value!("multi_option_number_string")
],
token_code: nil,
nullable: true,
precedence_sym: nil,
lineno: 43,
),
])
end
Expand Down

0 comments on commit 50385f2

Please sign in to comment.