Comments (4)
Hi,
I suspect the problem is that if your parser operates directly on the chars (as opposed to a token stream), then this grammar is not LL(1). When the parser encouters a "*" within the comment, it needs to look an extra char ahead to verify that "/" is the following char and therefore we are at the comment end. This makes it an LL(2) grammar, which this parser doesn't support.
One workardound is to first convert the char stream to a token stream, such that "/" and "/" become single tokens (e.g. COMMENT_START and COMMENT_END).
Some parsers get around this restriction by allowing backtracking. The problem with this is when the parser encounters an actual syntax error it then backtracks to see if there exists another route, meaning you then lose the location at which the error occurred, and the resultant error message is usually meaningless.
I'll have a play around with this to see whether there are any other solutions.
from funcj.
I got a hacky solution working but it has flaws:
public static final Parser<Chr, String> blockComment() {
final String[] prev = {""};
return string("/*")
.andR(satisfy("closing block comment", c -> {
if (c.equals('/') && prev[0] == "*") {
return false;
} else {
prev[0] = String.valueOf(c);
return true;
}
}).many())
.map(Chr:: listToString)
.map(s -> s.substring(0, s.length() - 2));
}
The main issue is that you have to reconstruct the parser every time it is used.
from funcj.
Does look somewhat hacky, but if it works...
I'll close this issue for now.
from funcj.
It is totally hacky, I am not proud of it :)
To your original comment, I think I agree ... the performance hit might be minimal and the greater flexibility might be worth it.
from funcj.
Related Issues (20)
- Try/Option etc recursion scheme methods
- IList::flatmap does not assign result properly HOT 1
- Allow data to be serialised even if a ctor can't be found
- Add support for Avro
- Allow dynamic type tags to be disabled
- funcj.codec - add support for type aliases
- Codec support for configurable field naming
- Codec: registerAllowedPackage support for package wildcards
- Add support to JSON and XML streaming codecs for support pretty-printing
- `sepBy1` should return `NonEmpty<T>` HOT 1
- `choice` and `or` combinators do not work correctly with `string` HOT 2
- Strange behaviour for `choice` HOT 4
- Need help with my grammar definition HOT 4
- Partial parsing fails HOT 5
- Calling many() on an uninitialized reference throws exception but it shouldn't. HOT 3
- Request: Change visibility of various parser fields in `JsonCombParser` to public HOT 7
- Example parsers with specific Token data structure vs Chr HOT 3
- Help: Parsing expressions with operator precedence. HOT 2
- Parser doesn't try the alternative choice if first parser fails HOT 2
- Code coverage not complete for property tests in StateTe.java HOT 1
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 funcj.