diff options
author | Asbjørn Sloth Tønnesen <ast@2e8.dk> | 2019-07-17 18:26:15 +0000 |
---|---|---|
committer | Asbjørn Sloth Tønnesen <ast@2e8.dk> | 2019-07-17 18:26:15 +0000 |
commit | 69d3a49eba0d984580a07d54d34a87b6aae8b802 (patch) | |
tree | 5513b9f542f0b4d3545c7f063f5c7bea50dfea8b | |
parent | 7d02dd60c0d6d106919ad3a021a6f98445daea78 (diff) | |
download | lua-inet-69d3a49eba0d984580a07d54d34a87b6aae8b802.tar.gz lua-inet-69d3a49eba0d984580a07d54d34a87b6aae8b802.tar.xz lua-inet-69d3a49eba0d984580a07d54d34a87b6aae8b802.zip |
tests: readme: allow multiline examples
Signed-off-by: Asbjørn Sloth Tønnesen <ast@2e8.dk>
-rw-r--r-- | test/readme.lua | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/test/readme.lua b/test/readme.lua index 9de3ae2..6f63276 100644 --- a/test/readme.lua +++ b/test/readme.lua @@ -9,9 +9,11 @@ local concat = table.concat local readme_parser do local P = lpeg.P - local Ct = lpeg.Ct + local S = lpeg.S + local V = lpeg.V local C = lpeg.C local Cc = lpeg.Cc + local Ct = lpeg.Ct local sp = P(' ') local eq = P('=') @@ -19,12 +21,16 @@ do local non_nl = P(1)-nl local rest_of_line = non_nl^0 - local div = sp^1 * P('-- returns ') + local extraline = (nl * sp * sp)^-1 + local line_or_space = extraline + sp^1 + local div = line_or_space * P('-- returns') * line_or_space local assign_mid = sp^1 * eq * sp^1 - local not_str = (sp^0 * nl) + div + assign_mid - local str = C((P(1)-not_str)^1) - local example = Ct(Cc('example') * str * div * sp^0 * str) + local table = P{"{" * ((1 - S('{}')) + V(1))^0 * "}"} + local not_str = (sp^0 * nl) + div + assign_mid + P('{') + local plainstr = (P(1)-not_str)^1 + local str = C(plainstr * (table * plainstr^0)^0) + local example = Ct(Cc('example') * str * div * str) local assign_left = P('local ')^-1 * str local assign_right = str local assignment = Ct(Cc('assignment') * assign_left * assign_mid * assign_right) |