scala / scala/scala-parser-combinators

RegexParsers: skipWhitespaces when using implicit conversion from a character

Open
#320 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
679
Forks
131
Avg merge
8h 25m
Merged PRs (30d)
3

Description

(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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading RegexParsers and its parent Parsers, focusing on the implicit conversion from a character to accept(c) and how literal parsers skip whitespace. Verify the existing examples with leading whitespace, then ensure character-based parsers behave consistently and confirm the quoted-string example parses with whitespace before delimiters.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.