Comments (8)
It actually is an error in the grammar.
start = scheme
scheme = ALPHA ( ALPHA / DIGIT / "+" / "-" / "." )*
ALPHA = [a-zA-Z]
DIGIT = [0-9]
Would be nice to catch this.
from pegjs.
I believe the error happens whenever you put non-terminal with asterisk within another non-terminal, that has asterisk after the other non-terminal as well (as shown in s3u comments). I think this fact can make a detection of this issue quite easy, although I think it is not necessary to consider this an error (I think a parser can be created for such a grammar). Fortunately, I believe this issue can be obeyed (that you can alternate your grammar in a way when it will not use such as rules), so the quick and dirty fix is just to make this issue visible, so the user knows what to avoid.
from pegjs.
You don't seem to need to need the double kleene situation to get this, and I believe infinite loop is actually "correct behavior".The reduction of this error seems to be:
start = .* (!.)*
What's happening is that you are using a kleene operator on an expression that expects zero length results. As such, yes, their are always infinite of these at the end of the file. The rule ALPHA = [a-zA-Z]* reduces to this as well because at the end of the file it matches zero-length versions of this indefinitely.
from pegjs.
Just to highlight that there are many ways to get this, the following also generates an infinite loop:
start = .* (!.)+
This also serves to show that its difficult to define "how many" matches should be allowed in these cases. If it was just "*" that produced this then there may be a tempting (but I believe still wrong) argument that it should just somehow know to not match at all.
from pegjs.
It would be nice to have a warning when generating a parser with a possibility to enter infinite loop on some inputs. However I am not 100% sure all such cases can be caught statically, and presence of actions/predicates would complicate things even if they can. I'll have to think about this more deeply.
But it's certainly not a priority now.
from pegjs.
Is there any way support could be built in to deal with recursion beyond even exiting upon it? I tried adapting the ABNF grammar, but am running into a loop: https://github.com/brettz9/js2peg/blob/rfc5234/examples/rfc5234.pegjs
from pegjs.
Turns out it was needed in my example, as I had a mistake...
from pegjs.
FWIW infinite loops are biting me hard write now in the tool I'm writing for editing and evaluating PEGs live. Certain transitory grammars produce a parser that then hangs the browser, killing your editing session (and losing recent unsaved work).
Edit: I just spent several hours moving to Web Workers so that I can detect and kill a parsing that is stuck in some endless recursion/loop.
from pegjs.
Related Issues (20)
- Up-to-date JavaScript grammar HOT 2
- Using PEG.js at runtime works, but generated grammer fails to work? HOT 2
- Operator precedence tree compiling extremely slowly HOT 2
- Merging multiple single-character expressions
- Fork of the online editor with inline errors HOT 1
- Ignore me -- wrong project
- [composable, declarative, typescript] react-peg: parser generator based on pegjs
- Bug with context-sensitive grammar HOT 1
- option to generate an es module instead of commonjs module HOT 12
- Cannot use parseFloat inside grammar HOT 4
- literalEscape HOT 1
- Support for runtime context object? HOT 3
- [META] Switch to Peggy HOT 9
- Grammar action errors need to be more informative HOT 4
- Allow access to different rules in code blocks HOT 2
- Using same rule in pattern HOT 2
- Pegjs online can't parser parser.pegjs HOT 2
- Variables in parentheses can't be accessed
- Documentation should describe all features of the grammar specification language (e.g., dollar sign "$", "text()") HOT 3
- Deprecate/archive and recommend peggy.js as official successor project? HOT 4
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 pegjs.