h0tk3y / better-parse

A nice parser combinator library for Kotlin
Apache License 2.0
421 stars 42 forks source link

RegexToken broken with latest js backend #51

Closed InfectedBytes closed 2 years ago

InfectedBytes commented 2 years ago

Using the latest Kotlin version (1.60.20) better-parse doesn't work with js backend. Using the example BooleanGrammar parsing always results in exception:

kotlin_com_github_h0tk3y_betterParse_better_parse.js?6388:1744 Uncaught TypeError: Cannot read properties of undefined (reading 'source')
    at preprocessRegex$outlinedJsCode$ (kotlin_com_github_h0tk3y_betterParse_better_parse.js?6388:1744:1)
    at preprocessRegex (kotlin_com_github_h0tk3y_betterParse_better_parse.js?6388:1691:1)
    at RegexToken_init_$Init$ (kotlin_com_github_h0tk3y_betterParse_better_parse.js?6388:1705:1)
    at RegexToken_init_$Create$ (kotlin_com_github_h0tk3y_betterParse_better_parse.js?6388:1709:1)
    at regexToken (kotlin_com_github_h0tk3y_betterParse_better_parse.js?6388:908:1)
    at regexToken$default (kotlin_com_github_h0tk3y_betterParse_better_parse.js?6388:913:1)
    at new BooleanGrammar (CharacterCompanion.js?f640:512:1)
    at BooleanGrammar_getInstance (CharacterCompanion.js?f640:683:1)

Problem is caused by the inline js code of preprocessRegex. It tries to access _nativePattern/nativePattern_0 of Kotlin js Regex class, but they are undefined. Changing it to nativePattern_1 solves the issue