Skip to content

RegexParsers: skipWhitespaces when using implicit conversion from a character #320

Open
@scabug

Description

@scabug

(I wanted to lower the priority of this issue, but somehow wasn't allowed to do so in the bug filing form)

A RegexParsers parser should skip whitespaces. It does so by omitting them in advance of each parsing step (so for example the literal("bla") parser at first skips all the whitespaces and then parses the literal "bla").

A string s is implicitly converted to a literal(s) parser. So writing

class MyParser extends RegexParsers {
def text = "first"|"second"
}

will parse "first" or "second" with arbitrary whitespaces in front of them.

A character c is implicitly converted to accept(c). accept() is defined in Parsers and not in RegexParsers, so the whitespaced aren't skipped here.

class MyParser extends RegexParsers {
def text = 'f'|'s'
}

will parse "f" or "s" but only if there aren't whitespaces in front of it.

This is somehow inconsistent and it took me a long time to realize it when I tried to write a string parser like

def string = '"' ~ stringcharacters ~ '"'

I think RegexParsers should override the parsers from its parent class and also skip whitespaces in front of them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions