ollef / Earley

Parsing all context-free grammars using Earley's algorithm in Haskell.
BSD 3-Clause "New" or "Revised" License
361 stars 24 forks source link

INDENT and DEDENT #49

Closed s5bug closed 4 years ago

s5bug commented 4 years ago

Is there a way to match INDENT/DEDENT or make parsers take an indentation level?

func foo(a: A, b: B): C =
  theresSomeIndentRequiredHere(a, b)

func noMoreIndentMeansNoMoreFoo: D = ???
ollef commented 4 years ago

Hey!

Good question.

There's no support built into the Earley library for indentation sensitivity, but perhaps a custom lexer could output such tokens for Earley to consume?

s5bug commented 4 years ago

Any recommendations on how to do that effectively and efficiently?

ollef commented 4 years ago

I'm afraid I can't help you there, but perhaps someone else can?

s5bug commented 4 years ago

I've opened a StackOverflow question. If I get a reasonable answer, I'll post it here and close the issue.

s5bug commented 4 years ago

I've been playing around with Megaparsec and Alex, both seem equally suited to handle this situation.