Fix up examples
This commit is contained in:
parent
645d66e0de
commit
c60ea2079f
@ -29,7 +29,7 @@ lang Base64:
|
||||
return Base64.from_bytes(text:bytes())
|
||||
|
||||
func from_bytes(bytes:[Byte] -> Base64?):
|
||||
output := [Byte(0) for _ in bytes.length * 4 / 3 + 4]
|
||||
output := &[Byte(0) for _ in bytes.length * 4 / 3 + 4]
|
||||
src := Int64(1)
|
||||
dest := Int64(1)
|
||||
while src + 2 <= bytes.length:
|
||||
@ -59,14 +59,14 @@ lang Base64:
|
||||
output[dest+2] = _EQUAL_BYTE
|
||||
output[dest+3] = _EQUAL_BYTE
|
||||
|
||||
return Base64.without_escaping(Text.from_bytes(output) or return none)
|
||||
return Base64.without_escaping(Text.from_bytes(output[]) or return none)
|
||||
|
||||
func decode_text(b64:Base64 -> Text?):
|
||||
return Text.from_bytes(b64:decode_bytes() or return none)
|
||||
|
||||
func decode_bytes(b64:Base64 -> [Byte]?):
|
||||
bytes := b64.text_content:bytes()
|
||||
output := [Byte(0) for _ in bytes.length/4 * 3]
|
||||
output := &[Byte(0) for _ in bytes.length/4 * 3]
|
||||
src := Int64(1)
|
||||
dest := Int64(1)
|
||||
while src + 3 <= bytes.length:
|
||||
@ -84,9 +84,9 @@ lang Base64:
|
||||
dest += 3
|
||||
|
||||
while output[-1] == 0xFF:
|
||||
output = output:to(-2)
|
||||
output[] = output:to(-2)
|
||||
|
||||
return output
|
||||
return output[]
|
||||
|
||||
func main(input=(/dev/stdin), decode=no):
|
||||
if decode:
|
||||
|
@ -73,7 +73,7 @@ struct World(player:@Player, goal:@Box, boxes:@[@Box], dt_accum=0.0, won=no):
|
||||
|
||||
func load_map(w:@World, map:Text):
|
||||
if map:has($/[]/):
|
||||
map = map:replace_all({$/[]/: "#", $/@{1..}/: "@", $/ /: " "})
|
||||
map = map:replace_all({$/[]/="#", $/@{1..}/="@", $/ /=" "})
|
||||
w.boxes = @[:@Box]
|
||||
box_size := Vec2(50., 50.)
|
||||
for y,line in map:lines():
|
||||
|
@ -6,10 +6,10 @@ _HELP := "
|
||||
$_USAGE
|
||||
"
|
||||
|
||||
func parse_ini(path:Path -> {Text:{Text:Text}}):
|
||||
func parse_ini(path:Path -> {Text,{Text,Text}}):
|
||||
text := path:read() or exit("Could not read INI file: $\[31;1]$(path.text_content)$\[]")
|
||||
sections := @{:Text:@{Text:Text}}
|
||||
current_section := @{:Text:Text}
|
||||
sections := @{:Text,@{Text,Text}}
|
||||
current_section := @{:Text,Text}
|
||||
|
||||
# Line wraps:
|
||||
text = text:replace($/\{1 nl}{0+space}/, " ")
|
||||
@ -19,14 +19,14 @@ func parse_ini(path:Path -> {Text:{Text:Text}}):
|
||||
skip if line:starts_with(";") or line:starts_with("#")
|
||||
if line:matches($/[?]/):
|
||||
section_name := line:replace($/[?]/, "\1"):trim():lower()
|
||||
current_section = @{:Text:Text}
|
||||
current_section = @{:Text,Text}
|
||||
sections[section_name] = current_section
|
||||
else if line:matches($/{..}={..}/):
|
||||
key := line:replace($/{..}={..}/, "\1"):trim():lower()
|
||||
value := line:replace($/{..}={..}/, "\2"):trim()
|
||||
current_section[key] = value
|
||||
|
||||
return {k:v[] for k,v in sections[]}
|
||||
return {k=v[] for k,v in sections[]}
|
||||
|
||||
func main(path:Path, key:Text?):
|
||||
keys := (key or ""):split($|/|)
|
||||
|
@ -25,7 +25,7 @@ func _get_file_dependencies(file:Path -> {Dependency}):
|
||||
deps:add(Dependency.Module(module_name))
|
||||
return deps[]
|
||||
|
||||
func _build_dependency_graph(dep:Dependency, dependencies:@{Dependency:{Dependency}}):
|
||||
func _build_dependency_graph(dep:Dependency, dependencies:@{Dependency,{Dependency}}):
|
||||
return if dependencies:has(dep)
|
||||
|
||||
dependencies[dep] = {:Dependency} # Placeholder
|
||||
@ -55,8 +55,8 @@ func _build_dependency_graph(dep:Dependency, dependencies:@{Dependency:{Dependen
|
||||
for dep2 in dep_deps:
|
||||
_build_dependency_graph(dep2, dependencies)
|
||||
|
||||
func get_dependency_graph(dep:Dependency -> {Dependency:{Dependency}}):
|
||||
graph := @{:Dependency:{Dependency}}
|
||||
func get_dependency_graph(dep:Dependency -> {Dependency,{Dependency}}):
|
||||
graph := @{:Dependency,{Dependency}}
|
||||
_build_dependency_graph(dep, graph)
|
||||
return graph
|
||||
|
||||
@ -70,7 +70,7 @@ func _printable_name(dep:Dependency -> Text):
|
||||
else:
|
||||
return "$(\x1b)[31;1m$(f.text_content) (not found)$(\x1b)[m"
|
||||
|
||||
func _draw_tree(dep:Dependency, dependencies:{Dependency:{Dependency}}, already_printed:@{Dependency}, prefix="", is_last=yes):
|
||||
func _draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}, already_printed:@{Dependency}, prefix="", is_last=yes):
|
||||
if already_printed:has(dep):
|
||||
say(prefix ++ (if is_last: "└── " else: "├── ") ++ _printable_name(dep) ++ " $\x1b[2m(recursive)$\x1b[m")
|
||||
return
|
||||
@ -85,7 +85,7 @@ func _draw_tree(dep:Dependency, dependencies:{Dependency:{Dependency}}, already_
|
||||
is_child_last := (i == children.length)
|
||||
_draw_tree(child, dependencies, already_printed, child_prefix, is_child_last)
|
||||
|
||||
func draw_tree(dep:Dependency, dependencies:{Dependency:{Dependency}}):
|
||||
func draw_tree(dep:Dependency, dependencies:{Dependency,{Dependency}}):
|
||||
printed := @{:Dependency}
|
||||
say(_printable_name(dep))
|
||||
printed:add(dep)
|
||||
|
Loading…
Reference in New Issue
Block a user