From d888bec4095170d159c488292ba098b243c0a44e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 1 Apr 2025 15:15:28 -0400 Subject: Clean up and improve patterns --- examples/ini/ini.tm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'examples/ini') diff --git a/examples/ini/ini.tm b/examples/ini/ini.tm index 1c50ac37..1c90b715 100644 --- a/examples/ini/ini.tm +++ b/examples/ini/ini.tm @@ -1,3 +1,6 @@ + +use patterns + _USAGE := " Usage: ini "[section[/key]]" " @@ -12,18 +15,18 @@ func parse_ini(path:Path -> {Text,{Text,Text}}): current_section := @{:Text,Text} # Line wraps: - text = text:replace($/\{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($/[?]/): - section_name := line:replace($/[?]/, "\1"):trim():lower() + if line:matches_pattern($Pat/[?]/): + section_name := line:replace($Pat/[?]/, "\1"):trim():lower() current_section = @{:Text,Text} sections[section_name] = current_section - else if line:matches($/{..}={..}/): - key := line:replace($/{..}={..}/, "\1"):trim():lower() - value := line:replace($/{..}={..}/, "\2"):trim() + else if line:matches_pattern($Pat/{..}={..}/): + 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[]} -- cgit v1.2.3