Skip to content
Open
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 .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_size = 2

[*.{json,toml,yml,gyp}]
indent_style = space
Expand Down
28 changes: 16 additions & 12 deletions grammar-declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ module.exports = {
alias(choice('default', 'null', 'get', 'set', 'dynamic', 'never'), $.keyword),
access_identifiers: ($) =>
seq('(', $._access_identifier, optional(seq(',', $._access_identifier)), ')'),
type_param: ($) => choice($._lhs_expression, seq($._lhs_expression, $.type_params)),
type_params: ($) => prec.right(1, seq('<', commaSep1($.type_param), '>')),
// _type_param: ($) => $.type,
_type_param: ($) => $.type,
type_params: ($) => seq('<', commaSep1($._type_param), '>'),

class_declaration: ($) =>
seq(
Expand Down Expand Up @@ -90,19 +91,22 @@ module.exports = {
field('name', $._lhs_expression),
optional('?'),
optional(seq(':', alias(choice($._lhs_expression, $.type, $.structure_type), $.type))),
optional(seq($._assignmentOperator, $._literal)),
optional(seq($._assignment_operator, $._literal)),
),
),

variable_declaration: ($) =>
seq(
repeat($.metadata),
repeat($.keyword),
choice(alias('var', $.keyword), alias('final', $.keyword)),
field('name', $._lhs_expression),
optional($.access_identifiers),
optional(seq(':', optional(repeat('(')), field('type', $.type), optional(repeat(')')))),
optional(seq(($._assignmentOperator, $.operator), $.expression)),
$._semicolon,
prec.right(
seq(
prec.left(repeat($.metadata)),
prec.left(repeat($.keyword)),
choice(alias('var', $.keyword), alias('final', $.keyword)),
field('name', $.identifier),
optional($.access_identifiers),
optional(seq(':', field('type', $.type))),
// optional(seq(':', optional(repeat('(')), field('type', $.type), optional(repeat(')')))),
optional(seq(($._assignment_operator, $.operator), $.expression)),
$._semicolon,
),
),
};
2 changes: 1 addition & 1 deletion grammar-literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
prec.right(
choice(
seq(choice($.identifier, $.string), ':', $.expression),
seq(choice($.identifier, $._literal), '=>', $.expression),
seq(choice($.identifier, $._literal), $._map_operator, $.expression),
),
),

Expand Down
43 changes: 22 additions & 21 deletions grammar-operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@ module.exports = {
operator: ($) => choice($._binaryOperator, $._unaryOperator),

// From: https://haxe.org/manual/expression-operators-unops.html
_unaryOperator: ($) => prec.right(choice($._prefixUnaryOperator, $._postfixUnaryOperator)),
_prefixUnaryOperator: ($) => choice('~', '!', '-', '++', '--'),
_postfixUnaryOperator: ($) => choice('++', '--'),
_unaryOperator: ($) => prec.right(choice($._prefixUnaryOperator, $._eitherUnaryOperator)),
_prefixUnaryOperator: ($) => token(choice('~', '!', '-')),
_eitherUnaryOperator: ($) => token(choice('++', '--')),

// From: https://haxe.org/manual/expression-operators-binops.html
_binaryOperator: ($) =>
prec.left(
choice(
$._arithmeticOperator,
$._bitwiseOperator,
$._logicalOperator,
$._comparisonOperator,
$._miscOperator,
$._assignmentOperator,
$._compoundAssignmentOperator,
$._rangeOperator,
$._arithmetic_operator,
$._bitwise_operator,
$._logical_operator,
$._comparison_operator,
$._map_operator,
$._null_colalese_operator,
$._assignment_operator,
$._compound_assignment_operator,
$._range_operator,
),
),
_arithmeticOperator: ($) => choice('%', '*', '/', '+', '-'),
_bitwiseOperator: ($) => choice('<<', '>>', '>>>', '&', '|', '^'),
_logicalOperator: ($) => choice('&&', '||'),
_comparisonOperator: ($) => choice('==', '!=', '<', '<=', '>', '>='),
_miscOperator: ($) => choice('=>', '??'),
// _miscOperator: ($) => choice('...', '=>'),
_assignmentOperator: ($) => '=',
_compoundAssignmentOperator: ($) =>
seq(choice($._arithmeticOperator, $._bitwiseOperator), $._assignmentOperator),
_rangeOperator: ($) => '...',
_arithmetic_operator: ($) => token(choice('%', '*', '/', '+', '-')),
_bitwise_operator: ($) => token(choice('<<', '>>', '>>>', '&', '|', '^')),
_logical_operator: ($) => token(choice('&&', '||')),
_comparison_operator: ($) => token(choice('==', '!=', '<', '<=', '>', '>=')),
_map_operator: ($) => token(choice('=>')),
_null_colalese_operator: ($) => token(choice('??')),
_assignment_operator: ($) => token('='),
_compound_assignment_operator: ($) =>
seq(choice($._arithmetic_operator, $._bitwise_operator), $._assignment_operator),
_range_operator: ($) => token('...'),
};
80 changes: 48 additions & 32 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@ const haxe_grammar = {
word: ($) => $.identifier,
inline: ($) => [$.statement, $.expression],
extras: ($) => [$.comment, /[\s\uFEFF\u2060\u200B\u00A0]/],
supertypes: ($) => [$.declaration],
supertypes: ($) => [
$.declaration,
// $.expression,
// $.statement,
],
conflicts: ($) => [
[$.block, $.object],
[$.typedef_declaration, $.type],
[$.call_expression, $._constructor_call],
[$._rhs_expression, $.pair],
[$._literal, $.pair],
[$.pair, $.pair],
[$.function_declaration],
[$.function_type, $.variable_declaration],
[$.type, $.function_type, $.variable_declaration],
[$.type, $._function_type_args],
[$.structure_type_pair, $._function_type_args],
[$.function_declaration, $.variable_declaration],
[$._prefixUnaryOperator, $._arithmeticOperator],
[$._prefixUnaryOperator, $._postfixUnaryOperator],
],
rules: {
module: ($) => seq(repeat($.statement)),
Expand Down Expand Up @@ -79,17 +75,17 @@ const haxe_grammar = {

throw_statement: ($) => prec.right(seq(alias('throw', $.keyword), $.expression)),

_rhs_expression: ($) =>
prec.right(choice($._literal, $.identifier, $.member_expression, $.call_expression)),

_unaryExpression: ($) =>
prec.left(
1,
choice(
// unary on LHS
seq($.operator, $._rhs_expression),
seq(
alias(choice($._prefixUnaryOperator, $._eitherUnaryOperator), $.operator),
$._rhs_expression,
),
// unary on RHS
seq($._rhs_expression, $.operator),
seq($._rhs_expression, alias($._eitherUnaryOperator, $.operator)),
),
),

Expand Down Expand Up @@ -143,32 +139,18 @@ const haxe_grammar = {
seq(
$.identifier,
alias('in', $.keyword),
choice(seq($.integer, $._rangeOperator, $.integer), $.identifier),
choice(seq($.integer, $._range_operator, $.integer), $.identifier),
),
),

expression: ($) =>
choice(
$._unaryExpression,
$.subscript_expression,
$.runtime_type_check_expression,
$.cast_expression,
$.type_trace_expression,
$.range_expression,
$._parenthesized_expression,
$.switch_expression,
// simple expression, or chained.
seq($._rhs_expression, repeat(seq($.operator, $._rhs_expression))),
),

subscript_expression: ($) =>
prec.left(
1,
seq(
choice($.identifier, $._parenthesized_expression, $.member_expression),
'[',
token('['),
field('index', $.expression),
']',
token(']'),
),
// seq($._parenthesized_expression, '[', field('index', $.expression), ']'),
),
Expand All @@ -180,12 +162,46 @@ const haxe_grammar = {
field('object', choice(alias('this', $.keyword), $.identifier)),
field('literal', $._literal),
),
choice(token('.'), seq(alias('?', $.operator), '.')),
token(choice('?.', '.')),
repeat1(field('member', $._lhs_expression)),
),
),

_binary_expression: ($) =>
prec.left(10, seq($.expression, alias($._binaryOperator, $.operator), $.expression)),

ternary_expression: ($) =>
prec.right(
5,
seq(
field('condition', $.expression),
alias('?', $.operator),
field('true_result', $.expression),
alias(':', $.operator),
field('false_result', $.expression),
),
),

_lhs_expression: ($) => prec(1, choice($.identifier, $.member_expression)),
_rhs_expression: ($) =>
prec.right(choice($._literal, $.identifier, $.member_expression, $.call_expression)),

expression: ($) =>
choice(
$._rhs_expression,
$._unaryExpression,
$.subscript_expression,
$.runtime_type_check_expression,
$.cast_expression,
$.type_trace_expression,
$.range_expression,
$._parenthesized_expression,
$.switch_expression,
$._binary_expression,
$.ternary_expression,
// simple expression, or chained.
// seq($._rhs_expression, repeat(seq($.operator, $._rhs_expression))),
),

builtin_type: ($) => prec.right(choice(...builtins)),

Expand Down
1 change: 0 additions & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
; ------

(":") @punctuation.special
(pair [":" "=>"] @punctuation.special)

[
"("
Expand Down
Loading