Skip to content

Commit

Permalink
Merge pull request #85 from crystal-lang-tools/keidax/nilable-constants
Browse files Browse the repository at this point in the history
Support nilable constants
  • Loading branch information
nobodywasishere authored Jan 5, 2025
2 parents f8fa4b4 + 9e628c0 commit 34b909b
Show file tree
Hide file tree
Showing 9 changed files with 926,099 additions and 918,997 deletions.
14 changes: 14 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ module.exports = grammar({
$.self,
$.constant,
$.generic_instance_type,
$.nilable_constant,
$.pseudo_constant,
$.special_variable,
alias($.global_match_data_index, $.special_variable),
Expand Down Expand Up @@ -1569,6 +1570,19 @@ module.exports = grammar({
))
},

nilable_constant: $ => {
const base = choice(
$.constant,
$.nilable_constant,
$.generic_instance_type,
)

return seq(
base,
token.immediate('?'),
)
},

pseudo_constant: $ => choice(
'__LINE__',
'__END_LINE__',
Expand Down
12 changes: 12 additions & 0 deletions queries/nvim/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"unless"
] @keyword.conditional

(conditional
[
"?"
":"
] @keyword.conditional.ternary)

[
"for"
"until"
Expand Down Expand Up @@ -133,6 +139,12 @@
(generic_type)
] @type

(nilable_constant
"?" @type.builtin)

(nilable_type
"?" @type.builtin)

(annotation
(constant) @attribute)

Expand Down
33 changes: 33 additions & 0 deletions src/grammar.json

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

Loading

0 comments on commit 34b909b

Please sign in to comment.