~james/remy

feat(frontend): support semicolon line comments

commit
a0e486f13b8e3c62454c0192400c1ca5d86a581e browse tree
parent
76eb8c0c102b513568343ee91839bb0ab21e49d4
author
james <j@cpl0.zip>
signature
Verified ~james signed with a key registered by ~james
date
2026-09-24 11:00 UTC

3 files changed, +19 −6

src/Examples.thy modified

@@ -109,4 +109,8 @@ lemma hexadecimal_execution:
109109 lemma incomplete_rejected: "prepare ''(if x y)'' = None"
110110 by eval
111111
112+lemma comment_tokens:
113+ "lex (''(+ x; ignore ) tokens'' @ newline @ ''y) ; end'') [] [] = [''('', ''+'', ''x'', ''y'', '')'']"
114+ by eval
115+
112116 end

src/Frontend.thy modified

@@ -6,12 +6,18 @@ fun finish :: "string \<Rightarrow> string list \<Rightarrow> string list" where
66 "finish [] out = out"
77 | "finish word out = rev word # out"
88
9-fun lex :: "string \<Rightarrow> string \<Rightarrow> string list \<Rightarrow> string list" where
10- "lex [] word out = rev (finish word out)"
11-| "lex (c # cs) word out = (if c = CHR '' '' \<or> c = CHR 0x09 \<or> c = CHR 0x0A \<or> c = CHR 0x0D
12- then lex cs [] (finish word out)
13- else if c = CHR ''('' \<or> c = CHR '')'' then lex cs [] ([c] # finish word out)
14- else lex cs (c # word) out)"
9+fun scan :: "string \<Rightarrow> string \<Rightarrow> string list \<Rightarrow> bool \<Rightarrow> string list" where
10+ "scan [] word out comment = rev (finish word out)"
11+| "scan (c # cs) word out comment = (if comment then
12+ scan cs [] out (c \<noteq> CHR 0x0A \<and> c \<noteq> CHR 0x0D)
13+ else if c = CHR '';'' then scan cs [] (finish word out) True
14+ else if c = CHR '' '' \<or> c = CHR 0x09 \<or> c = CHR 0x0A \<or> c = CHR 0x0D
15+ then scan cs [] (finish word out) False
16+ else if c = CHR ''('' \<or> c = CHR '')'' then scan cs [] ([c] # finish word out) False
17+ else scan cs (c # word) out False)"
18+
19+definition lex :: "string \<Rightarrow> string \<Rightarrow> string list \<Rightarrow> string list" where
20+ "lex s word out = scan s word out False"
1521
1622 fun digit :: "char \<Rightarrow> nat" where
1723 "digit c = (let n = nat_of_char c in

tests/cli.py modified

@@ -26,6 +26,9 @@ def main():
2626 assert int(invoke('eval',source,'0','0','0')) == 81
2727 source.write_text('(let 1x 3 1x)')
2828 invoke(source,binary,ok=False)
29+ for text in ['(+ x; ignore ) tokens\ny) ; end', '(+ x; comment\r\ny)', '(+ x y);end']:
30+ source.write_text(text)
31+ assert int(invoke('eval',source,'3','4','0')) == 7, text
2932 for text in ['0x','0x10000000000000000','0xfg','0xffextra','-0x1']:
3033 source.write_text(text)
3134 binary.write_bytes(b'preserve')