Comments (8)
Try parser.nextIs(EndToken.get())
. The end token is unparseable by design and is used by LexParser to assure that the entire input is consumed when calling parseFully. If you are writing statements and not expressions, you will most likely want to do this
from bychan.
In the minilang example, the semicolon is simply a separator between sub-expressions, and the whole language is expression based. If you use this approach, you won't need to check for an end token. This is due to the fact that the end token has LBP 0. When you parse the whole expression using LexParser, it will continue until it finds a token with LBP <=0. If you call parseFully it will also check that only the end token remains as i mentioned above.
from bychan.
@atorstling "The end token is unparseable by design" I thought I read that part correctly. I did try parser.nextIs(EndToken.get())
before, but the IDE simply says no instance(s) of type variable(s) N exist so that EndToken<N> conforms to TokenKey
I'm sorry, I may not be that advance in Java to figure out a solution. :(
from bychan.
Ah, my bad, let me get back to you when I'm at a computer.
from bychan.
http://stackoverflow.com/questions/40949670/is-there-a-way-to-check-if-next-token-is-end
from bychan.
Thanks for the stackoverflow post. That was an omission, see the stackoverflow. Fix applied.
from bychan.
Hey @danvim, I don't know how to reach you, do you have gitter? Anyway, I decided to clean up a lot of cruft in Bychan, and broke backwards compatibility while doing it. Basically as the end of the README says, the support for statements was not that great. The Repl and LexParser more or less assumed that you would always start by parsing an expression. I've changed that assumption now and made the API against the Parser identical irrespective if you are parsing from a token callback or not. So you are now able to move code out of token callbacks into functions and call functions in a recursive descend fashion. Check ReadmeExamples::statements for an example. I hope this makes it easier for you to parse statements, certainly if your topmost production is a statement.
from bychan.
@atorstling Thanks, I'll check that out very soon. :)
from bychan.
Related Issues (20)
- Rename to Bychan
- Right-associative operators
- Suffix operators
- Empty input HOT 1
- Dynamic tokens without name HOT 1
- Test dependent project HOT 1
- addToken could be private
- standaloneParseAs in tokenBuilder HOT 1
- Nonclementure HOT 1
- Instance of token: lexeme
- Stick with v1 fluent interface HOT 1
- Check getToken by key HOT 1
- Write examples
- Group dynamic lexeme info together in dynamic callbacks
- Row col in lexing as well
- Perf: Lexer should operate on stream, not string HOT 1
- Last try to remove UserParserCallbackImpl HOT 1
- Multiline REPL
- Is there a good way of throwing Runtime errors while running Repl? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bychan.