Skip to content

Commit

Permalink
Merge pull request #8 from caido/ef-source
Browse files Browse the repository at this point in the history
Source namespace
  • Loading branch information
Sytten authored Jun 14, 2024
2 parents 937d370 + 72868f5 commit 877c824
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 16 deletions.
8 changes: 7 additions & 1 deletion js/httpql.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
RequestNamespace { "req" }
ResponseNamespace { "resp" }
PresetNamespace { "preset" }
SourceNamespace { "source" }

// Row field names
RowIntFieldName { "id" }
Expand Down Expand Up @@ -74,13 +75,14 @@ GroupQuery { LeftParen Query? RightParen }

CombinedQuery { Query !and And Query | Query !or Or Query }

SingleQuery { RowQuery | RequestQuery | ResponseQuery | PresetQuery }
SingleQuery { RowQuery | RequestQuery | ResponseQuery | PresetQuery | SourceQuery }

IntExpression { IntOperator Colon IntValue }
StringExpression { StringOperator Colon StringValue | RegexOperator Colon (RegexValue | StringValue) }
DateExpression { DateOperator Colon StringValue }
PresetNameExpression { StringValue }
PresetAliasExpression { SymbolValue }
SourceNameExpression { StringValue }

RowQuery { RowNamespace Dot RowIntFieldName Dot IntExpression }

Expand All @@ -99,4 +101,8 @@ PresetQuery {
PresetNamespace Colon (PresetNameExpression | PresetAliasExpression)
}

SourceQuery {
SourceNamespace Colon SourceNameExpression
}

@external propSource highlight from "./props.js"
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@caido/httpql",
"version": "0.3.0",
"version": "0.4.0",
"description": "Parser for the HTTPQL language",
"author": "Caido Labs Inc. <[email protected]>",
"license": "MIT",
Expand Down
10 changes: 10 additions & 0 deletions js/src/deserialize/query.single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { deserializePresetQuery } from "./query.preset.js";
import { deserializeRequestQuery } from "./query.request.js";
import { deserializeResponseQuery } from "./query.response.js";
import { deserializeRowQuery } from "./query.row.js";
import { deserializeSourceQuery } from "./query.source.js";

export const deserializeSingleQuery = (
node: SyntaxNode,
Expand Down Expand Up @@ -51,5 +52,14 @@ export const deserializeSingleQuery = (
});
}

const sourceQuery = node.getChild(terms.SourceQuery);
if (isPresent(sourceQuery)) {
return deserializeSourceQuery(sourceQuery, doc).map((source) => {
return {
source,
};
});
}

return err(new InvalidQuery());
};
25 changes: 25 additions & 0 deletions js/src/deserialize/query.source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { SyntaxNode } from "@lezer/common";
import { err, type Result } from "neverthrow";

import { type HTTPQLError, InvalidQuery } from "../errors.js";
import { terms } from "../parser/index.js";
import type { ExprSource } from "../primitives.js";
import { isPresent } from "../utils.js";

import { deserializeString } from "./string.js";

export const deserializeSourceQuery = (
node: SyntaxNode,
doc: string,
): Result<ExprSource, HTTPQLError> => {
const nameNode = node.getChild(terms.SourceNameExpression);
if (isPresent(nameNode)) {
return deserializeString(nameNode, doc).map(({ value }) => {
return {
name: value,
};
});
}

return err(new InvalidQuery());
};
2 changes: 1 addition & 1 deletion js/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Test =

describe("httpql", () => {
describe("ast", () => {
const cases = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const cases = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (const c of cases) {
it(`Case ${c}`, () => {
const input = fs.readFileSync(
Expand Down
9 changes: 6 additions & 3 deletions js/src/parser/parser.terms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export const HTTPQL = 1,
PresetNameExpression = 37,
PresetAliasExpression = 38,
SymbolValue = 39,
CombinedQuery = 40,
And = 41,
Or = 42;
SourceQuery = 40,
SourceNamespace = 41,
SourceNameExpression = 42,
CombinedQuery = 43,
And = 44,
Or = 45;
16 changes: 8 additions & 8 deletions js/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { highlight } from "./props.js";
export const parser = LRParser.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OkjX~Ok!cO~O",
goto: "#z!QPP!R!_!ePPP!_!_!xPPP#OPPP!xPPP#XPP#_#bPP#eP!xPPP!xP#h#hP!xP#k!_PP#n#tQYOQ`RQvfRwgXZORfgWQORfgQqdQteS![!W!XR!^!YXXORfgQ!PxQ!QyR!U|Q!QzR!U}R![!XR!a!]R!Q{RsdRueQ]PRh]Q!`!]R!b!`",
nodeNames:
"⚠ HTTPQL Query StringQuery StringValue StringChar RightParen LeftParen GroupQuery SingleQuery RowQuery RowNamespace Dot RowIntFieldName IntExpression IntOperator Colon IntValue RequestQuery RequestNamespace RequestIntFieldName RequestStringFieldName StringExpression StringOperator RegexOperator RegexValue RegexContent / RequestDateFieldName DateExpression DateOperator ResponseQuery ResponseNamespace ResponseIntFieldName ResponseStringFieldName PresetQuery PresetNamespace PresetNameExpression PresetAliasExpression SymbolValue CombinedQuery And Or",
maxTerm: 51,
"⚠ HTTPQL Query StringQuery StringValue StringChar RightParen LeftParen GroupQuery SingleQuery RowQuery RowNamespace Dot RowIntFieldName IntExpression IntOperator Colon IntValue RequestQuery RequestNamespace RequestIntFieldName RequestStringFieldName StringExpression StringOperator RegexOperator RegexValue RegexContent / RequestDateFieldName DateExpression DateOperator ResponseQuery ResponseNamespace ResponseIntFieldName ResponseStringFieldName PresetQuery PresetNamespace PresetNameExpression PresetAliasExpression SymbolValue SourceQuery SourceNamespace SourceNameExpression CombinedQuery And Or",
maxTerm: 54,
nodeProps: [
["openedBy", 6, "LeftParen"],
["closedBy", 7, "RightParen"],
Expand All @@ -20,16 +20,16 @@ export const parser = LRParser.deserialize({
skippedNodes: [0],
repeatNodeCount: 2,
tokenData:
"!$T~R!]X^$zpq%Pqr%Wrs%]sx%Wxy%byz%iz}%W}!O%p!O!P&f!P!Q&m!Q![&t![!]'n!]!c%W!c!d'u!d!q%W!q!r(Y!r#O%W#O#P(g#P#R%W#R#S%p#S#T%W#T#U*X#U#V%p#V#W+n#W#X%p#X#Y2{#Y#Z%p#Z#[4}#[#]6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#V#W!&S#W#o&Wb!&XUw`}!O&W!Q![&W#R#S&W#T#X&W#X#Y!&k#Y#o&Wb!&rSyQw`}!O&W!Q![&W#R#S&W#T#o&WS!'RP;=`<%l%Z",
tokenizers: [
1,
2,
3,
4,
new LocalTokenGroup(
"x~RQ!P!QX#O#P^~^Ok~~aRO;'Sj;'S;=`o;=`Oj~oO!T~~tP!T~;=`<%lj~",
"x~RQ!P!QX#O#P^~^Ok~~aRO;'Sj;'S;=`o;=`Oj~oO!W~~tP!W~;=`<%lj~",
39,
50,
53,
),
],
topRules: { HTTPQL: [0, 1] },
Expand Down
3 changes: 3 additions & 0 deletions js/src/primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type Query = {
AND?: Maybe<[Query, Query]>;
OR?: Maybe<[Query, Query]>;
row?: Maybe<ClauseRow>;
source?: Maybe<ExprSource>;
preset?: Maybe<ExprPreset>;
request?: Maybe<ClauseRequest>;
response?: Maybe<ClauseResponse>;
Expand Down Expand Up @@ -37,6 +38,8 @@ export type ExprInt = {

export type ExprPreset = { alias: string } | { name: string };

export type ExprSource = { name: string };

export type ExprString = {
operator: OperatorString;
value: string;
Expand Down
10 changes: 10 additions & 0 deletions js/src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
ExprDate,
ExprInt,
ExprPreset,
ExprSource,
ExprString,
Query,
} from "./primitives.js";
Expand All @@ -26,6 +27,9 @@ const serializeClauseRequestResponse = (
if (isPresent(query.preset)) {
return serializeExprPreset(query.preset);
}
if (isPresent(query.source)) {
return serializeExprSource(query.source);
}
if (isPresent(query.request)) {
return serializeClauseRequest(query.request).map((str) => `req.${str}`);
}
Expand Down Expand Up @@ -134,3 +138,9 @@ const serializeExprString = (
const serializeExprDate = (value: ExprDate): Result<string, HTTPQLError> => {
return ok(`${value.operator.toLowerCase()}:"${value.value}"`);
};

const serializeExprSource = (
value: ExprSource,
): Result<string, HTTPQLError> => {
return ok(`source:"${value.name}"`);
};
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = ["Caido Labs Inc. <[email protected]>"]
description = "Parser for the HTTPQL language"
repository = "https://github.com/caido/httpql"
license = "MIT"
version = "0.3.0"
version = "0.4.0"
edition = "2021"

[dependencies]
Expand Down
8 changes: 7 additions & 1 deletion rust/httpql.pest
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RowNamespace = _{ "row" }
RequestNamespace = _{ "req" }
ResponseNamespace = _{ "resp" }
PresetNamespace = _{ "preset" }
SourceNamespace = _{ "source" }

// Row field names
RowIntFieldName = { "id" }
Expand Down Expand Up @@ -61,6 +62,7 @@ StringExpression = ${ StringOperator ~ Colon ~ StringValue | RegexOperator
DateExpression = ${ DateOperator ~ Colon ~ StringValue }
PresetNameExpression = { StringValue }
PresetAliasExpression = { SymbolValue }
SourceNameExpression = { StringValue }

// Clause
StringClause = { StringValue }
Expand All @@ -82,7 +84,11 @@ PresetClause = ${
PresetNamespace ~ Colon ~ (PresetNameExpression | PresetAliasExpression)
}

SourceClause = ${
SourceNamespace ~ Colon ~ SourceNameExpression
}

// Query
Clause = _{ StringClause | RowClause | RequestClause | ResponseClause | PresetClause | LeftParen ~ Query ~ RightParen }
Clause = _{ StringClause | RowClause | RequestClause | ResponseClause | PresetClause | SourceClause | LeftParen ~ Query ~ RightParen }
LogicalOperator = _{ And | Or }
Query = { Clause ~ (LogicalOperator ~ Clause)* }
1 change: 1 addition & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mod tests {
#[case(7)]
#[case(8)]
#[case(9)]
#[case(10)]
fn test_ast(#[case] case: u32) {
let input = std::fs::read_to_string(format!("../tests/ast/{case}/input.httpql")).unwrap();
let output = std::fs::read_to_string(format!("../tests/ast/{case}/output.ast")).unwrap();
Expand Down
Loading

0 comments on commit 877c824

Please sign in to comment.