UNPKG

1.11 kBJavaScriptView Raw
1import Expression from './expression';
2import RRText from '../ui/rrtext';
3import GrammarToRRDiagram from './grammartorrdiagram';
4import RRElement from '../ui/rrelement';
5import GrammarToBNF from './grammartobnf';
6
7export default class SpecialSequence extends Expression {
8
9 /**
10 * @param {string} text
11 */
12 constructor(text) {
13 super();
14 this.text = text;
15 }
16
17 /**
18 * @param {GrammarToRRDiagram} grammarToRRDiagram
19 * @return {RRElement}
20 */
21 toRRElement(grammarToRRDiagram) {
22 return new RRText(RRText.Type.SPECIAL_SEQUENCE, this.text, null);
23 }
24
25 /**
26 * @param {GrammarToBNF} grammarToBNF
27 * @param {string[]} sb
28 * @param {boolean} isNested
29 */
30 toBNF(grammarToBNF, sb, isNested) {
31 sb.push("(? ");
32 sb.push(this.text);
33 sb.push(" ?)");
34 }
35
36 /**
37 * @param {*} o
38 * @return {boolean}
39 */
40 equals(o) {
41 if(!(o instanceof SpecialSequence)) {
42 return false;
43 }
44 return this.text == o.text;
45 }
46
47}