Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node and token location information #5

Open
onbjerg opened this issue Dec 10, 2017 · 4 comments
Open

Node and token location information #5

onbjerg opened this issue Dec 10, 2017 · 4 comments

Comments

@onbjerg
Copy link
Contributor

onbjerg commented Dec 10, 2017

Add location information to tokens and AST nodes that map to the corresponding range in the source Radspec expression.

The location information should be under the key location and have the form:

{
  // The starting character in the source
  start: 0,
  // The ending character in the source
  end: 10
} 

Note that we do not support lines, since Radspec expressions are single line only (should we change this?).

This information will be used for #19.

Acceptance criteria

  • Above location information is added to AST nodes and tokens
  • Tests that demonstrate the information is correct
@status-open-bounty
Copy link

status-open-bounty commented Jan 9, 2018

Current balance: 0.0 ETH
Tokens: ANT: 10.00
Contract address: 0xc0e843ff98839af97cf44cc82b09e6eb354d088c
QR Code
Network: Mainnet
To claim this bounty sign up at https://openbounty.status.im and make sure to update your Ethereum address in My Payment Details so that the bounty is correctly allocated.
To fund it, send ETH or ERC20/ERC223 tokens to the contract address.

@oivoodoo
Copy link
Contributor

Hi @onbjerg . Could you place example criteria for this task?

Lets say we have this line 'Text 1+1'

tokens = [
  { type: 'TICK', location: { start: 5, end: 5 } },
  { type: 'NUMBER', location: { start: 6, end: 6 } },
  ...
]

or it should be something different?

@onbjerg
Copy link
Contributor Author

onbjerg commented Jan 15, 2018

@oivoodoo Your example is correct, however, when your addition expression gets turned into an AST node, the node should also look like this:

{
  type: 'BinaryExpression',
  operator: 'PLUS',
  // left: ...,
  // right: ...,
  location: {
    start: 6,
    end: 8
  }
}

The usefulness of this being implemented is that error messages can be a lot more helpful 😊

The thing I did for LLL.js (not finished, but available on my GitHub profile) is that I created a function that takes a closure that returns a node. It roughly looks like this:

function emitToken (closure) {
  let start = this.cursor
  let node = closure()
  
  return { location: { start, end: this.cursor }, ...node }
}

And then I wrapped every emittance of new nodes with this function, so that each time I consume a token etc., it will be reflected in the location property

@oivoodoo
Copy link
Contributor

oivoodoo commented Jan 15, 2018 via email

@sohkai sohkai removed the bounty label Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants