Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lxlquery): Support wildcard in qualifierValue #1192

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Wildcard? | 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
Loading