Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.
Discussion options

You must be logged in to vote

This cannot be done with precedence because the operator for assigning will always instead be parsed as the operator for eq assuming that they have the same symbol, because they are both infix. This means that we will have to use context sensitive parsing.

There are a couple different ways in Chumsky to do this. The first would be with contextual and the second with validate. For both examples, I will be using the following toy language:

PROGRAM => EXPR
EXPR    => NUM
EXPR    => MAP
EXPR    => ARRAY
EXPR    => '(' EXPR ')'
EXPR    => EXPR '+' EXPR
EXPR    => EXPR '=' EXPR
ARRAY   => '[' (EXPR (',' EXPR)*)? ']'
MAP     => '[' (ENTRY (',' ENTRY)*)? ']'
ENTRY   => EXPR '=' EXPR
NUM     => 'n'

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jimmycuadra
Comment options

@zesterer
Comment options

Answer selected by jimmycuadra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants