Skip to content

Commit

Permalink
[MainUI] Sitemap parser parse and discard comments (openhab#2045)
Browse files Browse the repository at this point in the history
Fixes openhab#2043

The sitemap parser was not able to cope with comments in the sitemap
text when pasted in from a sitemap file.
Comments will now be discarded (the REST API does not have fields for
comments), but the sitemap will still be parsed and saved.

Similarly, blanks where accepted in a number of places when defined in
text files, but not in the parser. This is now also corrected.

Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
Signed-off-by: Stefan Höhn <mail@stefanhoehn.com>
  • Loading branch information
mherwege authored and stefan-hoehn committed Sep 23, 2023
1 parent 276f311 commit 15b98e0
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions bundles/org.openhab.ui/web/src/assets/sitemap-lexer.nearley
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

let lexer = moo.compile({
WS: /[ \t]+/,
comment: /\/\/.*?$/,
sitemap: 'sitemap ',
name: 'name=',
label: 'label=',
item: 'item=',
icon: 'icon=',
widgetattr: ['url=', 'refresh=', 'service=', 'period=', 'height=', 'mappings=', 'minValue=', 'maxValue=', 'step=', 'encoding=', 'yAxisDecimalPattern=', 'inputHint='],
widgetattr: ['url=', 'refresh=', 'service=', 'period=', 'height=', 'minValue=', 'maxValue=', 'step=', 'encoding=', 'yAxisDecimalPattern=', 'inputHint='],
widgetboolattr: ['legend='],
widgetfreqattr: 'sendFrequency=',
widgetfrcitmattr: 'forceasitem=',
widgetmapattr: 'mappings=',
widgetvisiattr: 'visibility=',
widgetcolorattr: ['labelcolor=', 'valuecolor=', 'iconcolor='],
widgetswitchattr: 'switchSupport',
Expand All @@ -32,6 +32,8 @@
gt: '>',
equals: '=',
NL: { match: /\n/, lineBreaks: true },
SL_COMMENT: /\/\/.*$/,
ML_COMMENT: /\/\*[\s\S]*?\*\//,
boolean: /(?:true)|(?:false)/,
identifier: /(?:[A-Za-z_][A-Za-z0-9_]*)|(?:[0-9]+[A-Za-z_][A-Za-z0-9_]*)/,
number: /-?[0-9]+(?:\.[0-9]*)?/,
Expand Down Expand Up @@ -85,7 +87,7 @@ Sitemap -> %sitemap _ SitemapName __ SitemapLabel __ %lbrace _ Widgets _ %rbrace

SitemapName -> %identifier
SitemapLabel -> null {% (d) => { return {} } %}
| %label %string {% (d) => { return { 'label': d[1].value } } %}
| %label _ %string {% (d) => { return { 'label': d[2].value } } %}

Widgets -> Widget {% (d) => [d[0]] %}
| Widgets _ Widget {% (d) => d[0].concat([d[2]]) %}
Expand All @@ -97,11 +99,12 @@ Widget -> %nlwidget _ WidgetAttrs:*
WidgetAttrs -> WidgetAttr {% (d) => [d[0]] %}
| WidgetAttrs _ WidgetAttr {% (d) => d[0].concat([d[2]]) %}
WidgetAttr -> %widgetswitchattr {% (d) => ['switchEnabled', true] %}
| %widgetfrcitmattr WidgetBooleanAttrValue {% (d) => ['forceAsItem', d[1]] %}
| %widgetboolattr WidgetBooleanAttrValue {% (d) => [d[0].value, d[1]] %}
| %widgetfreqattr WidgetAttrValue {% (d) => ['frequency', d[1]] %}
| %icon WidgetIconAttrValue {% (d) => [d[0].value, d[1].join("")] %}
| WidgetAttrName WidgetAttrValue {% (d) => [d[0][0].value, d[1]] %}
| %widgetfrcitmattr _ WidgetBooleanAttrValue {% (d) => ['forceAsItem', d[2]] %}
| %widgetboolattr _ WidgetBooleanAttrValue {% (d) => [d[0].value, d[2]] %}
| %widgetfreqattr _ WidgetAttrValue {% (d) => ['frequency', d[2]] %}
| %icon _ WidgetIconAttrValue {% (d) => [d[0].value, d[2].join("")] %}
| WidgetAttrName _ WidgetAttrValue {% (d) => [d[0][0].value, d[2]] %}
| WidgetMappingsAttrName WidgetMappingsAttrValue {% (d) => [d[0][0].value, d[1]] %}
| WidgetVisibilityAttrName WidgetVisibilityAttrValue {% (d) => [d[0][0].value, d[1]] %}
| WidgetColorAttrName WidgetColorAttrValue {% (d) => [d[0][0].value, d[1]] %}
WidgetAttrName -> %item | %label | %widgetattr
Expand All @@ -116,7 +119,8 @@ WidgetIconName -> %identifier
WidgetAttrValue -> %number {% (d) => { return parseFloat(d[0].value) } %}
| %identifier {% (d) => d[0].value %}
| %string {% (d) => d[0].value %}
| %lbracket _ Mappings _ %rbracket {% (d) => d[2] %}
WidgetMappingsAttrName -> %widgetmapattr
WidgetMappingsAttrValue -> %lbracket _ Mappings _ %rbracket {% (d) => d[2] %}
WidgetVisibilityAttrName -> %widgetvisiattr
WidgetVisibilityAttrValue -> %lbracket _ Visibilities _ %rbracket {% (d) => d[2] %}
WidgetColorAttrName -> %widgetcolorattr
Expand Down Expand Up @@ -146,17 +150,16 @@ ColorComparator -> %eq | %noteq | %lteq | %gteq | %lt | %gt
ColorValue -> %number | %identifier | %string
ColorName -> %identifier | %string

_ -> null {% () => null %}
| _ %WS {% () => null %}
| _ %NL {% () => null %}
# | _ %comment {% () => null %}
_ -> null {% () => null %}
| __ {% () => null %}

__ -> %WS {% () => null %}
| %NL {% () => null %}
| %comment {% () => null %}
| __ %WS {% () => null %}
| __ %NL {% () => null %}
| __ %comment {% () => null %}
__ -> %WS {% () => null %}
| %NL {% () => null %}
| Comment {% () => null %}
| __ %WS {% () => null %}
| __ %NL {% () => null %}
| __ Comment {% () => null %}

Comment -> %SL_COMMENT {% () => null %}
| %ML_COMMENT {% () => null %}

NL -> %NL {% () => null %}
| _ %NL {% () => null %}

0 comments on commit 15b98e0

Please sign in to comment.