apg-js-examples
Version:
Examples of using the suite of apg-js applications and libraries.
17 lines (16 loc) • 815 B
JavaScript
// This is a simple demonstration of the negative `look-behind` operator.
// The grammar defines two types of text (ASCII printing characters,)
// Comment text begins with `//`, other text does not.
// Both of these input lines will parse successfully.
// Look at the trace to see that in the one case `other-text` is matched,
// while in the other case `comment-text` is matched.
// In a more realistic application the `AST` would be used to translate
// or otherwise distiguish between the two types of text.
(function negative() {
let input = '// this is a comment';
const grammar = new (require('./negative-grammar'))();
const setup = require('./setup');
setup(input, grammar, 'negative-comment');
input = 'this is not a comment';
setup(input, grammar, 'negative-no-comment');
})();