From d6cb444af696ea23d23b1252f2aa51235aff2d63 Mon Sep 17 00:00:00 2001 From: JP Appel Date: Mon, 2 Jun 2025 13:37:43 -0400 Subject: Fix lookback error in lexer --- pkg/query/lexer_test.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'pkg/query/lexer_test.go') diff --git a/pkg/query/lexer_test.go b/pkg/query/lexer_test.go index 761055e..0cfc1de 100644 --- a/pkg/query/lexer_test.go +++ b/pkg/query/lexer_test.go @@ -28,6 +28,26 @@ func TestLex(t *testing.T) { {TOK_CAT_DATE, "d"}, {TOK_OP_AP, ":"}, {TOK_VAL_DATETIME, "01010001"}, {Type: TOK_CLAUSE_END}, }}, + {"leading subclause", "(or a:a a:b)", []Token{ + {Type: TOK_CLAUSE_START}, {TOK_CLAUSE_AND, "and"}, + {Type: TOK_CLAUSE_START}, {TOK_CLAUSE_OR, "or"}, + {TOK_CAT_AUTHOR, "a"}, {TOK_OP_AP, ":"}, {TOK_VAL_STR, "a"}, + {TOK_CAT_AUTHOR, "a"}, {TOK_OP_AP, ":"}, {TOK_VAL_STR, "b"}, + {Type: TOK_CLAUSE_END}, + {Type: TOK_CLAUSE_END}, + }}, + {"clause after clause", "(or a:a a:b) (or a:c a:d)", []Token{ + {Type: TOK_CLAUSE_START}, {TOK_CLAUSE_AND, "and"}, + {Type: TOK_CLAUSE_START}, {TOK_CLAUSE_OR, "or"}, + {TOK_CAT_AUTHOR, "a"}, {TOK_OP_AP, ":"}, {TOK_VAL_STR, "a"}, + {TOK_CAT_AUTHOR, "a"}, {TOK_OP_AP, ":"}, {TOK_VAL_STR, "b"}, + {Type: TOK_CLAUSE_END}, + {Type: TOK_CLAUSE_START}, {TOK_CLAUSE_OR, "or"}, + {TOK_CAT_AUTHOR, "a"}, {TOK_OP_AP, ":"}, {TOK_VAL_STR, "c"}, + {TOK_CAT_AUTHOR, "a"}, {TOK_OP_AP, ":"}, {TOK_VAL_STR, "d"}, + {Type: TOK_CLAUSE_END}, + {Type: TOK_CLAUSE_END}, + }}, {"nested clauses", "a:a (or t:b t!=c) or d<=01010001 and -T~foo", []Token{ {Type: TOK_CLAUSE_START}, {TOK_CLAUSE_AND, "and"}, {TOK_CAT_AUTHOR, "a"}, {TOK_OP_AP, ":"}, {TOK_VAL_STR, "a"}, @@ -63,8 +83,8 @@ func TestLex(t *testing.T) { } if t.Failed() { - t.Log("Got\n", treeStringify(got)) - t.Log("Want\n", treeStringify(tt.want)) + t.Log("Got\n", TokensStringify(got)) + t.Log("Want\n", TokensStringify(tt.want)) } }) } -- cgit v1.2.3