Installation
npm install --save @rsql/parser
yarn add @rsql/parser
API
parse(rsql: string): ExpressionNode
Parses RSQL string and returns Abstract Syntax Tree. It can throw the following errors:
InvalidArgumentError
- in the case of invalid argument type passed to the parse
functionParsingError
- in the case of any problems encountered during parsing
new ParsingError(message: string, source: string)
A runtime error that should be thrown in the case of encountering any problem with the parsing
(invalid character, invalid token, etc.)
Example
import { parse, ParsingError } from "@rsql/parser";
import { isEqNode, getSingleValue } from "@rsql/ast";
function getUserNameFromRsql(rsql) {
let ast;
try {
ast = parse(rsql);
} catch (error) {
if (error instanceof ParsingError) {
return undefined;
} else {
throw error;
}
}
if (isEqNode(ast) && getSelector(ast) === "user.name") {
return getSingleValue(ast);
} else {
return undefined;
}
}
License
MIT