bijection / nearley-playground Goto Github PK
View Code? Open in Web Editor NEW⛹ Write Grammars for the Nearley Parser!
Home Page: https://omrelli.ug/nearley-playground/
License: MIT License
⛹ Write Grammars for the Nearley Parser!
Home Page: https://omrelli.ug/nearley-playground/
License: MIT License
Consider support use Moo at playground?
moo is the recommend tokenizer of nearley. so maybe it's required by users frequently.
This behavior was the source of much headache and confusion for me, because I thought that my parser was the problem.
For example, this simple grammar:
Main -> "foobar" {% () => "this has \n whitespace" %}
Produces this output in the test window:
"this has whitespace"
Example:
@builtin "string.ne"
@builtin "string.ne"
main -> dqstring
I duplicated the string import line, intending to replace "string.ne" with "number.ne".
Unfortunately the editor froze, but thanks to this comment I was able to retrieve my changes through localstorage.
Hi! I really like Nearley, and I was setting up some toy examples to teach others using the web browser playground app. But, it keeps freezing a lot. I fact, now it's freezing right away even with the most simple little grammars. What could be going on? The grammar is extremely simple in this case and it ran fine just moments ago. But now it does nothing but freeze, in chrome, in firefox, in private browsing.. yeah it just keeps freezing.
The script that is failing is:
http://omrelli.ug/nearley-playground/dist/client.bundle.js:20
What could be up?
Here's an example of a grammar I've put in when it's been freezing
MIDSOMER_MURDERS_PLOT -> LOCAL PROFESSION FOUND DEAD PLACE SUSPICION SUSPECT ANGRY BLAMED THREAT THREATENED
LOCAL -> "A local "
PROFESSION -> "linguist" | "philosopher" | "novelist"
FOUND -> " is found "
DEAD -> "drowned" | "strangled" | "dead" | "tortured to death" | "hanged" | "battered" | "suffocated" | "shot" | "knifed" | "nuked"
PLACE -> " in the coffee shop." |" in the swimming pool." | " after band practice."| " behind the primary school."
SUSPICION -> " Suspicion falls on the village "
SUSPECT -> "baker" | "pastor" | "mailman" | "florist" | "nerd" | "twins"
ANGRY -> ", angry that the "
BLAMED -> "new wind farm" | "pig" | "pub" | "decline in newspaper reading" | "metric system"
THREAT -> " might threaten "
THREATENED -> "the village fabric." | "what little sexual tension the village has left." | "the Old Inn." | "the cow farm."
It fails on line 20, but I don't know what the trouble is . I'm assuming copy-pasting in that bit of the script is not necessary (it's very large).
For some unknown reason, it now works in Chrome Incognito. I have done nothing different.
It can't select anything else but the first item for PROFESSION, so it's all linguists dying all the time (in this case). Unknown why, to me at least.
Output:
"A local linguist is found battered in the coffee shop. Suspicion falls on the village nerd, angry that the pub might threaten what little sexual tension the village has left."
“A local linguist is found shot after band practice. Suspicion falls on the village mailman, angry that the pub might threaten the Old Inn.”
"A local linguist is found dead after band practice. Suspicion falls on the village florist, angry that the decline in newspaper reading might threaten the village fabric.
Trying to use
@builtin "whitespace.ne"
causes
TypeError: __webpack_require__(...).readFileSync is not a function
...because it's not that easy to translate offset into line:col
Is there an easy way to refresh the tests after changing the grammar? Right now it seems like you have to change the text of the test. Seems there are a few options:
I'll consider a PR for this if I find some more time but wanted to see if there was something already in the works or that I missed.
I'm wanting to use the playground to teach context-free grammars to intro linguistics students. However, I'm often having problems with crashes myself and I'm worrying that the students will have too many problems.
a) which is the best browser to recommend them?
b) will clearing cookies be enough advice when it crashes?
I'm suspecting the crashing is because of some ambiguity, but sometimes it honestly crashes even with the simplest little grammar.
Never mind I'm just wigging out.
It would be very useful if the contents of the Nearley sandbox could passed via URL query string, e.g. see how https://flow.org/try/#0PTAEAEDMBsHsHcBQiAuBPADgU1AFSwM4qgC8oAPqAOQqEpUDcQA does it.
Hi @bijection looks like the nearley version being run is not the latest? I cannot use {% nuller %}
for example. cc @kach
Hi @bijection, does nearley-playground have an explicit OSS license?
As I develop a grammar, I'm specifying productions for many nonliterals. Each time I complete one, I want to test it before moving on to the next.
Currently, to do this I have to tinker with the "MAIN" nonliteral, so for example if I have:
Identifier -> ...
Integer -> ...
String -> ...
Then after finishing each of these I have to set
MAIN -> Identifier
# and after I'm done testing Identifiers, change it to next one
MAIN -> Integer
# and the next
MAIN -> String
To test out each of these.
The feature request is that with each test-case entered, a way to specify another nonliteral which the test case is meant for.
Reporting intuitive error messages is an important feature of a professional parser.
It seems the playground does not show any error message or error location, just a simple color red or green to indicate success failure:
Does Nearly itself not support error reporting? Or is this just a limitation of the playground?
bob -> bob | jill
jill -> "bob"
If you add a test with "bob", the page hangs. There should probably be something that catches grammars that seem to take too long to run, or to run the grammars on a webworker so it doesn't interrupt the user.
Hey, love the playground! Super handy for testing stuff out. However, I've gotten to the point in my grammar testing that I'd like to introduce a lexer to the code, but I'm not sure how to do that. In your examples, you use require
, which is a node.js thing, so I don't believe it will work in the browser. Supporting that, is that when I do use require, the console reports the following error:
Uncaught ReferenceError: require is not defined
at eval (eval at get_exports (tester.js?3b08:26), <anonymous>:7:16)
at eval (eval at get_exports (tester.js?3b08:26), <anonymous>:223:3)
at get_exports (tester.js?3b08:71)
at Tester.render (tester.js?3b08:41)
at eval (ReactCompositeComponent.js?063f:795)
at measureLifeCyclePerf (ReactCompositeComponent.js?063f:75)
at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js?063f:794)
at ReactCompositeComponentWrapper._renderValidatedComponent (ReactCompositeComponent.js?063f:821)
at ReactCompositeComponentWrapper._updateRenderedComponent (ReactCompositeComponent.js?063f:745)
at ReactCompositeComponentWrapper._performComponentUpdate (ReactCompositeComponent.js?063f:723)
I've tried messing with ES6 imports a bit but can't seem to get it to work. That one yields a different error message:
Uncaught SyntaxError: Unexpected identifier
at get_exports (tester.js?3b08:71)
at Tester.render (tester.js?3b08:41)
at eval (ReactCompositeComponent.js?063f:795)
at measureLifeCyclePerf (ReactCompositeComponent.js?063f:75)
at ReactCompositeComponentWrapper._renderValidatedComponentWithoutOwnerOrContext (ReactCompositeComponent.js?063f:794)
at ReactCompositeComponentWrapper._renderValidatedComponent (ReactCompositeComponent.js?063f:821)
at ReactCompositeComponentWrapper._updateRenderedComponent (ReactCompositeComponent.js?063f:745)
at ReactCompositeComponentWrapper._performComponentUpdate (ReactCompositeComponent.js?063f:723)
at ReactCompositeComponentWrapper.updateComponent (ReactCompositeComponent.js?063f:644)
at ReactCompositeComponentWrapper.receiveComponent (ReactCompositeComponent.js?063f:546)
The above is produced when using import moo from "moo"
, import lexer from "myLexer"
and import lexer from "myLexer.js"
with the "myLexer.js" script in the same dir as the other default grammars such as sentence.ne and arithmetic.ne.
So that brings me to the solution the two possible solutions:
Either the functionality to import a lexer is available, and I'm just not sure how to do it in the playground, or
import functionality is not available, and I'd like for support for it to be added in.
Though, at this point, it might be worth my time moving away from the playground for my development purposes. It was very useful for getting started! Thanks again! Let me know if I can provide any more info, etc. etc.
Hey! I'm the guy who made nearley, and I just stumbled onto your work here. This is amazing!
People have been asking for something like this since the beginning of time (see issues #106, #37, #68, #142, #78 on the issue tracker…). Would it be okay if I put links to nearley-playground on nearley.js.org, and also on the README?
Thanks! (And once again, this is so cool.)
Underneath each test there is a parse tree display which we have to expand one structure at a time, but I generally want to expand lots of stuff and it would be nice if there was a way to expand everything, or all children of an element, or down one level, or something faster than clicking on each triangle one at a time.
Awesome project, super useful!
MAIN -> "a":+:+:+
test with "aaaa" and add "a" one by one.
this problem caused by rendering a lot of elements to the DOM.
I think it could be fixed by limiting the outputs
to 100 item
nearley-playground/src/client/tester.js
Line 110 in c7704fb
.then(outputs => this.setState({outputs: outputs.slice(0, 100)}))
thank you 👍
Would it be possible to support Case-insensitive string literals as outlined on the nearly.js website?
cow -> "cow"i # matches CoW, COW, and so on.
(https://nearley.js.org/docs/grammar#more-syntax-tips-and-tricks)
When I try it the playground gives me a syntax error.
Hi @bijection! Playground is still lookin' fine :-)
@Hardmath123 and I were wondering if you'd thought of publishing the CodeMirror mode included here as a separate package? Might be useful for building future tools, who knows... No particular project in mind right now though!
Cheers.
You can save the grammar to a file, but you are unable to save the test cases to a file(s).
What would be nice is to allow importing/exporting a tab in the playground as a zip file where the grammar and each individual test case is contained in the zip file. In addition, it would be nice to include a nodejs console app in the zip file that would require the grammar and take zero or more test dataset names on the command line, then it would produce a pass/fail for each test case, e.g., a simple test runner. Test datasets would be plain text files.
👍 kudos for putting the playground together!!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.