Skip to content

Commit

Permalink
Support :!~ symbols, add symbol test cases (#153)
Browse files Browse the repository at this point in the history
* Support :!~ symbols, add symbol test cases

This commit updates the lexer to specifically match the symbol :!~.

I also add test cases from
https://github.com/ruby/spec/blob/master/language/symbol_spec.rb:

- :_
- :!~
- :''

Fixes #143.

* fixup! Support :!~ symbols, add symbol test cases
  • Loading branch information
nbrahms committed Jan 22, 2021
1 parent 6ee7d38 commit 8fd340f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,23 @@ struct Scanner {
}
return false;

// &, ^, |, ~, /, %, !,`
// &, ^, |, ~, /, %`
case '&':
case '^':
case '|':
case '~':
case '/':
case '%':
case '!':
case '`':
advance(lexer);
return true;

// !, !=, !~
case '!':
advance(lexer);
if (lexer->lookahead == '=' || lexer->lookahead == '~') advance(lexer);
return true;

// *, **
case '*':
advance(lexer);
Expand All @@ -316,6 +321,7 @@ struct Scanner {
}

bool scan_symbol_identifier(TSLexer *lexer) {

if (lexer->lookahead == '@') {
advance(lexer);
if (lexer->lookahead == '@') {
Expand Down
8 changes: 8 additions & 0 deletions test/corpus/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ symbol
:$0
:_bar
:åäö
:_

---

Expand All @@ -27,6 +28,7 @@ symbol
(simple_symbol)
(simple_symbol)
(simple_symbol)
(simple_symbol)
(simple_symbol))

======
Expand Down Expand Up @@ -59,6 +61,8 @@ symbol operators
:<=
:<<
:<=>
:!=
:!~

---

Expand Down Expand Up @@ -88,18 +92,22 @@ symbol operators
(simple_symbol)
(simple_symbol)
(simple_symbol)
(simple_symbol)
(simple_symbol)
(simple_symbol))

====================
single quoted symbol
====================

:''
:'foo bar'
:'#{'

---

(program
(delimited_symbol)
(delimited_symbol (string_content))
(delimited_symbol (string_content)))

Expand Down

0 comments on commit 8fd340f

Please sign in to comment.