Skip to content

Commit

Permalink
fix(lxlquery): support wildcard in qualifierValue
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperengstrom committed Dec 20, 2024
1 parent 2cba5f4 commit f9252d6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lxl-web/src/lib/styles/lxlquery.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
user-select: none;
}

.lxl-boolean-query {
.lxl-boolean-operator {
color: rgb(128, 0, 128);
}

Expand Down
14 changes: 7 additions & 7 deletions packages/codemirror-lang-lxlquery/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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({
Expand All @@ -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' },
Expand Down
4 changes: 2 additions & 2 deletions packages/codemirror-lang-lxlquery/src/syntax.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ QualifierKey {
}

QualifierValue {
Identifier | String | Number | Group
Identifier Wildcard? | String | Number | Group | Wildcard
}

QualifierOperator {
Expand All @@ -49,7 +49,7 @@ freetext {

BooleanOperator { "AND" | "OR" | "NOT" }

Wildcard { "*"+ }
Wildcard { "*" }

reserved { "includeEplikt" | "includePreliminary" }

Expand Down
39 changes: 36 additions & 3 deletions packages/codemirror-lang-lxlquery/test/cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -104,7 +128,7 @@ Query(
)


# BooleanQuery - erroneous
# BooleanQuery (invalid)

OR AND sommar

Expand All @@ -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)))
)


Expand Down Expand Up @@ -165,7 +194,11 @@ image:*

==>

Query(Qualifier(...))
Query(
Qualifier(
QualifierKey(...), QualifierOperator(...), QualifierValue(Wildcard)
)
)


# Other filters: include E-plikt
Expand Down

0 comments on commit f9252d6

Please sign in to comment.