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

Add support for curried dot operator (.) #36

Merged
merged 1 commit into from
Dec 25, 2023
Merged
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
46 changes: 46 additions & 0 deletions corpus/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -732,3 +732,49 @@ scientific notation
(record_operand
(atom
(num_literal))))))))

================================================================================
curried dot operator
================================================================================

"foo"
|> (.) { foo = "bar" }

--------------------------------------------------------------------------------

(term
(uni_term
(infix_expr
(infix_expr
(applicative
(record_operand
(atom
(str_chunks
(str_chunks_single
(chunk_literal_single
(str_literal))))))))
(infix_b_op_6)
(infix_expr
(applicative
(applicative
(record_operand
(atom
(curried_op))))
(record_operand
(atom
(uni_record
(record_last_field
(record_field
(field_path
(field_path_elem
(ident)))
(term
(uni_term
(infix_expr
(applicative
(record_operand
(atom
(str_chunks
(str_chunks_single
(chunk_literal_single
(str_literal))))))))))))))))))))
9 changes: 9 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,15 @@ module.exports = grammar({
//grammar.lalrpop: 617
curried_op: $ => choice(
$.infix_op,
// Field access isn't a proper infix operator, it's a form with special
// treatment (in particular because the second argument isn't necessarily
// a string but can be a statically known identifier, which can't be
// encoded as a generic operator application). It is thus not included in
// `infix_op`.
//
// Still, Nickel allows to use it as a curried operator as in `(.) foo
// bar`, so we add it here manually.
".",
// NOTE: Removed, see NOTE[special-infix].
//"|>",
//"!=",
Expand Down
4 changes: 4 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,10 @@
{
"type": "SYMBOL",
"name": "infix_op"
},
{
"type": "STRING",
"value": "."
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
"fields": {},
"children": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "infix_op",
Expand Down
Loading
Loading