How does "OPTION" work?
See original GitHub issueI’m currently working on this set of tokens:
[ Let {
image: 'let',
startOffset: 0,
startLine: 1,
startColumn: 1,
endLine: 1,
endColumn: 3,
isInsertedInRecovery: false },
Identifier {
image: 'a',
startOffset: 4,
startLine: 1,
startColumn: 5,
endLine: 1,
endColumn: 5,
isInsertedInRecovery: false },
Equals {
image: '=',
startOffset: 6,
startLine: 1,
startColumn: 7,
endLine: 1,
endColumn: 7,
isInsertedInRecovery: false },
NumberLiteral {
image: '1',
startOffset: 8,
startLine: 1,
startColumn: 9,
endLine: 1,
endColumn: 9,
isInsertedInRecovery: false } ]
I’m trying to process it like so:
this.RULE("LetStatement", () => {
this.CONSUME(Let);
this.CONSUME(Identifier);
this.CONSUME(Equals);
this.CONSUME(NumberLiteral);
this.OPTION(() => {
this.CONSUME(Semicolon);
});
});
This will fail with:
/srv/http/lang/node_modules/chevrotain/lib/src/parse/parser_public.js:1153
throw e;
^
TypeError: Cannot read property 'accept' of undefined
at getLookaheadPathsForOptionalProd (/srv/http/lang/node_modules/chevrotain/lib/src/parse/grammar/lookahead.js:369:16)
at buildLookaheadFuncForOptionalProd (/srv/http/lang/node_modules/chevrotain/lib/src/parse/grammar/lookahead.js:38:26)
at buildLookaheadForOption (/srv/http/lang/node_modules/chevrotain/lib/src/parse/grammar/lookahead.js:43:12)
at ChiParser.Parser.getLookaheadFuncFor (/srv/http/lang/node_modules/chevrotain/lib/src/parse/parser_public.js:1601:36)
at ChiParser.Parser.getLookaheadFuncForOption (/srv/http/lang/node_modules/chevrotain/lib/src/parse/parser_public.js:1561:21)
at ChiParser.Parser.optionInternal (/srv/http/lang/node_modules/chevrotain/lib/src/parse/parser_public.js:1391:34)
at ChiParser.Parser.OPTION1 (/srv/http/lang/node_modules/chevrotain/lib/src/parse/parser_public.js:524:21)
at ChiParser.Parser.OPTION (/srv/http/lang/node_modules/chevrotain/lib/src/parse/parser_public.js:500:29)
at ChiParser.RULE (/srv/http/lang/src/Parser.js:58:9)
at ChiParser.invokeRuleWithTry (/srv/http/lang/node_modules/chevrotain/lib/src/parse/parser_public.js:1108:29)
Why? Am I misunderstanding how OPTION
works?
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
What are Options? Types, Spreads, Example, and Risk Metrics
How Do Options Work? Options are a type of derivative product that allow investors to speculate on or hedge against the volatility of...
Read more >Options Trading Explained: A Beginner's Guide - CNBC
An option is a contract giving the investor the right (or option) but not the obligation to buy or sell a specific stock...
Read more >An Example of How Options Work | Desjardins Online Brokerage
Subtract what you paid for the contract, and your profit is ($8.25 - $3.15) x 100 = $510. You almost doubled our money...
Read more >How Do Options Work? Here's What Beginners Need to Know
An option is a contract that allows you the ability to purchase or sell an asset at a set price, as long as...
Read more >Options Definition - NerdWallet
How options work · Exercise the option, meaning you'll buy or sell shares of the stock at the strike price. · Sell the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think I need to review the entire tutorial’s code. Perhaps create an “offline” version of it and copy paste the source code from it.
It looks like overtime it has become a mixture of ES6 + TypeScript but probably not valid in either 😢.
I made some quick fixes. hopefully they are good enough for now.
Thanks so much! 👍 😃