Skip to main content
Module

x/ohm_js/src/CaseInsensitiveTerminal.js

A library and language for building parsers, interpreters, compilers, etc.
Go to Latest
File
import {Failure} from './Failure.js';import {TerminalNode} from './nodes.js';import {assert} from './common.js';import {PExpr, Terminal} from './pexprs-main.js';
export class CaseInsensitiveTerminal extends PExpr { constructor(param) { super(); this.obj = param; }
_getString(state) { const terminal = state.currentApplication().args[this.obj.index]; assert(terminal instanceof Terminal, 'expected a Terminal expression'); return terminal.obj; }
// Implementation of the PExpr API
allowsSkippingPrecedingSpace() { return true; }
eval(state) { const {inputStream} = state; const origPos = inputStream.pos; const matchStr = this._getString(state); if (!inputStream.matchString(matchStr, true)) { state.processFailure(origPos, this); return false; } else { state.pushBinding(new TerminalNode(matchStr.length), origPos); return true; } }
getArity() { return 1; }
substituteParams(actuals) { return new CaseInsensitiveTerminal(this.obj.substituteParams(actuals)); }
toDisplayString() { return this.obj.toDisplayString() + ' (case-insensitive)'; }
toFailure(grammar) { return new Failure( this, this.obj.toFailure(grammar) + ' (case-insensitive)', 'description', ); }
_isNullable(grammar, memo) { return this.obj._isNullable(grammar, memo); }}