martmists
05/31/2022, 2:59 PMJoffrey
06/01/2022, 7:29 PMOptional
in Kotlin can just be a nullable type, that's multiplatform and you benefit from a bunch of syntax features that are nicer than `Optional`'s own utilities.
Regarding StackOverflowError
, what are you trying to do with this class in the first place?mbonnin
06/01/2022, 7:31 PMnull
and undefined
could be useful. We ended up defining our own Optional
but having a standard way to do it would be nicemartmists
06/02/2022, 7:55 PMJoffrey
06/02/2022, 7:56 PMmartmists
06/02/2022, 8:00 PMJoffrey
06/02/2022, 8:06 PMmartmists
06/02/2022, 8:26 PMexpr := expr '+' term | term
and while this could be expanded to term ('+' term)*
this can become increasingly big with more complex grammars, and there's a good reason to want to implement it recursively as also outlined in this medium post by Guido van Rossum: https://medium.com/@gvanrossum_83706/left-recursive-peg-grammars-65dab3c580e1Joffrey
06/02/2022, 8:36 PMif it ends up recursing to deep I throw a different error, stating memoLeft needs to be used and in which rule it's necessaryI thought
memoLeft
was a function name, leading to a different implementation of your algo. So I thought your consumers/users were writing code. If I understand correctly now, your users write grammars, and your code is the parser. And memoLeft
is some sort of option that users can choose to use for some rules in the grammar, is this correct?martmists
06/02/2022, 8:58 PMmemoLeft
if they have left-recursion, otherwise it will cause a StackOverflowError (or similar on other targets), in which case I want to notify the user to use memoLeft
to avoid that problem.commaList := (commaList | term) ',' term
would be written as
private val commaList by sequence(memoLeft { // memoLeft needed due to left-recursion
val l = first(
::commaList,
::term
)
char(',')
val r = term()
"$l,$r" // String for now, could be replaced with AST/IR elements
})
commaList
Joffrey
06/03/2022, 7:42 AMmartmists
06/03/2022, 10:58 AM1 + 1 + 1 + 1 ...
repeating 50 times isn't any less valid.