UNPKG

apg-js-examples

Version:

Examples of using the suite of apg-js applications and libraries.

82 lines (74 loc) 3.1 kB
// 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 = 3 // CAT = 0 // REP = 3 // RNM = 3 // TLS = 0 // TBS = 0 // TRG = 7 // --- SABNF superset opcodes // UDT = 0 // AND = 0 // NOT = 0 // BKA = 0 // BKN = 0 // BKR = 0 // ABG = 0 // AEN = 0 // characters = [31 - 65535] // ``` /* OBJECT IDENTIFIER (for internal parser use) */ this.grammarObject = 'grammarObject'; /* RULES */ this.rules = []; this.rules[0] = { name: 'word', lower: 'word', index: 0, isBkr: false }; this.rules[1] = { name: 'english-word', lower: 'english-word', index: 1, isBkr: false }; this.rules[2] = { name: 'greek-word', lower: 'greek-word', index: 2, isBkr: false }; this.rules[3] = { name: 'other-word', lower: 'other-word', index: 3, isBkr: false }; /* UDTS */ this.udts = []; /* OPCODES */ /* word */ this.rules[0].opcodes = []; this.rules[0].opcodes[0] = { type: 1, children: [1,2,3] };// ALT this.rules[0].opcodes[1] = { type: 4, index: 1 };// RNM(english-word) this.rules[0].opcodes[2] = { type: 4, index: 2 };// RNM(greek-word) this.rules[0].opcodes[3] = { type: 4, index: 3 };// RNM(other-word) /* english-word */ this.rules[1].opcodes = []; this.rules[1].opcodes[0] = { type: 3, min: 1, max: Infinity };// REP this.rules[1].opcodes[1] = { type: 1, children: [2,3] };// ALT this.rules[1].opcodes[2] = { type: 5, min: 65, max: 90 };// TRG this.rules[1].opcodes[3] = { type: 5, min: 97, max: 122 };// TRG /* greek-word */ this.rules[2].opcodes = []; this.rules[2].opcodes[0] = { type: 3, min: 1, max: Infinity };// REP this.rules[2].opcodes[1] = { type: 5, min: 880, max: 1023 };// TRG /* other-word */ this.rules[3].opcodes = []; this.rules[3].opcodes[0] = { type: 3, min: 1, max: Infinity };// REP this.rules[3].opcodes[1] = { type: 1, children: [2,3,4,5] };// ALT this.rules[3].opcodes[2] = { type: 5, min: 31, max: 64 };// TRG this.rules[3].opcodes[3] = { type: 5, min: 91, max: 96 };// TRG this.rules[3].opcodes[4] = { type: 5, min: 123, max: 879 };// TRG this.rules[3].opcodes[5] = { type: 5, min: 1024, max: 65535 };// TRG // The `toString()` function will display the original grammar file(s) that produced these opcodes. this.toString = function toString(){ let str = ""; str += "word = english-word / greek-word / other-word\n"; str += "english-word = 1*(%d65-90/%d97-122)\n"; str += "greek-word = 1*(%x370-3ff)\n"; str += "other-word = 1*(%d31-64 / %d91-96 / %d123-879 / %x400-ffff)\n"; return str; } }