ebnf-railroad-visualizer
Version:
A web-based EBNF railroad diagram visualizer
55 lines • 1.81 kB
JavaScript
/*
* This work © 2024 by Alexander Voglsperger is licensed under CC BY 4.0.
* To view a copy of this license, see the provided LICENSE file or visit https://creativecommons.org/licenses/by/4.0/
*/
import { Sym } from '../scannerparser/Sym.js';
export var FactorType;
(function (FactorType) {
FactorType[FactorType["Identifier"] = 0] = "Identifier";
FactorType[FactorType["Literal"] = 1] = "Literal";
FactorType[FactorType["Group"] = 2] = "Group";
FactorType[FactorType["Repetition"] = 3] = "Repetition";
FactorType[FactorType["Optionally"] = 4] = "Optionally";
})(FactorType || (FactorType = {}));
/**
* A factor is a single symbol or a group of symbols defined as:
*
* ```plaintext
* FACTOR = IDENTIFIER
* | LITERAL
* | "(" EXPRESSION ")"
* | "{" EXPRESSION "}
* | "[" EXPRESSION "]" .
* ```
*/
export class Factor extends Sym {
constructor(type, value, id = -1) {
let strRepr;
switch (type) {
case FactorType.Group:
strRepr = `(${value})`;
break;
case FactorType.Repetition:
strRepr = `{${value}}`;
break;
case FactorType.Optionally:
strRepr = `[${value}]`;
break;
default:
strRepr = value.toString();
break;
}
super(strRepr, id);
this.type = type;
this.value = value;
}
toString() {
switch (this.type) {
case FactorType.Group: return `(${this.value})`;
case FactorType.Repetition: return `{${this.value}}`;
case FactorType.Optionally: return `[${this.value}]`;
default: return this.value.toString();
}
}
}
//# sourceMappingURL=Factor.js.map