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

Help with parser #25

Open
rndev-io opened this issue May 7, 2020 · 0 comments
Open

Help with parser #25

rndev-io opened this issue May 7, 2020 · 0 comments

Comments

@rndev-io
Copy link

rndev-io commented May 7, 2020

Hi, cool and useful library, thanks!

I need help to write parser for next grammar (it's some subset of CMake grammar)

FIRST(abc efg)

S_E_C_O_N_D()

third(
    abc
    efg
)

FOURTH(
    abc.efg
)

Where FIRST, S_E_C_O_N_D, third, FOURTH some macros, and abc, efg, abc.efg macros arguments (zero or more). I write parser, but I don't understand how to separate macros and arguments tokenization.

class CMake : Grammar<Any?>() {
    val LINE_COMMENT by token("#.*", ignore = true)
    val NL by token("[\r\n]+", ignore = true)
    val WS by token("\\s+", ignore = true)
    val O_PAREN by token("\\(")
    val C_PAREN by token("\\)")
    val IDENT by token("[A-Za-z_][A-Za-z0-9_]*")
    val ARG by token("[^\\s()#]+")
    val macros by IDENT * -O_PAREN * optional(parser(this::arguments)) * -C_PAREN
    val arguments by separated(parser(this::ARG), WS, true)
    override val rootParser by oneOrMore(macros)
}

This parser throw exception Could not parse input: MismatchedToken(expected=C_PAREN (\)), found=IDENT for "abc" at 6 (1:7)), but abc is ARG, not IDENT.

Thanks for help!

@rndev-io rndev-io changed the title Separate similar tokens Help with parser May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant