UNPKG

2.83 kBJavaScriptView Raw
1"use strict";
2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 return new (P || (P = Promise))(function (resolve, reject) {
5 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 step((generator = generator.apply(thisArg, _arguments || [])).next());
9 });
10};
11Object.defineProperty(exports, "__esModule", { value: true });
12const Builder_1 = require("./Builder");
13/*@internal*/
14class NonTerminal extends Builder_1.default {
15 constructor(spec, node, namespace) {
16 super(spec, node);
17 this.params = node.getAttribute('params');
18 this.optional = node.hasAttribute('optional');
19 this.namespace = namespace;
20 }
21 static enter({ spec, node, clauseStack }) {
22 return __awaiter(this, void 0, void 0, function* () {
23 const clause = clauseStack[clauseStack.length - 1];
24 const namespace = clause ? clause.namespace : spec.namespace;
25 const nt = new NonTerminal(spec, node, namespace);
26 spec._ntRefs.push(nt);
27 if (spec.opts.lintSpec && spec.locate(node) != null && !node.hasAttribute('example')) {
28 const clause = clauseStack[clauseStack.length - 1];
29 const namespace = clause ? clause.namespace : spec.namespace;
30 spec._ntStringRefs = spec._ntStringRefs.concat({
31 name: node.textContent,
32 loc: { line: 1, column: 1 },
33 node,
34 namespace,
35 });
36 }
37 });
38 }
39 build() {
40 const name = this.node.textContent;
41 // const id = 'prod-' + name;
42 const entry = this.spec.biblio.byProductionName(name, this.namespace);
43 if (entry) {
44 this.node.innerHTML = '<a href="' + entry.location + '#' + entry.id + '">' + name + '</a>';
45 this.entry = entry;
46 }
47 else {
48 this.node.innerHTML = name;
49 }
50 let modifiers = '';
51 if (this.params) {
52 modifiers += '<emu-params>[' + this.params + ']</emu-params>';
53 }
54 if (this.optional) {
55 modifiers += '<emu-opt>opt</emu-opt>';
56 }
57 if (modifiers.length > 0) {
58 const el = this.spec.doc.createElement('emu-mods');
59 el.innerHTML = modifiers;
60 this.node.appendChild(el);
61 }
62 }
63}
64exports.default = NonTerminal;
65NonTerminal.elements = ['EMU-NT'];