diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-01 15:15:28 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-01 15:15:28 -0400 |
| commit | d888bec4095170d159c488292ba098b243c0a44e (patch) | |
| tree | 0d0ff7c2e2c4ed75519ee32ec6482e04b1e68b3d /examples/ini/ini.tm | |
| parent | 354ed77535d17f2fc71780f1aaeb7ebfb80307d4 (diff) | |
Clean up and improve patterns
Diffstat (limited to 'examples/ini/ini.tm')
| -rw-r--r-- | examples/ini/ini.tm | 15 |
1 files changed, 9 insertions, 6 deletions
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 <filename> "[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[]} |
