apg-js-examples
Version:
Examples of using the suite of apg-js applications and libraries.
82 lines (74 loc) • 2.92 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 = 4
// udts = 0
// opcodes = 16
// --- ABNF original opcodes
// ALT = 1
// CAT = 2
// REP = 2
// RNM = 5
// TLS = 1
// TBS = 0
// TRG = 3
// --- SABNF superset opcodes
// UDT = 0
// AND = 0
// NOT = 1
// BKA = 0
// BKN = 1
// BKR = 0
// ABG = 0
// AEN = 0
// characters = [32 - 126]
// ```
/* OBJECT IDENTIFIER (for internal parser use) */
this.grammarObject = 'grammarObject';
/* RULES */
this.rules = [];
this.rules[0] = { name: 'cat-text', lower: 'cat-text', index: 0, isBkr: false };
this.rules[1] = { name: 'any', lower: 'any', index: 1, isBkr: false };
this.rules[2] = { name: 'word-char', lower: 'word-char', index: 2, isBkr: false };
this.rules[3] = { name: 'cat', lower: 'cat', index: 3, isBkr: false };
/* UDTS */
this.udts = [];
/* OPCODES */
/* cat-text */
this.rules[0].opcodes = [];
this.rules[0].opcodes[0] = { type: 2, children: [1,3,4] };// CAT
this.rules[0].opcodes[1] = { type: 3, min: 10, max: 10 };// REP
this.rules[0].opcodes[2] = { type: 4, index: 1 };// RNM(any)
this.rules[0].opcodes[3] = { type: 4, index: 3 };// RNM(cat)
this.rules[0].opcodes[4] = { type: 3, min: 0, max: Infinity };// REP
this.rules[0].opcodes[5] = { type: 4, index: 1 };// RNM(any)
/* any */
this.rules[1].opcodes = [];
this.rules[1].opcodes[0] = { type: 5, min: 32, max: 126 };// TRG
/* word-char */
this.rules[2].opcodes = [];
this.rules[2].opcodes[0] = { type: 1, children: [1,2] };// ALT
this.rules[2].opcodes[1] = { type: 5, min: 64, max: 90 };// TRG
this.rules[2].opcodes[2] = { type: 5, min: 97, max: 122 };// TRG
/* cat */
this.rules[3].opcodes = [];
this.rules[3].opcodes[0] = { type: 2, children: [1,3,4] };// CAT
this.rules[3].opcodes[1] = { type: 16 };// BKN
this.rules[3].opcodes[2] = { type: 4, index: 2 };// RNM(word-char)
this.rules[3].opcodes[3] = { type: 7, string: [99,97,116] };// TLS
this.rules[3].opcodes[4] = { type: 13 };// NOT
this.rules[3].opcodes[5] = { type: 4, index: 2 };// RNM(word-char)
// The `toString()` function will display the original grammar file(s) that produced these opcodes.
this.toString = function toString(){
let str = "";
str += "cat-text = 10any cat *any\n";
str += "any = %d32-126\n";
str += "word-char = %d64-90 / %d97-122\n";
str += "cat = !!word-char \"cat\" !word-char\n";
return str;
}
}