Skip to content

Commit

Permalink
mark prefix operators
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed Apr 12, 2024
1 parent 92bc7bd commit cc9d4c0
Show file tree
Hide file tree
Showing 18 changed files with 259 additions and 134 deletions.
10 changes: 5 additions & 5 deletions grammar/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = {
_qvarid: $ => alias($._qualified_variable, $.qualified),
_varids: $ => choice($._qvarid, $.variable),

_var: $ => choice($.variable, $._varsym_prefix),
_qvar: $ => choice($._qvarid, $._qualified_operator_prefix),
_var: $ => choice($.variable, $._pvarsym),
_qvar: $ => choice($._qvarid, $._pqvarsym),
_vars: $ => choice($._var, $._qvar),

_variable_ticked: $ => ticked($.variable),
Expand Down Expand Up @@ -51,8 +51,8 @@ module.exports = {
_qconid: $ => alias($._qualified_constructor, $.qualified),
_conids: $ => choice($._qconid, $.constructor),

_con: $ => choice($.constructor, $._consym_prefix),
_qcon: $ => choice($._qconid, $._qualified_constructor_operator_prefix),
_con: $ => choice($.constructor, $._pconsym),
_qcon: $ => choice($._qconid, $._pqconsym),
// Prec for conflict between projection and qualified name in `A.b`
_cons: $ => choice(prec('qcon', $._con), $._qcon),

Expand Down Expand Up @@ -83,7 +83,7 @@ module.exports = {
_qtyconid: $ => alias($._qualified_type, $.qualified),
_tyconids: $ => choice($._qtyconid, $._tyconid),

_tycon: $ => choice($._tyconid, $._varsym_prefix, $._consym_prefix),
_tycon: $ => choice($._tyconid, $._pvarsym, $._pconsym),
_qtycon: $ => choice($._qtyconid, $._qsym_prefix),
_tycons: $ => choice($._tycon, $._qtycon),

Expand Down
3 changes: 1 addition & 2 deletions grammar/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ module.exports = {
optional($.namespace),
choice(
$._tyconid,
$._varsym_prefix,
$._consym_prefix,
$._sym_prefix,
),
optional($.import_con_names),
),
Expand Down
6 changes: 2 additions & 4 deletions grammar/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ module.exports = {
seq(
optional($.namespace),
choice(
parens($, $.operator),
parens($, $._operator_minus),
parens($, $._qvarsym),
parens($, $._consyms),
$._sym_prefix,
$._qsym_prefix,
$._tyconids,
),
optional($.export_names),
Expand Down
13 changes: 10 additions & 3 deletions grammar/operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ module.exports = {
),
),

_pvarsym: $ => alias($._varsym_prefix, $.prefix_id),

_qualified_varsym: $ => qualified($, choice($.operator, $._operator_minus)),
_qvarsym: $ => alias($._qualified_varsym, $.qualified),

_varsyms: $ => choice($.operator, $._qvarsym),

_qualified_operator_prefix: $ => parens($, $._qvarsym),
_qvarsym_prefix: $ => parens($, $._qvarsym),
_pqvarsym: $ => alias($._qvarsym_prefix, $.prefix_id),

// ------------------------------------------------------------------------
// con
Expand All @@ -47,22 +50,26 @@ module.exports = {
_constructor_operator_alias: $ => $.constructor_operator,

_consym_prefix: $ => parens($, $.constructor_operator),
_pconsym: $ => alias($._consym_prefix, $.prefix_id),

_qualified_consym: $ => qualified($, $.constructor_operator),
_qconsym: $ => alias($._qualified_consym, $.qualified),

_consyms: $ => choice($.constructor_operator, $._qconsym),

_qualified_constructor_operator_prefix: $ => parens($, $._qconsym),
_qconsym_prefix: $ => parens($, $._qconsym),
_pqconsym: $ => alias($._qconsym_prefix, $.prefix_id),

// ------------------------------------------------------------------------
// op
// ------------------------------------------------------------------------

_sym: $ => choice($._operator_alias, $._constructor_operator_alias),

_qsym_prefix: $ => choice($._qualified_operator_prefix, $._qualified_constructor_operator_prefix),
_sym_prefix: $ => choice($._pvarsym, $._pconsym),

_qsym: $ => choice($._qvarsym, $._qconsym),

_qsym_prefix: $ => choice($._pqvarsym, $._pqconsym),

}
15 changes: 10 additions & 5 deletions test/corpus/class.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,16 @@ class A where
(class_declarations
(signature
(binding_list
(operator)
(prefix_id
(operator))
(variable)
(operator)
(operator)
(prefix_id
(operator))
(prefix_id
(operator))
(variable)
(operator))
(prefix_id
(operator)))
(type_name
(type_variable)))))))

Expand Down Expand Up @@ -433,7 +437,8 @@ class (++) a b
(class_apply
(class_name
(type_name
(operator)))
(prefix_id
(operator))))
(type_name
(type_variable))
(type_name
Expand Down
6 changes: 4 additions & 2 deletions test/corpus/data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ data A = A deriving ((+))
(class_apply
(class_name
(type_name
(operator)))
(prefix_id
(operator))))
(type_name
(type)))))
(data_type
Expand All @@ -490,7 +491,8 @@ data A = A deriving ((+))
(constructor)))
(deriving
(class_name
(operator))))))
(prefix_id
(operator)))))))

================================================================================
data: datatype context
Expand Down
12 changes: 8 additions & 4 deletions test/corpus/decl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,15 @@ decl: operator binding list
(declarations
(signature
(binding_list
(operator)
(operator)
(operator)
(prefix_id
(operator))
(prefix_id
(operator))
(prefix_id
(operator))
(variable)
(operator))
(prefix_id
(operator)))
(type_name
(type_variable)))))

Expand Down
18 changes: 10 additions & 8 deletions test/corpus/exp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2153,10 +2153,11 @@ a = a A.!? a a
(bind
(variable)
(exp_name
(qualified
(module
(module_id))
(operator))))
(prefix_id
(qualified
(module
(module_id))
(operator)))))
(bind
(variable)
(exp_infix
Expand Down Expand Up @@ -2213,10 +2214,11 @@ a = '(A..&)
(bind
(variable)
(exp_th_quoted_name
(qualified
(module
(module_id))
(operator))))))
(prefix_id
(qualified
(module
(module_id))
(operator)))))))

================================================================================
exp: negation in tuple
Expand Down
9 changes: 6 additions & 3 deletions test/corpus/family.txt
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ type family (<>) a a where
(head
(type_apply
(type_name
(operator))
(prefix_id
(operator)))
(type_name
(type_variable))
(type_name
Expand Down Expand Up @@ -745,12 +746,14 @@ type family (<>) where
(type_family
(head
(type_name
(operator)))
(prefix_id
(operator))))
(equations
(equation
(pattern
(type_name
(operator)))
(prefix_id
(operator))))
(type_name
(type)))))))

Expand Down
6 changes: 4 additions & 2 deletions test/corpus/gadt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ data a +++ b where
(type_variable)))
(gadt_constructors
(gadt_constructor
(constructor_operator)
(prefix_id
(constructor_operator))
(type_fun
(type_name
(type_variable))
Expand Down Expand Up @@ -326,7 +327,8 @@ data (:#) a where
(data_type
(type_apply
(type_name
(constructor_operator))
(prefix_id
(constructor_operator)))
(type_name
(type_variable))))))

Expand Down
15 changes: 10 additions & 5 deletions test/corpus/import.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ import Aaa.A (A((<>)))
(import_item
(type)
(import_con_names
(operator)))))))
(prefix_id
(operator))))))))

================================================================================
import: type dotdot
Expand Down Expand Up @@ -378,9 +379,11 @@ import A ((:<|>)((:<|>)))
(module_id))
(import_list
(import_item
(constructor_operator)
(prefix_id
(constructor_operator))
(import_con_names
(constructor_operator)))))))
(prefix_id
(constructor_operator))))))))

================================================================================
import: operator
Expand All @@ -397,7 +400,8 @@ import A ((<=<))
(module_id))
(import_list
(import_item
(operator))))))
(prefix_id
(operator)))))))

================================================================================
import: pattern/type
Expand Down Expand Up @@ -453,6 +457,7 @@ import A (type (++)(..))
(import_list
(import_item
(namespace)
(operator)
(prefix_id
(operator))
(import_con_names
(all_names)))))))
Loading

0 comments on commit cc9d4c0

Please sign in to comment.