boolean-expressions
Version:
Boolean expression parser and evaluator. Makes use of the Ohm grammar package with grammar rules found [here](https://github.com/avadavat/boolean-expressions/blob/master/src/grammar/grammarRules.ts).
15 lines (14 loc) • 659 B
TypeScript
import { Grammar, MatchResult } from "ohm-js";
/**
* Creates a semantics object with our truth grammar for the given query
* parameters.
*
* Returns a function to evaluate the semantics for the given match result
* with the given variables set to true, and the omitted variables set to false.
* This takes advantage of closures to allow us to re-use the same semantics object.
*
* The semantics API doesn't allow us to accept parameters to the evaluate
* function so this is how we get around it.
*/
declare function createSemantics(truthGrammar: Grammar, matchResult: MatchResult): (variables: string[]) => boolean;
export default createSemantics;