radspec
radspec copied to clipboard
Node and token location information
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
Current balance: 0.0 ETH
Tokens: ANT: 10.00
Contract address: 0xc0e843ff98839af97cf44cc82b09e6eb354d088c
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.
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?
@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
sounds great, going to give a try tonight :)
On 15 January 2018 at 17:16, Oliver [email protected] wrote:
@oivoodoo https://github.com/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 😊
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/aragon/radspec/issues/5#issuecomment-357694544, or mute the thread https://github.com/notifications/unsubscribe-auth/AADUxYSr_X-6i4-WlkbcXG2BV9Dia8Amks5tK13BgaJpZM4Q8mDs .
-- Best Regards, Alexandr
skype: oivoodoo