Skip to content
Permalink
Browse files
Fix parsing of '!=' after an identifier (#4834)
fixes #4815
  • Loading branch information
oprypin authored and ysbaddaden committed Aug 16, 2017
1 parent 53c4431 commit e5b6efe5d6d4dbcef6629c39f29451f7dc4f4b1e
Showing with 16 additions and 2 deletions.
  1. +11 −0 spec/compiler/lexer/lexer_spec.cr
  2. +4 −0 spec/compiler/parser/parser_spec.cr
  3. +1 −2 src/compiler/crystal/syntax/lexer.cr
@@ -451,6 +451,17 @@ describe "Lexer" do
token.type.should eq(:"/=")
end

it "lexes != after identifier (#4815)" do
lexer = Lexer.new("some_method!=5")
token = lexer.next_token
token.type.should eq(:IDENT)
token.value.should eq("some_method")
token = lexer.next_token
token.type.should eq(:"!=")
token = lexer.next_token
token.type.should eq(:NUMBER)
end

assert_syntax_error "'\\uFEDZ'", "expected hexadecimal character in unicode escape"
assert_syntax_error "'\\u{}'", "expected hexadecimal character in unicode escape"
assert_syntax_error "'\\u{110000}'", "invalid unicode codepoint (too large)"
@@ -153,6 +153,10 @@ describe "Parser" do
it_parses "def foo(n); foo(n -1); end", Def.new("foo", ["n".arg], "foo".call(Call.new("n".var, "-", 1.int32)))
it_parses "def type(type); end", Def.new("type", ["type".arg])

# #4815
assert_syntax_error "def foo!=; end", "unexpected token: !="
assert_syntax_error "def foo?=(x); end", "unexpected token: ?"

it_parses "def self.foo\n1\nend", Def.new("foo", body: 1.int32, receiver: "self".var)
it_parses "def self.foo()\n1\nend", Def.new("foo", body: 1.int32, receiver: "self".var)
it_parses "def self.foo=\n1\nend", Def.new("foo=", body: 1.int32, receiver: "self".var)
@@ -1214,8 +1214,7 @@ module Crystal
while ident_part?(current_char)
next_char
end
case current_char
when '!', '?'
if (current_char == '?' || current_char == '!') && peek_next_char != '='
next_char
end
@token.type = :IDENT

0 comments on commit e5b6efe

Please sign in to comment.