Skip to content

Commit

Permalink
Refactor addDot
Browse files Browse the repository at this point in the history
- Rename `addDots` to `addDot`.
- Move `token` call to `addDot` definition.
  • Loading branch information
savq committed Oct 29, 2024
1 parent 89f24fc commit ac751d1
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ module.exports = grammar({
$.operator,
$.integer_literal,
$.float_literal,
prec(-1, alias(':', $.operator)),
prec(-1, alias('begin', $.identifier)),
),

Expand Down Expand Up @@ -1095,6 +1094,7 @@ module.exports = grammar({
$._pipe_left_operator,
$._pipe_right_operator,
$._ellipsis_operator,
':',
$._plus_operator,
$._times_operator,
$._rational_operator,
Expand All @@ -1106,45 +1106,45 @@ module.exports = grammar({
$._unary_plus_operator,
),

_assignment_operator: _ => token(choice(':=', '$=', '.=', addDots(OPERATORS.assignment))),
_assignment_operator: _ => choice(':=', '$=', '.=', addDot(OPERATORS.assignment)),

_pair_operator: _ => token(addDots('=>')),
_pair_operator: _ => addDot('=>'),

_arrow_operator: _ => token(addDots(OPERATORS.arrow)),
_arrow_operator: _ => addDot(OPERATORS.arrow),

_lazy_or_operator: _ => token(addDots('||')),
_lazy_or_operator: _ => addDot('||'),

_lazy_and_operator: _ => token(addDots('&&')),
_lazy_and_operator: _ => addDot('&&'),

_comparison_operator: _ => token(addDots(OPERATORS.comparison)),
_comparison_operator: _ => addDot(OPERATORS.comparison),

_pipe_right_operator: _ => token(addDots('|>')),
_pipe_right_operator: _ => addDot('|>'),

_pipe_left_operator: _ => token(addDots('<|')),
_pipe_left_operator: _ => addDot('<|'),

_ellipsis_operator: _ => token(choice('..', addDots(OPERATORS.ellipsis))),
_ellipsis_operator: _ => token(choice('..', addDot(OPERATORS.ellipsis))),

_plus_operator: _ => token(addDots(OPERATORS.plus)),
_plus_operator: _ => addDot(OPERATORS.plus),

_times_operator: _ => token(addDots(OPERATORS.times)),
_times_operator: _ => addDot(OPERATORS.times),

_rational_operator: _ => token(addDots('//')),
_rational_operator: _ => addDot('//'),

_bitshift_operator: _ => token(addDots(OPERATORS.bitshift)),
_bitshift_operator: _ => addDot(OPERATORS.bitshift),

_power_operator: _ => token(addDots(OPERATORS.power)),
_power_operator: _ => addDot(OPERATORS.power),


_tilde_operator: _ => token(addDots('~')), // unary or assignment
_tilde_operator: _ => addDot('~'), // unary or assignment

_type_order_operator: _ => token(addDots('<: >:')), // unary or comparison
_type_order_operator: _ => addDot('<: >:'), // unary or comparison

_unary_operator: _ => token(addDots(OPERATORS.unary)),
_unary_operator: _ => addDot(OPERATORS.unary),

_unary_plus_operator: _ => token(addDots(OPERATORS.unary_plus)),
_unary_plus_operator: _ => addDot(OPERATORS.unary_plus),


_syntactic_operator: _ => token(choice('$', '.', '...', '->', '?')),
_syntactic_operator: _ => choice('$', '.', '...', '->', '?'),


_terminator: _ => choice(/\r?\n/, /;+/),
Expand Down Expand Up @@ -1178,9 +1178,9 @@ function sep1(separator, rule) {
*
* @param {string} operatorString
*/
function addDots(operatorString) {
function addDot(operatorString) {
const operators = operatorString.trim().split(/\s+/);
return seq(optional('.'), choice(...operators));
return token(seq(optional('.'), choice(...operators)));
}

/**
Expand Down

0 comments on commit ac751d1

Please sign in to comment.