ebnf2railroad
Advanced tools
Comparing version 1.9.0 to 1.10.0
100
CHANGELOG.md
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
and this project adheres to | ||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
## [1.10.0] - 2020-09-16 | ||
### Added | ||
- Support for `--dump-ast` and `--read-ast` options to allow external processing | ||
- Support for identifiers starting with an uppercase letter | ||
- Improved error reporting. Exceptions now contain a `data` element with the | ||
following: | ||
- `line` The line number of the error (starting from 1) | ||
- `pos` The position within the line of the error (starting from 1) | ||
- `expected` the types of token expected by the parser (array) | ||
- `token` the token received by the parser | ||
- Optimisation to prevent double skip lines | ||
### Security | ||
- Updated dependencies to solve security vulnerabilities | ||
### Fixed | ||
- Display of proper line number in CLI output | ||
## [1.9.0] - 2019-01-22 | ||
### Fixed | ||
- Improved detection for recursion and roots | ||
## [1.8.2] - 2019-01-21 | ||
### Changed | ||
- Updated example outputs | ||
### Fixed | ||
- Optimization issue in choice length | ||
## [1.8.1] - 2019-01-21 | ||
### Changed | ||
- Skip all optimizations with `--no-optimizations` | ||
## [1.8.0] - 2018-11-26 | ||
### Added | ||
- Dark and light color theme | ||
## [1.7.0] - 2018-11-22 | ||
### Added | ||
- Syntax diagram will wrap if sequences become very long | ||
- Split navigation bar in 3 parts. Root elements, Normal elements, | ||
Common elements | ||
- Split navigation bar in 3 parts. Root elements, Normal elements, Common | ||
elements | ||
- Added Marker of recursion in navigation list | ||
@@ -35,6 +72,9 @@ - Responsive design, mobile navigation, overall styling | ||
### Fixed | ||
- Small pretty print issues that caused weird line breaks | ||
## [1.6.0] - 2018-11-13 | ||
### Added | ||
- Formatting of text output in the document | ||
@@ -50,8 +90,10 @@ - Long sequences will wrap over multiple lines | ||
## [1.5.0] - 2018-11-10 | ||
### Added | ||
- Support to use package as library within other projects | ||
- Support for alternative characters: `|` -> `/`, `!`, `[ ]` -> `(/ /)`, | ||
`{ }` -> `(: :)` | ||
- Table of contents, showing structure in alphabet, or as | ||
hierarchy overview at the bottom. | ||
- Support for alternative characters: `|` -> `/`, `!`, `[ ]` -> `(/ /)`, `{ }` | ||
-> `(: :)` | ||
- Table of contents, showing structure in alphabet, or as hierarchy overview at | ||
the bottom. | ||
- Optimize EBNF syntax as `a | a` into `a` | ||
@@ -62,8 +104,10 @@ - Optimize EBNF syntax as `a | a, b` into `a, [ b ]` | ||
### Fixed | ||
- Closing tag for Terminals with single quotes | ||
- Issue when the chain was optimized without repeater | ||
`a, b, c, { b, c }`. | ||
- Issue when the chain was optimized without repeater `a, b, c, { b, c }`. | ||
## [1.4.0] - 2018-11-03 | ||
### Added | ||
- Optimize EBNF syntax as `[ a | b ]` in diagram as single choice with | ||
@@ -81,2 +125,3 @@ integrated skip | ||
### Fixed | ||
- Issue with optimizer in repeating elements `a, b, c, { d, b, c }`. the | ||
@@ -86,35 +131,42 @@ repetition showed `c, b` instead of `b, c` | ||
## [1.3.0] - 2018-11-02 | ||
### Added | ||
- Add support for comments within statements, that will be rendered | ||
within the diagram | ||
- Add support for comments within statements, that will be rendered within the | ||
diagram | ||
- Option `--title` to add a title to the output document | ||
- Show different start/end indicators if diagram is 'complex' (refers to | ||
other definitions) | ||
- Better optimization of repeating elements. `a, b, c, { d, b, c }` will | ||
display `a` followed by a loop containing `b, c` with `d` as repeater. | ||
- Show different start/end indicators if diagram is 'complex' (refers to other | ||
definitions) | ||
- Better optimization of repeating elements. `a, b, c, { d, b, c }` will display | ||
`a` followed by a loop containing `b, c` with `d` as repeater. | ||
- Extra example file, based on json.org | ||
### Fixed | ||
- Text dedenting issue in comments before sending comments to markdown parser | ||
## [1.2.0] - 2018-11-01 | ||
### Added | ||
- Show validation warnings for duplicate declarations | ||
- Show validation warnings for missing references | ||
- Option `--validate` to exit with status code 2 if document has | ||
warnings | ||
- Option `--validate` to exit with status code 2 if document has warnings | ||
- Option `--quiet` to suppress output to console | ||
- Optimize EBNF syntax as `( a ), { a }` in diagram as `a+` (one or more) | ||
- Optimize EBNF syntax as `a | { b }` in diagram as choice with "skip", | ||
"a", or one or more "b" | ||
- Optimize EBNF syntax as `a | [ b ]` in diagram as choice with "skip", | ||
"a", or "b" | ||
- Optimize EBNF syntax as `a | { b }` in diagram as choice with "skip", "a", or | ||
one or more "b" | ||
- Optimize EBNF syntax as `a | [ b ]` in diagram as choice with "skip", "a", or | ||
"b" | ||
### Changed | ||
- Long choice lists are now spread over multiple columns, if the | ||
length exceeds 10. | ||
- Long choice lists are now spread over multiple columns, if the length | ||
exceeds 10. | ||
- Updated styling of document | ||
## [1.1.0] - 2018-10-30 | ||
### Added | ||
- `--target` option to specify output file | ||
@@ -131,5 +183,7 @@ - Parse and render EBNF comments as markdown | ||
## [1.0.0] - 2018-10-29 | ||
### Added | ||
- Parser to parse ISO/IEC 14977 EBNF files (limited support only) | ||
- HTML output file based on filename of input file | ||
- list definitions that reference another defintion (referenced From) |
{ | ||
"name": "ebnf2railroad", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "EBNF to Railroad diagram", | ||
@@ -35,13 +35,16 @@ "keywords": [ | ||
"railroad-diagrams": "https://github.com/tabatkins/railroad-diagrams#e9b1a12", | ||
"showdown": "^1.8.7" | ||
"showdown": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"eslint": "^5.8.0", | ||
"eslint-plugin-mocha": "^5.2.0", | ||
"eslint": "^7.0.0", | ||
"eslint-plugin-mocha": "^8.0.0", | ||
"eslint-plugin-prettier": "^3.0.0", | ||
"jison": "^0.4.18", | ||
"mocha": "^5.2.0", | ||
"mocha": "^8.0.0", | ||
"prettier": "^1.14.3" | ||
}, | ||
"resolutions": { | ||
"minimist": "^1.2.3" | ||
} | ||
} |
@@ -9,4 +9,4 @@ # EBNF 2 RailRoad | ||
A command line tool to create great documentation including railroad | ||
diagrams based on the ISO/IEC 14977 specification | ||
A command line tool to create great documentation including railroad diagrams | ||
based on the ISO/IEC 14977 specification | ||
@@ -45,2 +45,4 @@ ## Features | ||
--no-text-formatting does not format the output text version (becomes single line) | ||
--dump-ast dump EBNF file AST to target destination for further processing | ||
--read-ast input file is in the AST format | ||
-h, --help output usage information | ||
@@ -71,6 +73,9 @@ ``` | ||
Check the examples folder for an example input file and the generated result page. | ||
Check the examples folder for an example input file and the generated result | ||
page. | ||
- EBNF `ebnf2railroad examples/ebnf.ebnf --title EBNF` [View online][example-ebnf] | ||
- JSON `ebnf2railroad examples/json.ebnf --title JSON` [View online][example-json] | ||
- EBNF `ebnf2railroad examples/ebnf.ebnf --title EBNF` [View | ||
online][example-ebnf] | ||
- JSON `ebnf2railroad examples/json.ebnf --title JSON` [View | ||
online][example-json] | ||
@@ -93,11 +98,15 @@ ## Usage as module | ||
Thanks for your interest in contributing! There are many ways to contribute to this project. [Get started here](CONTRIBUTING.md) | ||
Thanks for your interest in contributing! There are many ways to contribute to | ||
this project. [Get started here](CONTRIBUTING.md) | ||
## Acknowledgements | ||
- All railroad diagrams are generated through: https://github.com/tabatkins/railroad-diagrams | ||
- All railroad diagrams are generated through: | ||
https://github.com/tabatkins/railroad-diagrams | ||
- The EBNF parser is generated by http://zaa.ch/jison/ | ||
- All markdown is parsed with http://showdownjs.com/ | ||
[example-ebnf]: http://htmlpreview.github.io/?https://github.com/matthijsgroen/ebnf2railroad/blob/master/examples/ebnf.html | ||
[example-json]: http://htmlpreview.github.io/?https://github.com/matthijsgroen/ebnf2railroad/blob/master/examples/json.html | ||
[example-ebnf]: | ||
http://htmlpreview.github.io/?https://github.com/matthijsgroen/ebnf2railroad/blob/master/examples/ebnf.html | ||
[example-json]: | ||
http://htmlpreview.github.io/?https://github.com/matthijsgroen/ebnf2railroad/blob/master/examples/json.html |
@@ -5,3 +5,3 @@ const program = require("commander"); | ||
const writeFile = util.promisify(require("fs").writeFile); | ||
const { parse } = require("./ebnf-parser"); | ||
const { parseEbnf } = require("./main"); | ||
const { createDocumentation, validateEbnf } = require("./report-builder"); | ||
@@ -29,3 +29,5 @@ const { version } = require("../package.json"); | ||
"does not format the output text version (becomes single line)" | ||
); | ||
) | ||
.option("--dump-ast", "dump EBNF file AST for further processing") | ||
.option("--read-ast", "input file is in the AST format"); | ||
@@ -43,6 +45,10 @@ async function run(args) { | ||
const outputError = text => allowOutput && process.stderr.write(text + "\n"); | ||
const errLocation = struct => | ||
struct.pos !== undefined | ||
? `${struct.line}:${struct.pos}` | ||
: `${struct.line}`; | ||
const outputErrorStruct = struct => | ||
allowOutput && | ||
process.stderr.write( | ||
`${struct.type} on line ${struct.line}: ${struct.message}\n` | ||
`${struct.type} on line ${errLocation(struct)}: ${struct.message}\n` | ||
); | ||
@@ -64,5 +70,13 @@ | ||
const ast = parse(ebnf); | ||
const ast = !program.readAst ? parseEbnf(ebnf) : JSON.parse(ebnf); | ||
const warnings = validateEbnf(ast); | ||
if (program.dumpAst) { | ||
const defaultDumpFilename = basename + ".json"; | ||
const dumpFilename = | ||
program.target === true ? defaultDumpFilename : program.target; | ||
await writeFile(dumpFilename, JSON.stringify(ast), "utf8"); | ||
output(`🧬 AST dumped at ${dumpFilename}`); | ||
return; | ||
} | ||
warnings.length > 0 && | ||
@@ -83,3 +97,2 @@ allowOutput && | ||
} | ||
if (targetFilename) { | ||
@@ -92,3 +105,2 @@ const report = createDocumentation(ast, { | ||
await writeFile(targetFilename, report, "utf8"); | ||
output(`📜 Document created at ${targetFilename}`); | ||
@@ -98,6 +110,7 @@ } | ||
} catch (e) { | ||
if (e.hash) { | ||
const { line, expected, token } = e.hash; | ||
if (e.data) { | ||
const { line, expected, token, pos } = e.data; | ||
outputErrorStruct({ | ||
line, | ||
pos, | ||
type: "Parse error", | ||
@@ -114,5 +127,4 @@ message: `Expected ${expected}, got ${token}` | ||
} | ||
module.exports = { | ||
run | ||
}; |
@@ -87,3 +87,3 @@ /* parser generated by jison 0.4.18 */ | ||
case 1: | ||
return $$[$0-1]; | ||
return $$[$0-1]; | ||
break; | ||
@@ -127,3 +127,3 @@ case 2: | ||
case 19: | ||
this.$ = { nonTerminal: $$[$0].trim() }; | ||
this.$ = { nonTerminal: $$[$0].trim() }; | ||
break; | ||
@@ -669,8 +669,10 @@ case 20: | ||
break; | ||
case 26: return 5; | ||
case 26: return 5; | ||
break; | ||
case 27: return yy_.yytext; | ||
break; | ||
} | ||
}, | ||
rules: [/^(?:\s+)/,/^(?:\(\*([^*]|\*(?=[^)]))*\*\))/,/^(?:[a-z][A-Za-z0-9 ]*)/,/^(?:[0-9]+)/,/^(?:\(\/)/,/^(?:\/\))/,/^(?:\(:)/,/^(?::\))/,/^(?:\*)/,/^(?:=)/,/^(?:;)/,/^(?:\.)/,/^(?:,)/,/^(?:\|)/,/^(?:\/)/,/^(?:!)/,/^(?:-)/,/^(?:\{)/,/^(?:\})/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:"[^"]+")/,/^(?:'[^']+')/,/^(?:\?[^\?]+\?)/,/^(?:$)/], | ||
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26],"inclusive":true}} | ||
rules: [/^(?:\s+)/,/^(?:\(\*([^*]|\*(?=[^)]))*\*\))/,/^(?:[A-Za-z][A-Za-z0-9 ]*)/,/^(?:[0-9]+)/,/^(?:\(\/)/,/^(?:\/\))/,/^(?:\(:)/,/^(?::\))/,/^(?:\*)/,/^(?:=)/,/^(?:;)/,/^(?:\.)/,/^(?:,)/,/^(?:\|)/,/^(?:\/)/,/^(?:!)/,/^(?:-)/,/^(?:\{)/,/^(?:\})/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:"[^"]+")/,/^(?:'[^']+')/,/^(?:\?[^\?]+\?)/,/^(?:$)/,/^(?:.*)/], | ||
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27],"inclusive":true}} | ||
}); | ||
@@ -677,0 +679,0 @@ return lexer; |
@@ -14,5 +14,23 @@ const { parse } = require("./ebnf-parser"); | ||
const improveErrors = parser => input => { | ||
try { | ||
return parser(input); | ||
} catch (e) { | ||
const error = new Error(e.message); | ||
if (e.hash) { | ||
error.hash = e.hash; // backwards compatibility | ||
error.data = { | ||
expected: e.hash.expected, | ||
token: `'${e.hash.token[0]}'`, | ||
line: e.hash.line + 1, | ||
pos: e.hash.loc.last_column + 1 | ||
}; | ||
} | ||
throw error; | ||
} | ||
}; | ||
module.exports = { | ||
version, | ||
parseEbnf: parse, | ||
parseEbnf: improveErrors(parse), | ||
createDocumentation, | ||
@@ -19,0 +37,0 @@ documentStyle, |
@@ -295,8 +295,10 @@ const skipFirst = list => | ||
}); | ||
} else { | ||
return { | ||
...production, | ||
optional: optimizeProduction(production.optional) | ||
}; | ||
} | ||
if (production.optional.repetition || production.optional.optional) { | ||
return optimizeProduction(production.optional); | ||
} | ||
return { | ||
...production, | ||
optional: optimizeProduction(production.optional) | ||
}; | ||
} | ||
@@ -303,0 +305,0 @@ if (production.group) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89613
2344
109
Updatedshowdown@^1.0.0