query: Add not-eq? predicate in rust & wasm binding
This commit is contained in:
parent
f67c0526fd
commit
33492ca9df
2 changed files with 21 additions and 10 deletions
|
|
@ -742,7 +742,10 @@ class Language {
|
|||
throw new Error('Predicates must begin with a literal value');
|
||||
}
|
||||
const operator = steps[0].value;
|
||||
let isPositive = true;
|
||||
switch (operator) {
|
||||
case 'not-eq?':
|
||||
isPositive = false;
|
||||
case 'eq?':
|
||||
if (steps.length !== 3) throw new Error(
|
||||
`Wrong number of arguments to \`eq?\` predicate. Expected 2, got ${steps.length - 1}`
|
||||
|
|
@ -759,14 +762,16 @@ class Language {
|
|||
if (c.name === captureName1) node1 = c.node;
|
||||
if (c.name === captureName2) node2 = c.node;
|
||||
}
|
||||
return node1.text === node2.text
|
||||
return (node1.text === node2.text) === isPositive;
|
||||
});
|
||||
} else {
|
||||
const captureName = steps[1].name;
|
||||
const stringValue = steps[2].value;
|
||||
predicates[i].push(function(captures) {
|
||||
for (const c of captures) {
|
||||
if (c.name === captureName) return c.node.text === stringValue;
|
||||
if (c.name === captureName) {
|
||||
return (c.node.text === stringValue) === isPositive;
|
||||
};
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue