Skip to content

Commit

Permalink
Fix parsing of '!=' after an identifier (#4834)
Browse files Browse the repository at this point in the history
fixes #4815
  • Loading branch information
oprypin authored and ysbaddaden committed Aug 16, 2017
1 parent 53c4431 commit e5b6efe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions spec/compiler/lexer/lexer_spec.cr
Expand Up @@ -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)"
Expand Down
4 changes: 4 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/crystal/syntax/lexer.cr
Expand Up @@ -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
Expand Down

0 comments on commit e5b6efe

Please sign in to comment.