Skip to content

Commit

Permalink
feat[match ohm]: !! as a value expression, trait lists with trailin…
Browse files Browse the repository at this point in the history
…g commas (#22)

* feat: Promote non-null assert/unbox (`!!`) into a value expression

* fix: Correctly highlight built-in global static functions

* feat: Trailing commas for trait lists + more tests for trailing commas

* fix: Disable Python, Go and Swift binding test (Restored to the defaults)

* fix: Disable flaky binding tests on Windows (until they're fixed upstream)
  • Loading branch information
novusnota committed Apr 15, 2024
1 parent f17a4b1 commit 3e24e16
Show file tree
Hide file tree
Showing 16 changed files with 3,250 additions and 3,234 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
with:
generate: true
test-parser: true
test-rust: true
test-node: true
test-python: true
test-go: true
test-swift: true
test-rust: ${{runner.os != 'Windows'}}
test-node: ${{runner.os != 'Windows'}}
test-python: false # default
test-go: false # default
test-swift: false # default
3 changes: 2 additions & 1 deletion editor_queries/helix/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@
; function.builtin
; ----------------

((identifier) @function.builtin
(static_call_expression
name: (identifier) @function.builtin
(#any-of? @function.builtin
"send" "sender" "require" "now"
"myBalance" "myAddress" "newAddress"
Expand Down
3 changes: 2 additions & 1 deletion editor_queries/neovim/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@
; function.builtin
; ----------------

((identifier) @function.builtin
(static_call_expression
name: (identifier) @function.builtin
(#match? @function.builtin
"^(log|log2|send|sender|require|now|myBalance|myAddress|newAddress|contractAddress|contractAddressExt|emit|cell|ton|dump|beginString|beginComment|beginTailString|beginStringFromBuilder|beginCell|emptyCell|randomInt|random|checkSignature|checkDataSignature|sha256|min|max|abs|pow|throw|nativeThrowWhen|nativeThrowUnless|getConfigParam|nativeRandomize|nativeRandomizeLt|nativePrepareRandom|nativeRandom|nativeRandomInterval|nativeReserve)$"))

Expand Down
24 changes: 16 additions & 8 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ module.exports = grammar({
/* Each inner array represents a descending ordering of precedence */
precedences: (_) => [
[
"non_null_assert_expr",
"method_call_expr",
"field_access_expr",
"static_call_expr",
"parenthesized_expr",
"instance_expr",

"unary_suffix_expr",
// "unary_suffix_expr",
"unary_expr",

"binary_multiplication",
Expand Down Expand Up @@ -262,7 +263,7 @@ module.exports = grammar({

contract_attributes: ($) => repeat1(seq("@interface", "(", $.string, ")")),

trait_list: ($) => seq("with", commaSep1($.identifier)),
trait_list: ($) => seq("with", commaSepWithTrailing($.identifier)),

contract_body: ($) =>
seq(
Expand Down Expand Up @@ -436,7 +437,7 @@ module.exports = grammar({
$.ternary_expression, // ExpressionConditional
$.binary_expression, // ExpressionBinary
$.unary_expression, // ExpressionUnary
$.unary_suffix_expression, // ExpressionUnarySuffix
// $.unary_suffix_expression, // ExpressionUnarySuffix
$.value_expression, // ExpressionValue
),

Expand Down Expand Up @@ -523,14 +524,15 @@ module.exports = grammar({
),
),

unary_suffix_expression: ($) =>
prec.left(
"unary_suffix_expr",
seq(field("argument", $._expression), field("operator", choice("!!"))),
),
// unary_suffix_expression: ($) =>
// prec.left(
// "unary_suffix_expr",
// seq(field("argument", $._expression), field("operator", choice("!!"))),
// ),

value_expression: ($) =>
choice(
$.non_null_assert_expression, // ExpressionUnboxNonNull
$.method_call_expression, // ExpressionCall
$.field_access_expression, // ExpressionField
$.static_call_expression, // ExpressionStaticCall
Expand All @@ -545,6 +547,12 @@ module.exports = grammar({
$.self, // self
),

non_null_assert_expression: ($) =>
prec.left(
"non_null_assert_expr",
seq(field("argument", $._expression), field("operator", choice("!!"))),
),

method_call_expression: ($) =>
prec.right(
"method_call_expr",
Expand Down
3 changes: 2 additions & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@
; function.builtin
; ----------------

((identifier) @function.builtin
(static_call_expression
name: (identifier) @function.builtin
(#match? @function.builtin
"^(log|log2|send|sender|require|now|myBalance|myAddress|newAddress|contractAddress|contractAddressExt|emit|cell|ton|dump|beginString|beginComment|beginTailString|beginStringFromBuilder|beginCell|emptyCell|randomInt|random|checkSignature|checkDataSignature|sha256|min|max|abs|pow|throw|nativeThrowWhen|nativeThrowUnless|getConfigParam|nativeRandomize|nativeRandomizeLt|nativePrepareRandom|nativeRandom|nativeRandomInterval|nativeReserve)$")
(#is-not? local))
Expand Down
130 changes: 75 additions & 55 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 3e24e16

Please sign in to comment.