aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-04-05 18:11:06 +0000
committers-ol <s+removethis@s-ol.nu>2025-04-07 10:33:17 +0000
commit1ca6f7e9caa998b43eb236da2a7618c79c4e76e8 (patch)
tree582e528d12c1bdb18b7769558385b5dd6e474a4a
parentlib: add link-time/spring (diff)
downloadalive-1ca6f7e9caa998b43eb236da2a7618c79c4e76e8.tar.gz
alive-1ca6f7e9caa998b43eb236da2a7618c79c4e76e8.zip
line comments
-rw-r--r--alv/parsing.moon12
-rw-r--r--spec/internal/parsing_spec.moon4
2 files changed, 11 insertions, 5 deletions
diff --git a/alv/parsing.moon b/alv/parsing.moon
index 0ae2586..f8247a4 100644
--- a/alv/parsing.moon
+++ b/alv/parsing.moon
@@ -7,11 +7,13 @@ import R, S, P, V, C, Ct from require 'lpeg'
-- whitespace
wc = S ' \t\r\n'
-comment = P {
- 'comment',
- expr: (P '(') * ((V 'expr') + (1 - P ')'))^0 * (P ')')
- comment: (P '#(') * ((V 'expr') + (1 - P ')'))^0 * (P ')')
+cexpr = (P '(') * ((V 'cexpr') + (1 - P ')'))^0 * (P ')')
+ccell = P {
+ (P '#') * (V 'cexpr')
+ :cexpr
}
+cline = (P '##') * (1 - (P '\n'))^0
+comment = cline + ccell
mspace = (comment + wc)^0 / 1 -- optional whitespace
space = (wc^1 * (comment^0 * wc)^0) / 1 -- required whitespace
@@ -32,7 +34,7 @@ num = ((P '-')^-1 * (float + fract + int)) / Constant\parse 'num'
tag = (P '[') * (digit^1 / Tag.parse) * (P ']')
tpltext = ((P '\\"') + (P '\\\\') + (P '\\$') + (1 - (P '"') - (P '$')))^1 / 1
-tplcont = Ct ((P '$$') / 1 + ('$' * (V 'expr')) + tpltext)^0
+tplcont = Ct (('$' * (V 'expr')) + tpltext)^0
tplstr = (P '$') * tag^-1 * sym * '"' * tplcont * '"' / TemplateString\parse
expitem = tplstr + (V 'expr')
diff --git a/spec/internal/parsing_spec.moon b/spec/internal/parsing_spec.moon
index da70824..47de338 100644
--- a/spec/internal/parsing_spec.moon
+++ b/spec/internal/parsing_spec.moon
@@ -149,6 +149,10 @@ describe 'comments', ->
str = '#(this is a comment)'
assert.is.equal str, comment\match str
+ it 'line comments are parsed', ->
+ str = '## this is a comment )))!'
+ assert.is.equal str, comment\match str
+
it 'extend to matching braces', ->
str = '#(this is a comment #(with nested comments))'
assert.is.equal str, comment\match str