Replies: 2 comments 3 replies
-
Hey Darren, It's not very pretty, but this can be done using a sequence. E.g.:
etc. I've considered adding first-class support for this, but I haven't yet seen a use case that really warrants it. (Aside: Thanks for the inaugural post in our Github discussions! 🎉) |
Beta Was this translation helpful? Give feedback.
-
Today's Advent of Code puzzle specifies that values be 1–3 digits. I didn't think of
actions = {
int1000_hundreds(hundreds, tens) { return parseInt(hundreds.sourceString) * 100 + tens.eval() },
int1000_tens(tens, ones) { return parseInt(tens.sourceString) * 10 + ones.eval() },
int1000_ones(ones) { return parseInt(ones.sourceString) }
} It's terribly verbose and clumsy, and brought me here to find out if there's a better idiom. I admit I can't think of anything that would make this truly critical to be in the grammar. I think it was mostly that it was my first encounter with ohm, I was writing the grammar before I knew how the semantics would be evaluated, so I tried to define as much of the spec as possible in the grammar. Easier to keep the test cases together that way too. On the other hand, being a pattern language with |
Beta Was this translation helpful? Give feedback.
-
Looking for an approach to be able to define length constraints on tokens. As a canonical example, a math language that only allows variables to be a maximum of 4 characters would work.
GOOD:
var + 6 = var2
BAD:
var + 16 = otherVariable
Error: OtherVariable is too long (variables can be at most 4 characters in length)
Beta Was this translation helpful? Give feedback.
All reactions