ajanibilby / bnf-parser Goto Github PK
View Code? Open in Web Editor NEWDeterministic BNF compiler/parser
Home Page: http://bnf-parser.ajanibilby.com/
License: MIT License
Deterministic BNF compiler/parser
Home Page: http://bnf-parser.ajanibilby.com/
License: MIT License
The Syntax tab is broken for docs.
It should go to https://bnf-parser.ajanibilby.com/syntax but it doesn't.
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.
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
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
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)
The documentation says that hex escapes work like "\x6b"
but the actually behavior is "x6b"
.
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" !"$"+)+ ;
Very cool project!
What would be also nice is to have reverse parse/serialize functionality.
Should be possible without ambiguity (choose fewest possible repetitions).
// 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
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.