Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning output when using %require, which exists only for compatibility with Bison #478

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/lrama/parser.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rule
{
@grammar.prologue = val[2].s_value
}
| "%require" STRING
| "%require" STRING { warn '%require is provided for compatibility with Bison and can be removed after migration to Lrama.' }

bison_declaration: grammar_declaration
| "%expect" INTEGER { @grammar.expect = val[1] }
Expand Down
2 changes: 0 additions & 2 deletions spec/fixtures/common/basic.y
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* This is comment for this file.
*/

%require "3.0"

%{
// Prologue
%}
Expand Down
2 changes: 0 additions & 2 deletions spec/fixtures/common/nullable.y
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* This is comment for this file.
*/

%require "3.0"

%{
// Prologue
%}
Expand Down
2 changes: 0 additions & 2 deletions spec/fixtures/context/basic.y
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* This is comment for this file.
*/

%require "3.0"

%{
// Prologue
%}
Expand Down
4 changes: 2 additions & 2 deletions spec/lrama/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
expect(context.yytname[context.yytranslate[11]]).to eq("\"escaped vertical tab\"")
expect(context.yytname[context.yytranslate[258]]).to eq("keyword_class")
expect(context.yyrline).to eq([
0, 64, 64, 65, 66, 69, 71, 71, 74, 77,
78, 81, 84, 87
0, 62, 62, 63, 64, 67, 69, 69, 72, 75,
76, 79, 82, 85
])
expect(context.yytname).to eq([
"\"EOI\"", "error", "\"invalid token\"", "\"backslash\"",
Expand Down
30 changes: 13 additions & 17 deletions spec/lrama/lexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
grammar_file = Lrama::Lexer::GrammarFile.new(path, text)
lexer = Lrama::Lexer.new(grammar_file)

expect(lexer.next_token).to eq(['%require', '%require'])
expect(lexer.next_token).to eq([:STRING, '"3.0"'])
expect(lexer.next_token).to eq(['%{', '%{'])

lexer.status = :c_declaration
lexer.end_symbol = '%}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: "\n// Prologue\n")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 7, first_column: 2, last_line: 9, last_column: 0)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 5, first_column: 2, last_line: 7, last_column: 0)
lexer.status = :initial

expect(lexer.next_token).to eq(['%}', '%}'])
Expand All @@ -37,7 +35,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: "\n print_int();\n")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 15, first_column: 10, last_line: 17, last_column: 0)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 13, first_column: 10, last_line: 15, last_column: 0)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand All @@ -49,7 +47,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: "\n print_token();\n")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 18, first_column: 10, last_line: 20, last_column: 0)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 16, first_column: 10, last_line: 18, last_column: 0)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand All @@ -62,7 +60,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: 'struct lex_params *p')])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 22, first_column: 12, last_line: 22, last_column: 32)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 20, first_column: 12, last_line: 20, last_column: 32)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand All @@ -73,7 +71,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: 'struct parse_params *p')])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 23, first_column: 14, last_line: 23, last_column: 36)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 21, first_column: 14, last_line: 21, last_column: 36)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand All @@ -84,7 +82,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: "\n initial_action_func(@$);\n")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 26, first_column: 1, last_line: 28, last_column: 0)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 24, first_column: 1, last_line: 26, last_column: 0)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand All @@ -96,7 +94,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: "\n int i;\n long l;\n char *str;\n")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 30, first_column: 8, last_line: 34, last_column: 0)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 28, first_column: 8, last_line: 32, last_column: 0)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand Down Expand Up @@ -175,7 +173,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: " code 1 ")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 63, first_column: 11, last_line: 63, last_column: 19)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 61, first_column: 11, last_line: 61, last_column: 19)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand All @@ -187,7 +185,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: " code 2 ")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 64, first_column: 23, last_line: 64, last_column: 31)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 62, first_column: 23, last_line: 62, last_column: 31)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand All @@ -200,7 +198,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: " code 3 ")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 64, first_column: 58, last_line: 64, last_column: 66)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 62, first_column: 58, last_line: 62, last_column: 66)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand All @@ -214,7 +212,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: " code 4 ")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 65, first_column: 23, last_line: 65, last_column: 31)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 63, first_column: 23, last_line: 63, last_column: 31)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand All @@ -227,7 +225,7 @@
lexer.end_symbol = '}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: " code 5 ")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 65, first_column: 58, last_line: 65, last_column: 66)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 63, first_column: 58, last_line: 63, last_column: 66)
lexer.status = :initial

expect(lexer.next_token).to eq(['}', '}'])
Expand Down Expand Up @@ -273,15 +271,13 @@
grammar_file = Lrama::Lexer::GrammarFile.new(path, text)
lexer = Lrama::Lexer.new(grammar_file)

expect(lexer.next_token).to eq(['%require', '%require'])
expect(lexer.next_token).to eq([:STRING, '"3.0"'])
expect(lexer.next_token).to eq(['%{', '%{'])

lexer.status = :c_declaration
lexer.end_symbol = '%}'
token = lexer.next_token
expect(token).to eq([:C_DECLARATION, token_class::UserCode.new(s_value: "\n// Prologue\n")])
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 7, first_column: 2, last_line: 9, last_column: 0)
expect(token[1].location).to eq Lrama::Lexer::Location.new(grammar_file: grammar_file, first_line: 5, first_column: 2, last_line: 7, last_column: 0)
lexer.status = :initial

expect(lexer.next_token).to eq(['%}', '%}'])
Expand Down
Loading