Giter Club home page Giter Club logo

myna-parser's Introduction

myna-parser's People

Contributors

bd82 avatar cdiggins avatar hypercubed avatar ninoseki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

myna-parser's Issues

Question on requirements for the programing language you are working on.

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?

How to *use* ?

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?

ParserError messages don't seem to be propogated

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

Case insensitive keywords?

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;

delay() rule ID number changes each time

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?

2 small mistakes in the sample code in readme.md

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));
  1. the variable delimiter is not defined;
  2. last line should be parser, not parse.

Possible performance improvements

Class instances avoidance

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.

Specific boolean conditions.

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.

typescript declaration file absent

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.

Myna module improperly exported

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;

Possible performance degradation under Chrome Canary 61

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:

  • Most other parsing libraries get a speed boost in Chrome Canary 61.
  • Screen shot (I get about 500 ops/Second on Chrome 58)
    capture

Question: how to check in sequence if there is a whitespace + symbol

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.