diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-04-05 18:11:06 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-04-07 10:33:17 +0000 |
| commit | 1ca6f7e9caa998b43eb236da2a7618c79c4e76e8 (patch) | |
| tree | 582e528d12c1bdb18b7769558385b5dd6e474a4a | |
| parent | lib: add link-time/spring (diff) | |
| download | alive-1ca6f7e9caa998b43eb236da2a7618c79c4e76e8.tar.gz alive-1ca6f7e9caa998b43eb236da2a7618c79c4e76e8.zip | |
line comments
| -rw-r--r-- | alv/parsing.moon | 12 | ||||
| -rw-r--r-- | spec/internal/parsing_spec.moon | 4 |
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 |
