Skip to content

feat: optional spaces and whitespaces #76

Description

@ladihzey

What problem does this feature solve?

Currently the whitespace parser is strict and requires at least one character to be matched. There are many cases where I need to wrap it into optional parser e.g. the spaces before and after argument braces are optional.

function main() {...}
function main (){...}

Describe the solution

I think aligning this parser with other API would be a little bit more convenient by matching the current pairs such as many and many1, sepBy and sepBy1:

  • whitespaces1 - requires a single or multiple characters, works as the current whitespace
  • whitespaces - requires zero or more whitespaces to match, works as optional(whitespace)
  • (optional) wrapWhitespaces and wrapWhitespaces1 - that should prevent writing the common pattern of surrounding whitespaces over and over again:
sequence(
    functionKeyword,
    takeMid(
        optional(whitespace),
        functionName,
        optional(whitespace)
   )
)

/* could be turned into */

sequence(
    functionKeyword,
    wrapWhitespaces(functionName)
)

Metadata

Metadata

Assignees

Labels

A-parsersArea: Issues related to parsersC-feature-acceptedCategory: A feature request that has been accepted and awaiting implementationP-mediumPriority: Medium

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions