rokucommunity / rokucommunity/brighterscript

Support finding lower and upper bounds of an expression chain

Open
#847 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted plugin api
Dominant language
TypeScript
Stars
208
Forks
68
Avg merge
8h 39m
Merged PRs (30d)
39

Description

We need a way to find the lower bounds and upper bounds (leftmost edge and rightmost edge) of an expression chain. Consider the following example:

delta["echo"]@.foxtrot(    alpha.beta.charlie) 

For alpha.beta.charlie we want to find:

  • expressionStart -> alpha (VariableExpression)
  • expressionEnd -> charlie (DottedGetExpression)

For delta["echo"]@.foxtrot( alpha.beta.charlie) we want to find:

  • expressionStart - > delta (VariableExpression)
  • expressionEnd -> .foxtrot(...) (CallExpression)

I envision this being implemented by adding two new abstract methods to AstNode (or perhaps just on Expression since Statements make no sense in this context):

/**
 * Get the subject of a given expression (the leftmost expression). (i.e. from `a.b.c` this returns `a`)
 */
findExpressionStart();

/**
 * Get the rightmost expression from a given expression. (i.e. from `a.b.c` this returns `c`)
 */
findExpressionEnd()
  • findExpressionStart could probably have a hardcoded return true for VariableExpression, LiteralExpression, and any other expression types that are exclusively used to "start" an expression chain

  • findExpressionEnd will be a little more complicated, but might be solved by checking parents are the IndexedGetExpression, DottedGetExpression and CallExpression with the right callee if expr.parent instanceof CallExpression && expr === parent.callee

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 locating AstNode, Expression, VariableExpression, LiteralExpression, IndexedGetExpression, DottedGetExpression, and CallExpression in the TypeScript source. Trace how the example expression chains are represented, then define the expected start and end results for both examples and add tests covering those cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
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.