My name is Christopher Diggins.
I am designing and implementing the Plato programming language.
Myna Parsing Library
Home Page: https://cdiggins.github.io/myna-parser
License: MIT License
My name is Christopher Diggins.
I am designing and implementing the Plato programming language.
From the readme:
The JavaScript library that comes closest to what I was looking for in terms of API is probably Parsimmon. It did not satisfy my particular needs for the project I am working on
As another Parsing Library author (Chevrotain) I'm interested in what requirements Parsimmon did
not satisfy?
Preamble: I like this library's API. I use both Chevrotain and Parsimmon for parsing. This is an interesting new library.
I'm having the same trouble I had with Chevrotain. Both projects don't say how to use them to parse in their README. I've looked thru the grammer/tools and I still can't quite figure out what it is you expect us to do.
What I'm looking for is how to do this:
// get the reusable parser created with a grammar
var parser = require('./getMyAwesomeMynaParser')
// export a parse function which uses it
module.exports = function parse(input) {
return parser.parse(input)
// or, use some top-level rule
return parser.topRule(input)
}
Also, when I figure that out, I'm thinking it'll provide an AST. Or, is it possible to have the parser generate something as it parses similar to Parsimmon's map()
and others to generate a value?
The next big thing for Myna will be partial recovery from errors, so that multiple errors can be detected in the code. See: http://duriansoftware.com/joe/Constructing-human-grade-parsers.html.
Basically I see special rules to indicate where to advance to in the case of an error, and returning an array of errors from a parse (empty array indicating success).
A grammar I'm developing seems to be throwing a ParserError, although I'm having a lot of trouble finding out exactly where the error is happening. To make matters more complicated, I seem to be unable to see the error messages that are coming out of the ParserError. It seems like the message
parameter is not being propogated to the error object or accessible in the console.
Here's a simple test case.
> try { throw new Error('123') } catch (e) { console.error(e.toString()) }
Error: 123
undefined
> try { throw new ParserError('123') } catch (e) { console.error(e.toString()) }
Error
Explainjs is not a dependency. NPM must have updated the package.json when I was trying out explainjs.
Should there be a way to declare a keyword (or char + seq) as case insensitive?
Something like:
this.exponent = m.seq(m.char("e").ignoreCase, this.plusOrMinus.opt, m.digits);
this.null = m.keyword("null").ignoreCase.ast;
How would you create grammar_markdown.js in TypeScript?
I'm setting up an AST evaluator and instead of matching rules by their name
I am using their id
in the hopes it'll be faster to do number comparison than string comparison.
It's working except for the one delayed rule created via myna.delay(function() { return myna.choice(...) })
.
When I run myna.parse(rule, input)
the ID of the delayed node is brand new. The first one after the last of my rule's IDs.
And, if I run the parse()
repeatedly then the ID changes each time. It's growing by 10. So, I'm wondering what's going on in parse()
which creates 10 new rules. Perhaps that one rule is being used 10 times?
I'm thinking the original ID should remain the same. Maybe not for Delay.
Ah-hah. I looked in the JS source and found the M.choice()
I'm using in the delayed rule creates a new Choice
rule. So, it's doing this every time the delayed rule is used during a parse()
.
Do you think it's possible to reuse the ID from the "delayed rule" in the rule created when the deferred execution is resolved? In what I'm doing, I mean the myna.choice()
would create the new Choice rule and use the ID from its wrapping Delay rule.
Wait, does it call that every time the rule is encountered or does it resolve the first time?
It looks like the delay is created with a function which is passed to the Delay constructor and then reused in parseImplementation() like this.fn().parse(p)
. So, it seems like it re-resolves it every time.
So, what do you think about making it capable of resolving only once and reusing the id
assigned to the Delay rule which wrapped it?
There are two small mistakes in the sample code in readme.md.
var g = new function()
{
var delimiter = ","; // need to define delimiter first
this.textdata = m.notChar('\n\r"' + delimiter);
...
}
console.log(parser(input));
parser
, not parse
.I see much usage of the newkeyword.
I am uncertain but it appears as though it may also be used in hot spots( parser runtime) in the code and not only in one time initial definitions?
if that is indeed the case I suggest you try avoiding initializing class instances at parser runtime.
Plain objects ({}) if sufficient would be much faster.
This is a minor thing but conditions such as:
if (!this.createsAstNode)
Will take longer than a more precise condition:
if (this.createsAstNode === false)
If these kind of conditions appear in enough hot spots in the code base
you may be able to squeeze a a tiny bit of extra performance.
Myna module functions don't have return types declared. This limits the effectiveness of TypeScript real-time type checking.
I'm aware that library is written in typescript itself, but there's no typescript declaration file present to be used as an npm @types module.
You just need to append the declaration flag as true in tsconfig.json.
Also, the npm module contains a lot of unnecessary files such as docs files and website files. Even test files aren't required there.
Running require("myna-parser") in Runkit failed. I discovered that the way I was exporting the module was incorrect.
In Myna.ts Instead of:
declare let module;
if (typeof module === "object" && module.exports)
module.exports.Myna = Myna;
I should have written:
declare let module;
if (typeof module === "object" && module.exports)
module.exports = Myna;
Looks like Myna only runs much slower on Chrome Canary 61
(which includes the new TurboFan V8 compiler and Ignition interpreter).
I don't know if this is a bug in Chrome that will be fixed by the time an official version of Chrome is released or if it is a a real issue.
Just an heads up...
Also Note:
There are some minor syntax errors in the README's example code.
It would be helpful to have an test harness and leverage qunit more effectively.
I propose using Karma and the QUnit karma plugin.
Hello, I don't want to capture sequence, when there are no whitespaces: bla+something+bla
, I only want to capture, when there are whitespaces: bla +something+ bla
. I am having trouble getting this to work.
Catching everything between +
is straight forward: m.seq('+', this.plainTextEmphasis, '+').ast
, but I wan to parse it only when ther is a space/empty line before and after +
.
I've tried just adding space char in the sequence before +
, but that doesn't seem to work:
m.seq(' ', '+', this.plainTextEmphasis, '+', ' ').ast
I've also tried replacing whitespace with ws
, atWs
etc., but that didn't help either.
Does anyone know, how to do it properly?
Reproduce with this snippet:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
// will cause "Uncaught ReferenceError: exports is not defined"
<script src="https://unpkg.com/myna-parser/myna.js"></script>
</body>
</html>
Related to:
https://github.com/cdiggins/myna-parser/blob/master/myna.js#L1298
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.