ebnf2railroad
Advanced tools
Comparing version 1.8.0 to 1.8.1
@@ -7,2 +7,6 @@ # Changelog | ||
## [1.8.1] - 2019-01-21 | ||
### Changed | ||
- Skip all optimizations with `--no-optimizations` | ||
## [1.8.0] - 2018-11-26 | ||
@@ -9,0 +13,0 @@ ### Added |
{ | ||
"name": "ebnf2railroad", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"description": "EBNF to Railroad diagram", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -85,9 +85,10 @@ const { | ||
const SHRINK_CHOICE = 10; | ||
const MAX_CHOICE_LENGTH = 10; | ||
const MAX_SEQUENCE_LENGTH = 45; | ||
const productionToDiagram = production => { | ||
const productionToDiagram = (production, options) => { | ||
if (production.identifier) { | ||
return production.complex | ||
? ComplexDiagram(productionToDiagram(production.definition)) | ||
: Diagram(productionToDiagram(production.definition)); | ||
? ComplexDiagram(productionToDiagram(production.definition, options)) | ||
: Diagram(productionToDiagram(production.definition, options)); | ||
} | ||
@@ -112,9 +113,11 @@ if (production.terminal) { | ||
const makeChoice = items => new Choice(0, items); | ||
const options = production.choice.map(productionToDiagram); | ||
const choiceOptions = production.choice.map(elem => | ||
productionToDiagram(elem, options) | ||
); | ||
const choiceLists = []; | ||
while (options.length > SHRINK_CHOICE) { | ||
const subList = options.splice(0, SHRINK_CHOICE); | ||
while (choiceOptions.length > options.shrinkChoiceAt) { | ||
const subList = choiceOptions.splice(0, options.shrinkChoiceAt); | ||
choiceLists.push(makeChoice(subList)); | ||
} | ||
choiceLists.push(makeChoice(options)); | ||
choiceLists.push(makeChoice(choiceOptions)); | ||
return choiceLists.length > 1 | ||
@@ -126,3 +129,3 @@ ? HorizontalChoice(...choiceLists) | ||
const sequenceLength = determineDiagramSequenceLength(production); | ||
if (sequenceLength > 45) { | ||
if (sequenceLength > options.maxSequenceLength) { | ||
const subSequences = production.sequence | ||
@@ -140,3 +143,3 @@ .reduce( | ||
if ( | ||
currentLength + remainingLength > 40 && | ||
currentLength + remainingLength > options.maxSequenceLength - 5 && | ||
currentLength >= 25 && | ||
@@ -154,3 +157,5 @@ remainingLength > 10 | ||
...subSequences.map(subSequence => | ||
Sequence(...subSequence.map(productionToDiagram)) | ||
Sequence( | ||
...subSequence.map(elem => productionToDiagram(elem, options)) | ||
) | ||
) | ||
@@ -160,3 +165,5 @@ ); | ||
return Sequence(...production.sequence.map(productionToDiagram)); | ||
return Sequence( | ||
...production.sequence.map(elem => productionToDiagram(elem, options)) | ||
); | ||
} | ||
@@ -167,3 +174,3 @@ if (production.repetition && production.skippable === true) { | ||
Skip(), | ||
OneOrMore(productionToDiagram(production.repetition)) | ||
OneOrMore(productionToDiagram(production.repetition, options)) | ||
); | ||
@@ -174,10 +181,10 @@ } | ||
? OneOrMore( | ||
productionToDiagram(production.repetition), | ||
productionToDiagram(production.repeater) | ||
productionToDiagram(production.repetition, options), | ||
productionToDiagram(production.repeater, options) | ||
) | ||
: OneOrMore(productionToDiagram(production.repetition)); | ||
: OneOrMore(productionToDiagram(production.repetition, options)); | ||
} | ||
if (production.repetition && production.amount !== undefined) { | ||
return OneOrMore( | ||
productionToDiagram(production.repetition), | ||
productionToDiagram(production.repetition, options), | ||
Comment(`${production.amount} ×`, {}) | ||
@@ -187,3 +194,3 @@ ); | ||
if (production.optional) { | ||
return Choice(1, Skip(), productionToDiagram(production.optional)); | ||
return Choice(1, Skip(), productionToDiagram(production.optional, options)); | ||
} | ||
@@ -193,3 +200,3 @@ if (production.comment) { | ||
? Sequence( | ||
productionToDiagram(production.group), | ||
productionToDiagram(production.group, options), | ||
Comment(production.comment, {}) | ||
@@ -200,3 +207,3 @@ ) | ||
if (production.group) { | ||
return productionToDiagram(production.group); | ||
return productionToDiagram(production.group, options); | ||
} | ||
@@ -262,6 +269,16 @@ if (production.exceptNonTerminal) { | ||
const diagram = productionToDiagram({ | ||
...renderProduction, | ||
complex: outgoingReferences.length > 0 | ||
}); | ||
const diagram = productionToDiagram( | ||
{ | ||
...renderProduction, | ||
complex: outgoingReferences.length > 0 | ||
}, | ||
{ | ||
maxChoiceLength: options.optimizeDiagrams | ||
? MAX_CHOICE_LENGTH | ||
: Infinity, | ||
maxSequenceLength: options.optimizeDiagrams | ||
? MAX_SEQUENCE_LENGTH | ||
: Infinity | ||
} | ||
); | ||
return ebnfTemplate({ | ||
@@ -268,0 +285,0 @@ identifier: production.identifier, |
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
87302
2310