aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/colorful/CHANGES.md4
-rw-r--r--examples/colorful/colorful.tm6
-rw-r--r--examples/http-server/CHANGES.md4
-rw-r--r--examples/http-server/http-server.tm12
-rw-r--r--examples/ini/CHANGES.md4
-rw-r--r--examples/ini/ini.tm8
6 files changed, 25 insertions, 13 deletions
diff --git a/examples/colorful/CHANGES.md b/examples/colorful/CHANGES.md
index 093cc077..985e98a7 100644
--- a/examples/colorful/CHANGES.md
+++ b/examples/colorful/CHANGES.md
@@ -1,5 +1,9 @@
# Version History
+## v1.3
+
+- Version bump for Tomo syntax changes.
+
## v1.2
- Version bump for patterns.
diff --git a/examples/colorful/colorful.tm b/examples/colorful/colorful.tm
index 5b01cfd5..fed873fd 100644
--- a/examples/colorful/colorful.tm
+++ b/examples/colorful/colorful.tm
@@ -45,7 +45,7 @@ func main(texts:[Text], files:[Path]=[], by_line=no)
func _for_terminal(c:Colorful, state:_TermState -> Text)
- return c.text.map_pattern(recursive=no, $Pat/@(?)/, func(m:PatternMatch) _add_ansi_sequences(m.captures[1], state))
+ return c.text.map_pattern(recursive=no, $Pat/@(?)/, func(m:PatternMatch) _add_ansi_sequences(m.captures[1]!, state))
enum _Color(Default, Bright(color:Int16), Color8Bit(color:Int16), Color24Bit(color:Int32))
func from_text(text:Text -> _Color?)
@@ -174,7 +174,7 @@ func _add_ansi_sequences(text:Text, prev_state:_TermState -> Text)
text.pattern_captures($Pat/{0+..}:{0+..}/) or
return "@("++_for_terminal(Colorful.from_text(text), prev_state)++")"
)
- attributes := parts[1].split_pattern($Pat/{0+space},{0+space}/)
+ attributes := parts[1]!.split_pattern($Pat/{0+space},{0+space}/)
new_state := prev_state
for attr in attributes
if attr.starts_with("fg=")
@@ -215,6 +215,6 @@ func _add_ansi_sequences(text:Text, prev_state:_TermState -> Text)
fail("Invalid attribute: '$attr'")
result := prev_state.apply(new_state)
- result ++= parts[2].map_pattern(recursive=no, $Pat/@(?)/, func(m:PatternMatch) _add_ansi_sequences(m.captures[1], new_state))
+ result ++= parts[2]!.map_pattern(recursive=no, $Pat/@(?)/, func(m:PatternMatch) _add_ansi_sequences(m.captures[1]!, new_state))
result ++= new_state.apply(prev_state)
return result
diff --git a/examples/http-server/CHANGES.md b/examples/http-server/CHANGES.md
index 42ae752c..636f9296 100644
--- a/examples/http-server/CHANGES.md
+++ b/examples/http-server/CHANGES.md
@@ -1,5 +1,9 @@
# Version History
+## v1.1
+
+Version bump for Tomo syntax changes.
+
## v1.0
Initial version
diff --git a/examples/http-server/http-server.tm b/examples/http-server/http-server.tm
index 8e8aff7e..cc99b521 100644
--- a/examples/http-server/http-server.tm
+++ b/examples/http-server/http-server.tm
@@ -74,12 +74,12 @@ func serve(port:Int32, handler:func(request:HTTPRequest -> HTTPResponse), num_th
struct HTTPRequest(method:Text, path:Text, version:Text, headers:[Text], body:Text)
func from_text(text:Text -> HTTPRequest?)
m := text.pattern_captures($Pat'{word} {..} HTTP/{..}{crlf}{..}') or return none
- method := m[1]
- path := m[2].replace_pattern($Pat'{2+ /}', '/')
- version := m[3]
- rest := m[-1].pattern_captures($Pat/{..}{2 crlf}{0+ ..}/) or return none
- headers := rest[1].split_pattern($Pat/{crlf}/)
- body := rest[-1]
+ method := m[1]!
+ path := m[2]!.replace_pattern($Pat'{2+ /}', '/')
+ version := m[3]!
+ rest := m[-1]!.pattern_captures($Pat/{..}{2 crlf}{0+ ..}/) or return none
+ headers := rest[1]!.split_pattern($Pat/{crlf}/)
+ body := rest[-1]!
return HTTPRequest(method, path, version, headers, body)
struct HTTPResponse(body:Text, status=200, content_type="text/plain", headers:{Text=Text}={})
diff --git a/examples/ini/CHANGES.md b/examples/ini/CHANGES.md
index 42ae752c..636f9296 100644
--- a/examples/ini/CHANGES.md
+++ b/examples/ini/CHANGES.md
@@ -1,5 +1,9 @@
# Version History
+## v1.1
+
+Version bump for Tomo syntax changes.
+
## v1.0
Initial version
diff --git a/examples/ini/ini.tm b/examples/ini/ini.tm
index 4dc27725..790b3abc 100644
--- a/examples/ini/ini.tm
+++ b/examples/ini/ini.tm
@@ -40,20 +40,20 @@ func main(path:Path, key:Text?)
")
data := parse_ini(path)
- if keys.length < 1 or keys[1] == '*'
+ if keys.length < 1 or keys[1]! == '*'
say("$data")
return
- section := keys[1].lower()
+ 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] == '*'
+ if keys.length < 2 or keys[2]! == '*'
say("$section_data")
return
- section_key := keys[2].lower()
+ 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]))\[]