diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b4af945 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "editor.insertSpaces": false, + "[markdown]": { + "files.trimTrailingWhitespace": false + } +} \ No newline at end of file diff --git a/changelog.md b/changelog.md index d05f460..0e6a1b4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Changelog +## Version 3.1.2 +### Fixes: + - [x] Updated readme to clarify behaviour of select statements + ## Version 3.1.1 ### Fixes: - [x] Incorrect referencing for syntax errors. diff --git a/package.json b/package.json index e8da52b..f92955f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bnf-parser", - "version": "3.1.1", + "version": "3.1.2", "description": "Deterministic BNF compiler/parser", "main": "./bin/index.js", "scripts": { diff --git a/readme.md b/readme.md index 655ceb5..fee28f2 100644 --- a/readme.md +++ b/readme.md @@ -28,7 +28,7 @@ - [Range](#range) - [Literal](#literal) -A simple library for generate syntax pasers based BNF syntax descriptions. +A simple library for generate syntax pasers based BNF syntax descriptions. There are a few changes from standard BNF forms to help produce cleaner syntax tree outputs that BNFs normally provide. # Example @@ -126,7 +126,7 @@ The omit character goes in front af a single term, and must be the front most op !term ``` -This operator must be between two single length constants, this will accept all characters within the range of the two bounds (inclusive). +This operator must be between two single length constants, this will accept all characters within the range of the two bounds (inclusive). ### Range `->` @@ -135,7 +135,7 @@ This operator must be between two single length constants, this will accept all "a"->"z"* # will consume as many characters as are in the range ``` -This operator must be between two single length constants, this will accept all characters within the range of the two bounds (inclusive). Until the repetition count is reached. +This operator must be between two single length constants, this will accept all characters within the range of the two bounds (inclusive). Until the repetition count is reached. The first operand must have no repetitions, however the repetition markers on the last operand will apply to the whole group. ## Imports @@ -154,7 +154,7 @@ Is initialised with a built syntax tree. Once initialized it can be given input ```ts class Parser { - constructor(blob: any) + constructor(blob: any) // Attempts to parse a language into a syntax tree parse( @@ -300,6 +300,14 @@ If there is a repetition marker such as `name+` there will be an extra noded add Will resolve as the syntax tree of the first matching option. For instance if you have the select statement `variable | number`, if the parser matches a variable it would be the same as having a `variable` at that point in the sequence. +> The select statement will always consume the first valid option, and your should order your select statements accordingly +> i.e. +> ```bnf +> program ::= "a" | "aa" ; +> ``` +> Giving this program "aa" will fail, as it will consume the single "a", then since there is no repetition the program will end leaving the second "a" unconsumed. As the syntax did not parse the whole string, this is considered an error. +> See [Parser](#parser) for information on how to allow partial matches + ## Omit Any omit statement within a sequence will be removed, and then looking at the outputted syntax tree it is like they never existed, however they are still critical to a successful match. In the case that they are within a select, they will still be visible with `.type` of `omit`, with no child nodes.