apg-js-examples
Version:
Examples of using the suite of apg-js applications and libraries.
85 lines (76 loc) • 3.01 kB
JavaScript
// copyright: Copyright (c) 2024 Lowell D. Thomas, all rights reserved<br>
// license: BSD-2-Clause (https://opensource.org/licenses/BSD-2-Clause)<br>
//
// Generated by apg-js, Version 4.4.0 [apg-js](https://github.com/ldthomas/apg-js)
module.exports = function grammar(){
// ```
// SUMMARY
// rules = 5
// udts = 0
// opcodes = 14
// --- ABNF original opcodes
// ALT = 0
// CAT = 1
// REP = 3
// RNM = 6
// TLS = 3
// TBS = 0
// TRG = 1
// --- SABNF superset opcodes
// UDT = 0
// AND = 0
// NOT = 0
// BKA = 0
// BKN = 0
// BKR = 0
// ABG = 0
// AEN = 0
// characters = [40 - 57]
// ```
/* OBJECT IDENTIFIER (for internal parser use) */
this.grammarObject = 'grammarObject';
/* RULES */
this.rules = [];
this.rules[0] = { name: 'phone-number', lower: 'phone-number', index: 0, isBkr: false };
this.rules[1] = { name: 'area-code', lower: 'area-code', index: 1, isBkr: false };
this.rules[2] = { name: 'office', lower: 'office', index: 2, isBkr: false };
this.rules[3] = { name: 'subscriber', lower: 'subscriber', index: 3, isBkr: false };
this.rules[4] = { name: 'digit', lower: 'digit', index: 4, isBkr: false };
/* UDTS */
this.udts = [];
/* OPCODES */
/* phone-number */
this.rules[0].opcodes = [];
this.rules[0].opcodes[0] = { type: 2, children: [1,2,3,4,5,6] };// CAT
this.rules[0].opcodes[1] = { type: 7, string: [40] };// TLS
this.rules[0].opcodes[2] = { type: 4, index: 1 };// RNM(area-code)
this.rules[0].opcodes[3] = { type: 7, string: [41] };// TLS
this.rules[0].opcodes[4] = { type: 4, index: 2 };// RNM(office)
this.rules[0].opcodes[5] = { type: 7, string: [45] };// TLS
this.rules[0].opcodes[6] = { type: 4, index: 3 };// RNM(subscriber)
/* area-code */
this.rules[1].opcodes = [];
this.rules[1].opcodes[0] = { type: 3, min: 3, max: 3 };// REP
this.rules[1].opcodes[1] = { type: 4, index: 4 };// RNM(digit)
/* office */
this.rules[2].opcodes = [];
this.rules[2].opcodes[0] = { type: 3, min: 3, max: 3 };// REP
this.rules[2].opcodes[1] = { type: 4, index: 4 };// RNM(digit)
/* subscriber */
this.rules[3].opcodes = [];
this.rules[3].opcodes[0] = { type: 3, min: 4, max: 4 };// REP
this.rules[3].opcodes[1] = { type: 4, index: 4 };// RNM(digit)
/* digit */
this.rules[4].opcodes = [];
this.rules[4].opcodes[0] = { type: 5, min: 48, max: 57 };// TRG
// The `toString()` function will display the original grammar file(s) that produced these opcodes.
this.toString = function toString(){
let str = "";
str += "phone-number = \"(\" area-code \")\" office \"-\" subscriber\n";
str += "area-code = 3digit\n";
str += "office = 3digit\n";
str += "subscriber = 4digit\n";
str += "digit = %d48-57\n";
return str;
}
}