scala / scala/scala-parser-combinators

Making position a type member in parsers.scala

Open
#89 0 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

Hi,

The parser combinators works wonderfully, except for a minor tweak I'd like to add: I would like to constrain the type of position data structure in my parser pipeline.

At the moment, parsers.scala will use the base type Position, and leave the specific position type to Readers. The downstream operation will need to perform pattern matching to cast the position data into specific type, e.g. OffsetPosition. This gets tedious if I already know that my parser will only use one specific Position type

I propose to make position a type member in a similar fashion to Elem and Input. Existing code base can be kept in-tact by adding

type Pos = Position. 

If needed, a user can constrain the position type to be more specific by overriding the type member;
e.g.

override type Pos = OffsetPosition

I will send out a pull request on the proposed change. Please take a look.

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 in parsers.scala, comparing the existing Position handling with the Elem and Input type members and the Readers that provide specific positions such as OffsetPosition. The change is done when Pos defaults to Position for existing code and can be overridden with a more specific position type without requiring downstream casts.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.