Code Monkey home page Code Monkey logo

bnf-parser's Introduction

metrics

bnf-parser's People

Contributors

ajanibilby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

pauldraper

bnf-parser's Issues

+Show bnf stack trace on error

Include a list of strings within BNF_SyntaxError for the current BNF term that failed, and what terms it was "called" from. This can then be used to print out better syntax errors, allowing you to more easily debug BNFs due to the fact you can ensure that it is attempting to match the fail point with the correct term.

Cannot read properties of undefined (reading `'getReach'`) since v3.1.2

Hello!

bnf-parser 3.1.2 seems to have introduced a regression. We're getting the following crash when calling parse:

TypeError: Cannot read properties of undefined (reading 'getReach')
      at SyntaxNode.getReach (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/syntax.js:70:50)
      at Sequence.parseSingle (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/parser.js:347:32)
      at Sequence.parse (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/parser.js:271:28)
      at Sequence.parse (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/parser.js:323:25)
      at Rule.parse (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/parser.js:389:28)
      at Parser.parse (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/bnf-parser/bin/parser.js:425:29)
      at parseAttributeSyntaxInternal (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/utils/attribute-syntax.js:97:34)
      at memoized (/Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/lodash/memoize.js:62:23)
      at /Users/jeffrey.fowler/development/sequelize-v7-alias-bug/node_modules/@sequelize/core/lib/dialects/abstract/where-sql-builder.js:215:88
      at Array.map (<anonymous>)

This is the BNF in question: https://github.com/sequelize/sequelize/blob/e6690cdf27980d57be1bb9f138b04124775b153b/packages/core/src/utils/attribute-syntax.ts#L56-L87
attributeParser.parse from the above code fails when we feed something like 'prop' into it.

Do you know if we're doing something incorrectly or if this is an actual bug?

Related threads: sequelize/sequelize#15749, sequelize/sequelize#15792

Wasm-Parser: Upper case ranges not working

With the new wasm parser upper case ranges don't appear to work at all

This example will always fail

program ::= letter+ ;
letter ::= "a"->"z" | "A"->"Z" ;
snakeCase

Error with default BNF example

Hello,

Running through the homepage example, I use the following BNF:

program ::= %w* statement+ ;
block   ::= %("block" w+) ...name %(w* "{" w*) seq_stmt* %("}" w*) ;

And run:

npx bnf-compile ./syntax.bnf

And I get:

Found: ./syntax.bnf

 - Compiling syntax
   Encoding Parser
Parse Error: Unknown term name "w" (1:14) -> (1:16)

Not getting correct end bytes for repetitions of a select

Repetition of a select not working correctly:

# input: $abcHello $abc World
program ::= ("$abc" | !"$"+)+ ;
{
  "root": {
    "type": "program",
    "start": 0,
    "end": 0,
    "count": 1,
    "value": [
      {
        "type": "(...)+",
        "start": 0,
        "end": 0,
        "count": 4,
        "value": [
          {
            "type": "literal",
            "start": 0,
            "end": 4,
            "count": 4,
            "value": "$abc",
            "ref": {}
          }, {}, {},
          {
            "type": "literal",
            "start": 14,
            "end": 20,
            "count": 6,
            "value": " World",
            "ref": { }
          }
        ],
        "ref": {}
      }
    ],
    "ref": {},
  "reachBytes": 20,
  "reach": {
    "line": 1,
    "col": 21,
    "index": 20
  },
  "isPartial": true
}

This leads also to things being incorrectly labeled as partial, because reachBytes !== end

Repetition of sequences work correctly:

# input: $abcHello $abc World
program ::= ("$abc" !"$"+)+ ;

Unparse

Very cool project!

What would be also nice is to have reverse parse/serialize functionality.

Should be possible without ambiguity (choose fewest possible repetitions).

Version 4.0 Release Checklist

  • All issues related to release closed
  • Documentation
    • CLI usage
    • Shared Artifact API outline
    • Bnf artifact API outline
    • Whole library API outline

Parse error due to select option order

// OK
let result = BNF.parse(`program ::= "aa" | "a";`);
let tree = Compile(result);
let syntax = tree.parse("aa");
console.log("result", result, "syntax", syntax);
// Not OK
let result = BNF.parse(`program ::= "a" | "aa";`);
let tree = Compile(result);
let syntax = tree.parse("aa");
console.log("result", result, "syntax", syntax);

Edit by @AjaniBilby:
Answer

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.