-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow identifiers with trailing ? or ! in more places #88
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,6 +285,18 @@ module.exports = grammar({ | |
$.pseudo_call_argument_list, | ||
$._parenthesized_type, | ||
], | ||
|
||
// Ternary has precedence over type declaration | ||
[ | ||
$.call, | ||
$.type_declaration, | ||
], | ||
|
||
// Want to prefer identifiers ending with `?` | ||
[ | ||
$.identifier_method_call, | ||
$.identifier, | ||
], | ||
], | ||
|
||
conflicts: $ => [ | ||
|
@@ -981,6 +993,7 @@ module.exports = grammar({ | |
method_proc: $ => { | ||
const receiver = field('receiver', choice( | ||
$.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
$.instance_var, | ||
$.class_var, | ||
$.self, | ||
|
@@ -1180,7 +1193,10 @@ module.exports = grammar({ | |
}, | ||
|
||
fun_param: $ => { | ||
const name = field('name', choice($.identifier, $.constant)) | ||
const name = field('name', choice( | ||
$.identifier, $.constant, | ||
alias($.identifier_method_call, $.identifier), | ||
)) | ||
const type = field('type', seq(/[ \t]:\s/, $._bare_type)) | ||
|
||
return seq( | ||
|
@@ -1227,7 +1243,19 @@ module.exports = grammar({ | |
), | ||
|
||
c_struct_fields: $ => { | ||
const names = seq($.identifier, repeat(seq(',', $.identifier))) | ||
const names = seq( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outside of params, this and type declaration I don't expect to change. What are your thoughts on just adding these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think I understand, which ones specifically? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type declaration names and c struct / union fields |
||
choice( | ||
$.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
), | ||
repeat(seq( | ||
',', | ||
choice( | ||
$.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
), | ||
)), | ||
) | ||
|
||
return seq( | ||
names, | ||
|
@@ -1266,7 +1294,19 @@ module.exports = grammar({ | |
), | ||
|
||
union_fields: $ => { | ||
const names = seq($.identifier, repeat(seq(',', $.identifier))) | ||
const names = seq( | ||
choice( | ||
$.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
), | ||
repeat(seq( | ||
',', | ||
choice( | ||
$.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
), | ||
)), | ||
) | ||
|
||
return seq( | ||
names, | ||
|
@@ -1425,7 +1465,9 @@ module.exports = grammar({ | |
param: $ => { | ||
const extern_name = field('extern_name', $.identifier) | ||
const name = field('name', choice( | ||
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression, | ||
$.identifier, alias($.identifier_method_call, $.identifier), | ||
$.instance_var, $.class_var, | ||
$.macro_var, $.macro_expression, | ||
nobodywasishere marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)) | ||
const type = field('type', seq(/[ \t]:\s/, $._bare_type)) | ||
const default_value = field('default', seq('=', $._expression)) | ||
|
@@ -1441,7 +1483,9 @@ module.exports = grammar({ | |
|
||
splat_param: $ => { | ||
const name = field('name', choice( | ||
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression, | ||
$.identifier, alias($.identifier_method_call, $.identifier), | ||
$.instance_var, $.class_var, | ||
$.macro_var, $.macro_expression, | ||
)) | ||
const type = field('type', seq(/[ \t]:\s/, $._bare_type)) | ||
|
||
|
@@ -1455,7 +1499,9 @@ module.exports = grammar({ | |
|
||
double_splat_param: $ => { | ||
const name = field('name', choice( | ||
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression, | ||
$.identifier, alias($.identifier_method_call, $.identifier), | ||
$.instance_var, $.class_var, | ||
$.macro_var, $.macro_expression, | ||
)) | ||
const type = field('type', seq(/[ \t]:\s/, $._bare_type)) | ||
|
||
|
@@ -1469,7 +1515,9 @@ module.exports = grammar({ | |
|
||
block_param: $ => { | ||
const name = field('name', choice( | ||
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression, | ||
$.identifier, alias($.identifier_method_call, $.identifier), | ||
$.instance_var, $.class_var, | ||
$.macro_var, $.macro_expression, | ||
)) | ||
const type = field('type', seq(/:\s/, $._bare_type)) | ||
|
||
|
@@ -1930,7 +1978,10 @@ module.exports = grammar({ | |
)), | ||
|
||
macro_for: $ => { | ||
const var_name = field('var', choice($.underscore, $.identifier)) | ||
const var_name = field('var', choice( | ||
$.underscore, $.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
)) | ||
|
||
return seq( | ||
'for', | ||
|
@@ -2478,6 +2529,7 @@ module.exports = grammar({ | |
'out', | ||
choice( | ||
$.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
$.instance_var, | ||
$.underscore, | ||
$.macro_var, | ||
|
@@ -2489,6 +2541,7 @@ module.exports = grammar({ | |
const lhs = field('lhs', choice( | ||
$.underscore, | ||
$.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
$.instance_var, | ||
$.class_var, | ||
$.macro_var, | ||
|
@@ -2552,6 +2605,7 @@ module.exports = grammar({ | |
|
||
const lhs = field('lhs', choice( | ||
$.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
$.instance_var, | ||
$.class_var, | ||
$.macro_var, | ||
|
@@ -2570,6 +2624,7 @@ module.exports = grammar({ | |
lhs_splat: $ => seq('*', choice( | ||
$.underscore, | ||
$.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
$.instance_var, | ||
$.class_var, | ||
$.macro_var, | ||
|
@@ -2583,6 +2638,7 @@ module.exports = grammar({ | |
const lhs_basic = choice( | ||
$.underscore, | ||
$.identifier, | ||
alias($.identifier_method_call, $.identifier), | ||
$.instance_var, | ||
$.class_var, | ||
$.macro_var, | ||
|
@@ -2608,7 +2664,11 @@ module.exports = grammar({ | |
|
||
uninitialized_assign: $ => { | ||
return seq( | ||
field('lhs', choice($.identifier, $.instance_var, $.class_var, $.global_var, $.macro_var)), | ||
field('lhs', choice( | ||
$.identifier, alias($.identifier_method_call, $.identifier), | ||
$.instance_var, $.class_var, | ||
$.global_var, $.macro_var, | ||
)), | ||
'=', | ||
field('rhs', $.uninitialized_var), | ||
) | ||
|
@@ -2618,7 +2678,9 @@ module.exports = grammar({ | |
|
||
type_declaration: $ => { | ||
const variable = field('var', choice( | ||
$.identifier, $.instance_var, $.class_var, $.macro_var, $.macro_expression, | ||
$.identifier, alias($.identifier_method_call, $.identifier), | ||
$.instance_var, $.class_var, | ||
$.macro_var, $.macro_expression, | ||
)) | ||
const type = field('type', $._bare_type) | ||
const value = field('value', $._expression) | ||
|
@@ -2643,11 +2705,15 @@ module.exports = grammar({ | |
field('type', $._bare_type), | ||
), | ||
|
||
block_body_param: $ => field('name', $.identifier), | ||
block_body_param: $ => field('name', choice( | ||
$.identifier, alias($.identifier_method_call, $.identifier), | ||
)), | ||
|
||
block_body_splat_param: $ => seq( | ||
'*', | ||
field('name', $.identifier), | ||
field('name', choice( | ||
$.identifier, alias($.identifier_method_call, $.identifier), | ||
)), | ||
), | ||
|
||
_block_body_nested_param: $ => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary?