aboutsummaryrefslogtreecommitdiff
path: root/examples/ini
diff options
context:
space:
mode:
Diffstat (limited to 'examples/ini')
-rw-r--r--examples/ini/CHANGES.md5
-rw-r--r--examples/ini/ini.tm61
-rw-r--r--examples/ini/modules.ini2
-rw-r--r--examples/ini/test.ini8
4 files changed, 0 insertions, 76 deletions
diff --git a/examples/ini/CHANGES.md b/examples/ini/CHANGES.md
deleted file mode 100644
index 42ae752c..00000000
--- a/examples/ini/CHANGES.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# Version History
-
-## v1.0
-
-Initial version
diff --git a/examples/ini/ini.tm b/examples/ini/ini.tm
deleted file mode 100644
index 4dc27725..00000000
--- a/examples/ini/ini.tm
+++ /dev/null
@@ -1,61 +0,0 @@
-
-use patterns
-
-_USAGE := "
- Usage: ini <filename> "[section[/key]]"
-"
-_HELP := "
- ini: A .ini config file reader tool.
- $_USAGE
-"
-
-func parse_ini(path:Path -> {Text={Text=Text}})
- 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}/, " ")
-
- 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()
- 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()
- current_section[key] = value
-
- return {k=v[] for k,v in sections[]}
-
-func main(path:Path, key:Text?)
- keys := (key or "").split($|/|)
- if keys.length > 2
- exit("
- Too many arguments!
- $_USAGE
- ")
-
- data := parse_ini(path)
- if keys.length < 1 or keys[1] == '*'
- say("$data")
- return
-
- 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]))\[]
- ")
- if keys.length < 2 or keys[2] == '*'
- say("$section_data")
- return
-
- 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]))\[]
- ")
- say(value)
diff --git a/examples/ini/modules.ini b/examples/ini/modules.ini
deleted file mode 100644
index fb52a859..00000000
--- a/examples/ini/modules.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[patterns]
-version=v1.0
diff --git a/examples/ini/test.ini b/examples/ini/test.ini
deleted file mode 100644
index 782dc76f..00000000
--- a/examples/ini/test.ini
+++ /dev/null
@@ -1,8 +0,0 @@
-[ Book ]
-title = Dirk Gently's Holistic Detective Agency
-author = Douglas Adams
-published = 1987
-
-[ Protagonist ]
-name = Dirk Gently
-age = 42