Skip to content

Commit

Permalink
feat: use the new reserved rules api
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Nov 24, 2024
1 parent 12fe553 commit e3075c9
Show file tree
Hide file tree
Showing 8 changed files with 4,755 additions and 595 deletions.
8 changes: 8 additions & 0 deletions a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
func a() {
x. // Should error here

switch v {
case 1:
doSomething()
}
}
11 changes: 11 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ module.exports = grammar({
[$.type_parameter_declaration, $._simple_type, $.generic_type, $._expression],
],

reserved: {
global: $ => [
// https://go.dev/ref/spec#Keywords
'break', 'default', 'func', 'interface', 'select',
'case', 'defer', 'go', 'map', 'struct',
'chan', 'else', 'goto', 'package', 'switch',
'const', 'fallthrough', 'if', 'range', 'type',
'continue', 'for', 'import', 'return', 'var',
],
},

supertypes: $ => [
$._expression,
$._type,
Expand Down
3,827 changes: 3,827 additions & 0 deletions log.html

Large diffs are not rendered by default.

106 changes: 105 additions & 1 deletion src/grammar.json

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

1,327 changes: 735 additions & 592 deletions src/parser.c

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/tree_sitter/array.h

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

11 changes: 10 additions & 1 deletion src/tree_sitter/parser.h

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

57 changes: 57 additions & 0 deletions test/corpus/errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
=================================================
Error detected at globally reserved keyword
=================================================

func a() {
a. // Should error here, and not use 'if' as a field

if b > c {
d()
}
}


func b() {
b. // Should error here, and not use 'switch' as a field

switch v {
case 1:
doSomething()
}
}

---

(source_file
(function_declaration
(identifier)
(parameter_list)
(block
(ERROR
(identifier))
(comment)
(if_statement
(binary_expression
(identifier)
(identifier))
(block
(expression_statement
(call_expression
(identifier)
(argument_list)))))))
(function_declaration
(identifier)
(parameter_list)
(block
(ERROR
(identifier))
(comment)
(expression_switch_statement
(identifier)
(expression_case
(expression_list
(int_literal))
(expression_statement
(call_expression
(identifier)
(argument_list))))))))

0 comments on commit e3075c9

Please sign in to comment.