diff --git a/lxl-web/src/lib/styles/lxlquery.css b/lxl-web/src/lib/styles/lxlquery.css index f8f57f0cc..a3f50a21a 100644 --- a/lxl-web/src/lib/styles/lxlquery.css +++ b/lxl-web/src/lib/styles/lxlquery.css @@ -38,7 +38,7 @@ user-select: none; } -.lxl-boolean-query { +.lxl-boolean-operator { color: rgb(128, 0, 128); } diff --git a/packages/codemirror-lang-lxlquery/src/index.ts b/packages/codemirror-lang-lxlquery/src/index.ts index 1312975b3..f4a3ed768 100644 --- a/packages/codemirror-lang-lxlquery/src/index.ts +++ b/packages/codemirror-lang-lxlquery/src/index.ts @@ -8,7 +8,7 @@ import { styleTags, Tag, tagHighlighter } from '@lezer/highlight'; * for the matching syntax */ const tags = { - BooleanQuery: Tag.define('BooleanQuery'), + BooleanOperator: Tag.define('BooleanOperator'), Wildcard: Tag.define('Wildcard'), Qualifier: Tag.define('Qualifier'), QualifierKey: Tag.define('QualifierKey'), @@ -17,12 +17,12 @@ const tags = { }; const tagMatcher = { - BooleanQuery: tags.BooleanQuery, - Wildcard: tags.Wildcard, + 'BooleanQuery/BooleanOperator': tags.BooleanOperator, // only highlight operator within valid query + 'Query/Wildcard': tags.Wildcard, 'Qualifier/...': tags.Qualifier, - 'QualifierKey/...': tags.QualifierKey, - 'QualifierOperator/...': tags.QualifierOperator, - 'QualifierValue/...': tags.QualifierValue + 'QualifierKey!': tags.QualifierKey, + 'QualifierOperator!': tags.QualifierOperator, + 'QualifierValue!': tags.QualifierValue }; export const lxlQueryLanguage = LRLanguage.define({ @@ -34,7 +34,7 @@ export const lxlQueryLanguage = LRLanguage.define({ }); const highlighter = tagHighlighter([ - { tag: tags.BooleanQuery, class: 'lxl-boolean-query' }, + { tag: tags.BooleanOperator, class: 'lxl-boolean-operator' }, { tag: tags.Wildcard, class: 'lxl-wildcard' }, { tag: tags.Qualifier, class: 'lxl-qualifier' }, { tag: tags.QualifierKey, class: 'lxl-qualifier-key' }, diff --git a/packages/codemirror-lang-lxlquery/src/syntax.grammar b/packages/codemirror-lang-lxlquery/src/syntax.grammar index 8becf0758..9cb3f8fa4 100644 --- a/packages/codemirror-lang-lxlquery/src/syntax.grammar +++ b/packages/codemirror-lang-lxlquery/src/syntax.grammar @@ -25,7 +25,7 @@ QualifierKey { } QualifierValue { - Identifier | String | Number | Group + Identifier Wildcard? | String | Number Wildcard? | Group | Wildcard } QualifierOperator { @@ -49,7 +49,7 @@ freetext { BooleanOperator { "AND" | "OR" | "NOT" } - Wildcard { "*"+ } + Wildcard { "*" } reserved { "includeEplikt" | "includePreliminary" } diff --git a/packages/codemirror-lang-lxlquery/test/cases.txt b/packages/codemirror-lang-lxlquery/test/cases.txt index 21eff5635..09ec8d3e1 100644 --- a/packages/codemirror-lang-lxlquery/test/cases.txt +++ b/packages/codemirror-lang-lxlquery/test/cases.txt @@ -82,6 +82,30 @@ Query( ) +# Qualifier with wildcard + +titel:kulturarv* + +==> + +Query( + Qualifier(QualifierKey(...), QualifierOperator(...), QualifierValue(Identifier, Wildcard)) +) + +# Qualifier with wildcard (invalid) + +subject*:vinter + +==> + +Query( + Identifier, + Wildcard, + ⚠(...), + Identifier +) + + # BooleanQuery sommar OR vinter NOT vår @@ -104,7 +128,7 @@ Query( ) -# BooleanQuery - erroneous +# BooleanQuery (invalid) OR AND sommar @@ -131,7 +155,12 @@ träd* bibliografi:"sigel:DST" NOT typ:Text ==> Query( - Identifier, Wildcard, BooleanQuery(Qualifier(QualifierKey(Identifier), QualifierOperator(EqualOperator), QualifierValue(String)), BooleanOperator, Qualifier(QualifierKey(Identifier), QualifierOperator(EqualOperator), QualifierValue(Identifier))) + Identifier, + Wildcard, + BooleanQuery( + Qualifier(QualifierKey(Identifier), QualifierOperator(EqualOperator), QualifierValue(String)), + BooleanOperator, + Qualifier(QualifierKey(Identifier), QualifierOperator(EqualOperator), QualifierValue(Identifier))) ) @@ -165,7 +194,11 @@ image:* ==> -Query(Qualifier(...)) +Query( + Qualifier( + QualifierKey(...), QualifierOperator(...), QualifierValue(Wildcard) + ) +) # Other filters: include E-plikt