@malloydata/malloy-filter
v0.0.325
Published
Parsers for the Malloy filtering sub-languages
Downloads
17,422
Readme
Filter Languages
There is a unique filter language for each filterable data type. The documentation-bRoKeN-lInK describes the various languages.
Grammars
malloy-filter use moo and nearley to generate parsers for each sub language. The grammars are in grammars.
After changing a .ne file use npm run build to update the generated parser.
API
Refer to the clause interfaces for details on the
output of the parser, or look at the parser tests in src/test/ for more examples
of parser output.
import {StringFilterExpression, StringClause} from '@malloydata/malloy-filter'
// or ...
// NumberFilterExpression, NumberClause
// BooleanFilterExpression, BooleanClause
// TemporalFilterExpression, TemporalClause
// Each has two entry points, "parse" and "unparse"
const stringParse = StringFilterExpression.parse('FOO%,-FOOD')
if (stringParse.parsed) {
console.log(JSON.stringify(stringParse.parsed, null, 2));
/*
* Output will look something like this ...
* { operator: ',',
* members: [
* {operator: 'starts', values: ['FOO']}
* {operator: '=', not: true, values: ['FOOD']}
* ],
* }
*/
console.log(StringFilterExpression.unparse(stringParse.parse));
/*
* There will be minor variations on unparse, for example in this
* case there will be space after the comma:
*
* FOO%, -FOOD
*/
} else {
console.log(stringParse.log);
}Testing
The malloy-filter tests use Jest.
npm run build
npm run test