aboutsummaryrefslogtreecommitdiff
path: root/examples/ini
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-06 22:26:12 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-06 22:26:12 -0400
commit3406515a44b13d0c290c28ac42bd364ce27560c7 (patch)
tree38000658e651ad19b9c8c2590df8fd6bb6faa4d7 /examples/ini
parentd8afa73368cdff38125fa1f7d17ad5ce54c84def (diff)
Make string escapes more normal: "\n" for newline, etc. Backticks can be
used to put in literal code without escape sequences.
Diffstat (limited to 'examples/ini')
-rw-r--r--examples/ini/ini.tm18
1 files changed, 9 insertions, 9 deletions
diff --git a/examples/ini/ini.tm b/examples/ini/ini.tm
index c24cb4b9..4dc27725 100644
--- a/examples/ini/ini.tm
+++ b/examples/ini/ini.tm
@@ -10,23 +10,23 @@ _HELP := "
"
func parse_ini(path:Path -> {Text={Text=Text}})
- text := path.read() or exit("Could not read INI file: $\[31;1]$(path)$\[]")
+ text := path.read() or exit("Could not read INI file: \[31;1]$(path)\[]")
sections : @{Text=@{Text=Text}}
current_section : @{Text=Text}
# Line wraps:
- text = text.replace_pattern($Pat/\{1 nl}{0+space}/, " ")
+ text = text.replace_pattern($Pat/\\{1 nl}{0+space}/, " ")
for line in text.lines()
line = line.trim()
skip if line.starts_with(";") or line.starts_with("#")
if line.matches_pattern($Pat/[?]/)
- section_name := line.replace($Pat/[?]/, "\1").trim().lower()
+ section_name := line.replace($Pat/[?]/, "@1").trim().lower()
current_section = @{}
sections[section_name] = current_section
else if line.matches_pattern($Pat/{..}={..}/)
- key := line.replace_pattern($Pat/{..}={..}/, "\1").trim().lower()
- value := line.replace_pattern($Pat/{..}={..}/, "\2").trim()
+ key := line.replace_pattern($Pat/{..}={..}/, "@1").trim().lower()
+ value := line.replace_pattern($Pat/{..}={..}/, "@2").trim()
current_section[key] = value
return {k=v[] for k,v in sections[]}
@@ -46,8 +46,8 @@ func main(path:Path, key:Text?)
section := keys[1].lower()
section_data := data[section] or exit("
- Invalid section name: $\[31;1]$section$\[]
- Valid names: $\[1]$(", ".join([k.quoted() for k in data.keys]))$\[]
+ Invalid section name: \[31;1]$section\[]
+ Valid names: \[1]$(", ".join([k.quoted() for k in data.keys]))\[]
")
if keys.length < 2 or keys[2] == '*'
say("$section_data")
@@ -55,7 +55,7 @@ func main(path:Path, key:Text?)
section_key := keys[2].lower()
value := section_data[section_key] or exit("
- Invalid key: $\[31;1]$section_key$\[]
- Valid keys: $\[1]$(", ".join([s.quoted() for s in section_data.keys]))$\[]
+ Invalid key: \[31;1]$section_key\[]
+ Valid keys: \[1]$(", ".join([s.quoted() for s in section_data.keys]))\[]
")
say(value)