Skip to content
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

feat: support Tact 1.6.0 #45

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ To find highlighting and other queries for specific editors, look in the `editor
## Useful ⚡ Tact links

- [Official Website](https://tact-lang.org/)
- [Documentation](https://docs.tact-lang.org/)
- Discussion Group in [Telegram](https://t.me/tactlang)
- [X/Twitter](https://twitter.com/tact_language)

Expand Down
20 changes: 14 additions & 6 deletions editor_queries/helix/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

(identifier) @variable

(destruct_bind
name: (identifier) @comment.line
bind: (identifier) @variable)

; variable.builtin
; ----------------

Expand Down Expand Up @@ -62,11 +66,14 @@
"%" "%="
"=" "=="
"!" "!=" "!!"
"<" "<=" "<<"
">" ">=" ">>"
"&" "|" "^"
"&&" "||"
"->"
"<" "<=" "<<" "<<="
">" ">=" ">>" ">>="
"&" "&="
"|" "|="
"^" "^="
"&&" "&&="
"||" "||="
"->" ".."
] @operator

; constructor
Expand Down Expand Up @@ -119,7 +126,7 @@
; -------------------

(import
library: (string) @string.special.path)
name: (string) @string.special.path)

; constant
; --------
Expand All @@ -145,6 +152,7 @@

((identifier) @constant.builtin
(#any-of? @constant.builtin
"SendDefaultMode"
"SendBounceIfActionFail"
"SendPayGasSeparately"
"SendIgnoreErrors"
Expand Down
1 change: 1 addition & 0 deletions editor_queries/helix/indents.scm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

; {..., ...}
(instance_argument_list)
(destruct_bind_list)

; {...; ...}
(message_body)
Expand Down
3 changes: 3 additions & 0 deletions editor_queries/helix/textobjects.scm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
(instance_argument_list
((_) @parameter.inside @parameter.movement . ","? @parameter.around) @parameter.around)

(destruct_bind_list
((_) @parameter.inside @parameter.movement . ","? @parameter.around) @parameter.around)

; single parameter

(receive_function
Expand Down
1 change: 1 addition & 0 deletions editor_queries/neovim/folds.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(argument_list)
; {…, …}
(instance_argument_list)
(destruct_bind_list)
; {…; …}
(message_body)
(struct_body)
Expand Down
22 changes: 17 additions & 5 deletions editor_queries/neovim/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
; --------
(identifier) @variable

(destruct_bind
name: (identifier) @comment
bind: (identifier) @variable)

; variable.builtin
; ----------------
(self) @variable.builtin
Expand Down Expand Up @@ -53,15 +57,23 @@
"<"
"<="
"<<"
"<<="
">"
">="
">>"
">>="
"&"
"&="
"|"
"|="
"^"
"^="
"&&"
"&&="
"||"
"||="
"->"
".."
] @operator

; constructor
Expand Down Expand Up @@ -109,7 +121,7 @@
; string.special.path
; -------------------
(import
library: (string) @string.special.path)
name: (string) @string.special.path)

; boolean
; -------
Expand All @@ -129,10 +141,10 @@

((identifier) @constant.builtin
(#any-of? @constant.builtin
"SendBounceIfActionFail" "SendPayGasSeparately" "SendIgnoreErrors" "SendDestroyIfZero"
"SendRemainingValue" "SendRemainingBalance" "SendOnlyEstimateFee" "ReserveExact"
"ReserveAllExcept" "ReserveAtMost" "ReserveAddOriginalBalance" "ReserveInvertSign"
"ReserveBounceIfActionFail"))
"SendDefaultMode" "SendBounceIfActionFail" "SendPayGasSeparately" "SendIgnoreErrors"
"SendDestroyIfZero" "SendRemainingValue" "SendRemainingBalance" "SendOnlyEstimateFee"
"ReserveExact" "ReserveAllExcept" "ReserveAtMost" "ReserveAddOriginalBalance"
"ReserveInvertSign" "ReserveBounceIfActionFail"))

; property
; --------
Expand Down
1 change: 1 addition & 0 deletions editor_queries/neovim/indents.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(argument_list)
; {..., ...}
(instance_argument_list)
(destruct_bind_list)
; {...; ...}
(message_body)
(struct_body)
Expand Down
2 changes: 1 addition & 1 deletion editor_queries/neovim/locals.scm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

; imports
(import
(string) @local.definition.import)
name: (string) @local.definition.import)

; References @local.reference
; -----------------------------
Expand Down
15 changes: 15 additions & 0 deletions editor_queries/neovim/textobjects.scm
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,21 @@
","? @_end
(#make-range! "parameter.outer" @parameter.inner @_end))

; second and following
(destruct_bind_list
"," @_start
.
(_) @parameter.inner
(#make-range! "parameter.outer" @_start @parameter.inner))

; first
(destruct_bind_list
.
(_) @parameter.inner
.
","? @_end
(#make-range! "parameter.outer" @parameter.inner @_end))

; single parameter
(receive_function
parameter: (_) @parameter.inner @parameter.outer)
Expand Down
77 changes: 66 additions & 11 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ function commaSepWithTrailing(rule) {
return optional(seq(rule, repeat(seq(",", rule)), optional(",")));
}

/**
* Creates a rule to match one or more of the rules separated by a comma with an optional trailing comma or a trailing comma and a .. ("the rest", remaining fields)
*
* @param {Rule} rule
*
* @return {ChoiceRule}
*
*/
function commaSepWithTrailingRest(rule) {
return optional(
seq(rule, repeat(seq(",", rule)), optional(seq(",", optional("..")))),
);
}

/**
* Creates a rule to match one or more of the rules separated by a comma
*
Expand Down Expand Up @@ -120,7 +134,7 @@ module.exports = grammar({

/* Imports */

import: ($) => seq("import", field("library", $.string), ";"),
import: ($) => seq("import", field("name", $.string), ";"),

/* Module items */

Expand Down Expand Up @@ -188,7 +202,7 @@ module.exports = grammar({
"fun",
field("name", $.identifier),
field("parameters", $.parameter_list),
field("result", optional(seq(":", $._type))),
optional(seq(":", field("result", $._type))),
field("body", $.asm_function_body),
),

Expand Down Expand Up @@ -254,7 +268,7 @@ module.exports = grammar({
"fun",
field("name", $.identifier),
field("parameters", $.parameter_list),
field("result", optional(seq(":", $._type))),
optional(seq(":", field("result", $._type))),
choice(";", field("body", alias($.block_statement, $.function_body))),
),

Expand All @@ -264,7 +278,7 @@ module.exports = grammar({
"fun",
field("name", $.identifier),
field("parameters", $.parameter_list),
field("result", optional(seq(":", $._type))),
optional(seq(":", field("result", $._type))),
),

_function_definition: ($) =>
Expand All @@ -277,10 +291,10 @@ module.exports = grammar({
field("body", alias($.block_statement, $.function_body)),
),

function_attributes: (_) =>
function_attributes: ($) =>
repeat1(
choice(
"get",
$.get_attribute,
"mutates",
"extends",
"virtual",
Expand All @@ -290,6 +304,9 @@ module.exports = grammar({
),
),

get_attribute: ($) =>
seq("get", optional(seq("(", field("value", $._expression), ")"))),

parameter_list: ($) => seq("(", commaSepWithTrailing($.parameter), ")"),

parameter: ($) =>
Expand All @@ -312,7 +329,7 @@ module.exports = grammar({
field("body", alias($.struct_body, $.message_body)),
),

message_value: ($) => seq("(", $.integer, ")"),
message_value: ($) => seq("(", $._expression, ")"),

struct_body: ($) => seq("{", semicolonSepWithTrailing($.field), "}"),

Expand Down Expand Up @@ -465,6 +482,7 @@ module.exports = grammar({
$.assignment_statement, // StatementAssign
$.augmented_assignment_statement, // StatementAugmentedAssign
$.do_until_statement, // StatementUntil
$.destruct_statement, // StatementDestruct
),

let_statement: ($) =>
Expand All @@ -476,6 +494,24 @@ module.exports = grammar({
field("value", $._expression),
),

destruct_statement: ($) =>
seq(
"let",
field("name", alias($._type_identifier, $.type_identifier)),
field("binds", $.destruct_bind_list),
"=",
field("value", $._expression),
),

destruct_bind_list: ($) =>
seq("{", commaSepWithTrailingRest($.destruct_bind), "}"),

destruct_bind: ($) =>
seq(
field("name", $.identifier),
optional(seq(":", field("bind", $.identifier))),
),

block_statement: ($) =>
prec.right(
seq(
Expand Down Expand Up @@ -507,7 +543,20 @@ module.exports = grammar({
field("left", $._path_expression),
field(
"operator",
choice("+=", "-=", "*=", "/=", "%=", "&=", "|=", "^="),
choice(
"+=",
"-=",
"*=",
"/=",
"%=",
"&=",
"|=",
"^=",
"||=",
"&&=",
">>=",
"<<=",
),
),
field("right", $._expression),
),
Expand Down Expand Up @@ -777,7 +826,13 @@ module.exports = grammar({

/* Types */

_type: ($) => choice($.map_type, $.bounced_type, $._simple_type),
_type: ($) =>
choice(
$.map_type,
$.bounced_type,
$.optional_type,
alias($._type_identifier, $.type_identifier),
),

map_type: ($) =>
seq(
Expand All @@ -799,8 +854,8 @@ module.exports = grammar({
">",
),

_simple_type: ($) =>
seq(alias($._type_identifier, $.type_identifier), optional("?")),
optional_type: ($) =>
seq(alias($._type_identifier, $.type_identifier), "?"),

_type_identifier: (_) => /[A-Z][a-zA-Z0-9_]*/,

Expand Down
Loading
Loading