Skip to content

Commit

Permalink
Do not use semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Jan 31, 2024
1 parent ebd1bfc commit 5111ae2
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions spec/lrama/lexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
expect(lexer.next_token).to eq([:STRING, '"3.0"'])
expect(lexer.next_token).to eq(['%{', '%{'])

lexer.status = :c_declaration; lexer.end_symbol = '%}'
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)
Expand All @@ -30,7 +31,8 @@
expect(lexer.next_token).to eq(['%printer', '%printer'])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand All @@ -41,7 +43,8 @@
expect(lexer.next_token).to eq(['%printer', '%printer'])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand All @@ -53,7 +56,8 @@
expect(lexer.next_token).to eq(['%lex-param', '%lex-param'])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand All @@ -63,7 +67,8 @@
expect(lexer.next_token).to eq(['%parse-param', '%parse-param'])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand All @@ -73,7 +78,8 @@
expect(lexer.next_token).to eq(['%initial-action', '%initial-action'])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand All @@ -84,7 +90,8 @@
expect(lexer.next_token).to eq(['%union', '%union'])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand Down Expand Up @@ -162,7 +169,8 @@
expect(lexer.next_token).to eq([:IDENTIFIER, token_class::Ident.new(s_value: 'tPLUS')])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand All @@ -173,7 +181,8 @@
expect(lexer.next_token).to eq([:IDENTIFIER, token_class::Ident.new(s_value: 'keyword_class')])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand All @@ -185,7 +194,8 @@
expect(lexer.next_token).to eq([:IDENTIFIER, token_class::Ident.new(s_value: 'keyword_end')])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand All @@ -198,7 +208,8 @@
expect(lexer.next_token).to eq([:IDENTIFIER, token_class::Ident.new(s_value: 'keyword_class')])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand All @@ -210,7 +221,8 @@
expect(lexer.next_token).to eq([:IDENTIFIER, token_class::Ident.new(s_value: 'keyword_end')])
expect(lexer.next_token).to eq(['{', '{'])

lexer.status = :c_declaration; lexer.end_symbol = '}'
lexer.status = :c_declaration
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)
Expand Down Expand Up @@ -259,7 +271,8 @@
expect(lexer.next_token).to eq([:STRING, '"3.0"'])
expect(lexer.next_token).to eq(['%{', '%{'])

lexer.status = :c_declaration; lexer.end_symbol = '%}'
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)
Expand Down Expand Up @@ -323,7 +336,8 @@
it do
grammar_file = Lrama::Lexer::GrammarFile.new("invalid.y", "@invalid")
lexer = Lrama::Lexer.new(grammar_file)
lexer.status = :c_declaration; lexer.end_symbol = "%}"
lexer.status = :c_declaration
lexer.end_symbol = "%}"

expect { lexer.next_token }.to raise_error(ParseError, "Unexpected code: @invalid.")
end
Expand Down

0 comments on commit 5111ae2

Please sign in to comment.