whitequark / whitequark/parser

Consider making location explicit.

Open
#691 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Yacc
Stars
1.6k
Forks
205
PR merge metrics
No merged PRs in 30d

Description

I've been using this gem quite a bit recently.

I'm also looking at parsing C/C++ using clang into the same format, with the goal of providing a unified index for symbol lookup (as much as is possible).

In practice, it seems to me that an AST is (almost) always tied to some kind of source "location". I know there are cases where an AST is completely detached from actual code, but that is not, in my experience, the most common use case.

Have you considered whether it would make sense to expose a generic Location abstraction in the AST gem, that would cover multiple use cases?

In more concrete terms, making an interface for:

class AST::Node
  attr :location
end

# Introduce:

class AST::Location
  # Generic handling of source code, e.g. getting textual value, etc.
end

When I come to implementing a parser for C++ using the AST gem, I'm either going to have to roll my own location class with the same interface as the parser gem, or, preferably, follow some standard set out by the AST gem. The benefit would make it easier for converting an AST back into source code.

Essentially, what I'm proposing, is whether we can move a very light amount of location interface abstractions into the AST gem, such that parsing other languages could expose a shared interface for accessing location details.

Contributor guide

Open the contributing guide

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 reviewing the proposed AST::Node location attribute and the AST::Location interface in the issue, then read the surrounding comment discussion for an agreed direction. Done would require a decided, shared location abstraction that supports the stated source-location and textual-value use cases, but the issue does not identify files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.