apg-js-examples
Version:
Examples of using the suite of apg-js applications and libraries.
24 lines (23 loc) • 1.29 kB
JavaScript
/* *************************************************************************************
* copyright: Copyright (c) 2021 Lowell D. Thomas, all rights reserved
* license: BSD-2-Clause (https://opensource.org/licenses/BSD-2-Clause)
* ********************************************************************************* */
// This is a simple demonstration of the parsing a substring.
// The grammar is for a simplified phone number.
// The first example parses the entire string to match the phone number.
// The second example also matches the phone number, but only as a sub-string with a leading prefix phrase.
// The final example parses a substring which is completely embedded in the full input string.
(function simple() {
let input;
const grammar = new (require('./phone-number'))();
const setup = require('./setup');
/* defaults the substring to the full string */
input = '(800)555-1234';
setup(input, undefined, undefined, grammar, 'substring-full');
/* substring starts interior to string an runs to end of string */
input = 'xxx(800)555-1234';
setup(input, 3, undefined, grammar, 'substring-interior');
/* selects an embedded substring */
input = 'xxx(800)555-1234yyy';
setup(input, 3, 13, grammar, 'substring-embedded');
})();