examples: add a template example, update the regex examples (#8829)
parent
6e262b5d84
commit
3f3bec45fa
|
@ -851,7 +851,7 @@ jobs:
|
|||
./v test-parser -S examples/cli.v
|
||||
./v test-parser -S examples/json.v
|
||||
./v test-parser -S examples/vmod.v
|
||||
./v test-parser -S examples/regex_example.v
|
||||
./v test-parser -S examples/regex/regex_example.v
|
||||
./v test-parser -S examples/2048/2048.v
|
||||
|
||||
parser-silent-fuzzing:
|
||||
|
@ -874,7 +874,7 @@ jobs:
|
|||
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/cli.v > examples/cli_fuzz.v
|
||||
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/json.v > examples/json_fuzz.v
|
||||
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/vmod.v > examples/vmod_fuzz.v
|
||||
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/regex_example.v > examples/regex_example_fuzz.v
|
||||
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/regex/regex_example.v > examples/regex_example_fuzz.v
|
||||
zzuf -R '\x00-\x20\x7f-\xff' -r0.01 < examples/2048/2048.v > examples/2048/2048_fuzz.v
|
||||
./v test-parser -S examples/hello_world_fuzz.v
|
||||
./v test-parser -S examples/hanoi_fuzz.v
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
module main
|
||||
|
||||
// NB: you need to `v install pcre` to be able to compile this example.
|
||||
|
||||
import pcre
|
||||
|
||||
fn example() {
|
||||
r := pcre.new_regex('Match everything after this: (.+)', 0) or {
|
||||
println('An error occured!')
|
||||
return
|
||||
}
|
||||
|
||||
m := r.match_str('Match everything after this: "I ❤️ VLang!"', 0, 0) or {
|
||||
println('No match!')
|
||||
return
|
||||
}
|
||||
|
||||
// m.get(0) -> Match everything after this: "I ❤️ VLang!"
|
||||
// m.get(1) -> "I ❤️ VLang!"'
|
||||
// m.get(2) -> Error!
|
||||
whole_match := m.get(0) or {
|
||||
println('We matched nothing...')
|
||||
return
|
||||
}
|
||||
|
||||
matched_str := m.get(1) or {
|
||||
println('We matched nothing...')
|
||||
return
|
||||
}
|
||||
|
||||
println(whole_match) // Match everything after this: "I ❤️ VLang!"
|
||||
println(matched_str) // "I ❤️ VLang!"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
example()
|
||||
|
||||
mut text := '[ an s. s! ]( wi4ki:something )
|
||||
[ an s. s! ]( wi4ki:something )
|
||||
[ an s. s! ](wiki:something)
|
||||
[ an s. s! ](something)dd
|
||||
d [ an s. s! ](something ) d
|
||||
[ more text ]( something ) s [ something b ](something)dd
|
||||
|
||||
'
|
||||
|
||||
// check the regex on https://regex101.com/r/HdYya8/1/
|
||||
|
||||
regex := r'(\[[a-z\.\! ]*\]\( *\w*\:*\w* *\))*'
|
||||
|
||||
r := pcre.new_regex(regex, 0) or {
|
||||
println('An error occured!')
|
||||
return
|
||||
}
|
||||
|
||||
m := r.match_str(text, 0, 0) or {
|
||||
println('No match!')
|
||||
return
|
||||
}
|
||||
|
||||
whole_match1 := m.get(0) or {
|
||||
println('We matched nothing 0...')
|
||||
return
|
||||
}
|
||||
|
||||
println(whole_match1)
|
||||
|
||||
println(m.get_all())
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
# regex
|
||||
|
||||
There are 2 ways to do regex:
|
||||
a) using the native module called `regex`
|
||||
b) using an exteranl module called `pcre`, which wraps the C library pcre.
|
||||
NB: you need to first do: `v install pcre`, for the `pcre` module to work.
|
||||
|
||||
You can find examples of both in this directory.
|
|
@ -23,18 +23,18 @@ fn convert_html_rgb(in_col string) u32 {
|
|||
// NOTE: if you want use escaped code you must use the r"" (raw) strings,
|
||||
// *** please remember that V interpoaltion doesn't work on raw strings. ***
|
||||
|
||||
query:= "#([a-fA-F0-9]{$n_digit})([a-fA-F0-9]{$n_digit})([a-fA-F0-9]{$n_digit})"
|
||||
query := '#([a-fA-F0-9]{$n_digit})([a-fA-F0-9]{$n_digit})([a-fA-F0-9]{$n_digit})'
|
||||
|
||||
mut re := regex.regex_opt(query) or { panic(err) }
|
||||
start, end := re.match_string(in_col)
|
||||
println("start: $start, end: $end")
|
||||
println('start: $start, end: $end')
|
||||
mut res := u32(0)
|
||||
if start >= 0 {
|
||||
group_list := re.get_group_list()
|
||||
r := ("0x" + in_col[group_list[0].start..group_list[0].end]).int() << col_mul
|
||||
g := ("0x" + in_col[group_list[1].start..group_list[1].end]).int() << col_mul
|
||||
b := ("0x" + in_col[group_list[2].start..group_list[2].end]).int() << col_mul
|
||||
println("r: $r g: $g b: $b")
|
||||
r := ('0x' + in_col[group_list[0].start..group_list[0].end]).int() << col_mul
|
||||
g := ('0x' + in_col[group_list[1].start..group_list[1].end]).int() << col_mul
|
||||
b := ('0x' + in_col[group_list[2].start..group_list[2].end]).int() << col_mul
|
||||
println('r: $r g: $g b: $b')
|
||||
res = u32(r) << 16 | u32(g) << 8 | u32(b)
|
||||
}
|
||||
return res
|
||||
|
@ -47,23 +47,23 @@ fn convert_html_rgb_n(in_col string) u32 {
|
|||
mut n_digit := if in_col.len == 4 { 1 } else { 2 }
|
||||
mut col_mul := if in_col.len == 4 { 4 } else { 0 }
|
||||
|
||||
query:= "#(?P<red>[a-fA-F0-9]{$n_digit})(?P<green>[a-fA-F0-9]{$n_digit})(?P<blue>[a-fA-F0-9]{$n_digit})"
|
||||
query := '#(?P<red>[a-fA-F0-9]{$n_digit})(?P<green>[a-fA-F0-9]{$n_digit})(?P<blue>[a-fA-F0-9]{$n_digit})'
|
||||
|
||||
mut re := regex.regex_opt(query) or { panic(err) }
|
||||
start, end := re.match_string(in_col)
|
||||
println("start: $start, end: $end")
|
||||
println('start: $start, end: $end')
|
||||
mut res := u32(0)
|
||||
if start >= 0 {
|
||||
red_s, red_e := re.get_group_bounds_by_name("red")
|
||||
r := ("0x" + in_col[red_s..red_e]).int() << col_mul
|
||||
|
||||
green_s, green_e := re.get_group_bounds_by_name("green")
|
||||
g := ("0x" + in_col[green_s..green_e]).int() << col_mul
|
||||
|
||||
blue_s, blue_e := re.get_group_bounds_by_name("blue")
|
||||
b := ("0x" + in_col[blue_s..blue_e]).int() << col_mul
|
||||
|
||||
println("r: $r g: $g b: $b")
|
||||
red_s, red_e := re.get_group_bounds_by_name('red')
|
||||
r := ('0x' + in_col[red_s..red_e]).int() << col_mul
|
||||
|
||||
green_s, green_e := re.get_group_bounds_by_name('green')
|
||||
g := ('0x' + in_col[green_s..green_e]).int() << col_mul
|
||||
|
||||
blue_s, blue_e := re.get_group_bounds_by_name('blue')
|
||||
b := ('0x' + in_col[blue_s..blue_e]).int() << col_mul
|
||||
|
||||
println('r: $r g: $g b: $b')
|
||||
res = u32(r) << 16 | u32(g) << 8 | u32(b)
|
||||
}
|
||||
return res
|
||||
|
@ -71,10 +71,10 @@ fn convert_html_rgb_n(in_col string) u32 {
|
|||
|
||||
fn main() {
|
||||
// convert HTML rgb color using groups
|
||||
println(convert_html_rgb("#A0b0Cc").hex())
|
||||
println(convert_html_rgb("#ABC").hex())
|
||||
println(convert_html_rgb('#A0b0Cc').hex())
|
||||
println(convert_html_rgb('#ABC').hex())
|
||||
|
||||
// convert HTML rgb color using named groups
|
||||
println(convert_html_rgb_n("#A0B0CC").hex())
|
||||
println(convert_html_rgb_n("#ABC").hex())
|
||||
println(convert_html_rgb_n('#A0B0CC').hex())
|
||||
println(convert_html_rgb_n('#ABC').hex())
|
||||
}
|
|
@ -23,8 +23,8 @@ fn regex_match_core(src string, pat string, src_pos int, pat_pos int, mut memo [
|
|||
if pat[ppos] == `\\` {
|
||||
ppos++
|
||||
}
|
||||
res := ppos + 1 < pat.len &&
|
||||
pat[ppos + 1] in [`*`, `?`] && regex_match_core(src, pat, spos, ppos + 2, mut memo)
|
||||
res := ppos + 1 < pat.len && pat[ppos + 1] in [`*`, `?`]
|
||||
&& regex_match_core(src, pat, spos, ppos + 2, mut memo)
|
||||
memo[src_pos][pat_pos] = if res { 1 } else { 0 }
|
||||
return res
|
||||
} else {
|
||||
|
@ -32,27 +32,28 @@ fn regex_match_core(src string, pat string, src_pos int, pat_pos int, mut memo [
|
|||
if first_is_bslash {
|
||||
ppos++
|
||||
}
|
||||
first_bslash_and_match := first_is_bslash && ppos < pat.len &&
|
||||
(((pat[ppos] == `d` && src[spos].is_digit()) ||
|
||||
(pat[ppos] == `D` && !src[spos].is_digit()) ||
|
||||
(pat[ppos] == `s` && src[spos].is_space()) ||
|
||||
(pat[ppos] == `S` && !src[spos].is_space()) ||
|
||||
(pat[ppos] == `w` && (src[spos].is_digit() || src[spos].is_letter() || src[spos] == `_`)) ||
|
||||
(pat[ppos] == `W` && !(src[spos].is_digit() || src[spos].is_letter() || src[spos] == `_`))) ||
|
||||
(pat[ppos] in [`d`, `D`, `s`, `S`, `w`, `W`] &&
|
||||
ppos + 1 < pat.len && pat[ppos + 1] in [`*`, `?`, `+`]) ||
|
||||
(pat[ppos] !in [`d`, `D`, `s`, `S`, `w`, `W`] && src[spos] == pat[ppos]))
|
||||
first_bslash_and_match := first_is_bslash && ppos < pat.len
|
||||
&& (((pat[ppos] == `d` && src[spos].is_digit())
|
||||
|| (pat[ppos] == `D` && !src[spos].is_digit())
|
||||
|| (pat[ppos] == `s` && src[spos].is_space())
|
||||
|| (pat[ppos] == `S` && !src[spos].is_space())
|
||||
|| (pat[ppos] == `w` && (src[spos].is_digit() || src[spos].is_letter()
|
||||
|| src[spos] == `_`)) || (pat[ppos] == `W` && !(src[spos].is_digit()
|
||||
|| src[spos].is_letter() || src[spos] == `_`)))
|
||||
|| (pat[ppos] in [`d`, `D`, `s`, `S`, `w`, `W`] && ppos + 1 < pat.len
|
||||
&& pat[ppos + 1] in [`*`, `?`, `+`])
|
||||
|| (pat[ppos] !in [`d`, `D`, `s`, `S`, `w`, `W`] && src[spos] == pat[ppos]))
|
||||
if ppos + 1 < pat.len {
|
||||
match pat[ppos + 1] {
|
||||
`*` {
|
||||
if first_bslash_and_match {
|
||||
res := regex_match_core(src, pat, spos + 1, ppos - 1, mut memo) || regex_match_core(src, pat, spos, ppos +
|
||||
2, mut memo)
|
||||
res := regex_match_core(src, pat, spos + 1, ppos - 1, mut memo)
|
||||
|| regex_match_core(src, pat, spos, ppos + 2, mut memo)
|
||||
memo[src_pos][pat_pos] = if res { 1 } else { 0 }
|
||||
return res
|
||||
} else if src[spos] == pat[ppos] || pat[ppos] == `.` {
|
||||
res := regex_match_core(src, pat, spos + 1, ppos, mut memo) || regex_match_core(src, pat, spos, ppos +
|
||||
2, mut memo)
|
||||
res := regex_match_core(src, pat, spos + 1, ppos, mut memo)
|
||||
|| regex_match_core(src, pat, spos, ppos + 2, mut memo)
|
||||
memo[src_pos][pat_pos] = if res { 1 } else { 0 }
|
||||
return res
|
||||
} else {
|
||||
|
@ -63,13 +64,13 @@ fn regex_match_core(src string, pat string, src_pos int, pat_pos int, mut memo [
|
|||
}
|
||||
`+` {
|
||||
if first_bslash_and_match {
|
||||
res := regex_match_core(src, pat, spos + 1, ppos - 1, mut memo) || regex_match_core(src, pat, spos +
|
||||
1, ppos + 2, mut memo)
|
||||
res := regex_match_core(src, pat, spos + 1, ppos - 1, mut memo)
|
||||
|| regex_match_core(src, pat, spos + 1, ppos + 2, mut memo)
|
||||
memo[src_pos][pat_pos] = if res { 1 } else { 0 }
|
||||
return res
|
||||
} else if src[spos] == pat[ppos] || pat[ppos] == `.` {
|
||||
res := regex_match_core(src, pat, spos + 1, ppos, mut memo) || regex_match_core(src, pat, spos +
|
||||
1, ppos + 2, mut memo)
|
||||
res := regex_match_core(src, pat, spos + 1, ppos, mut memo)
|
||||
|| regex_match_core(src, pat, spos + 1, ppos + 2, mut memo)
|
||||
memo[src_pos][pat_pos] = if res { 1 } else { 0 }
|
||||
return res
|
||||
} else {
|
||||
|
@ -79,8 +80,8 @@ fn regex_match_core(src string, pat string, src_pos int, pat_pos int, mut memo [
|
|||
}
|
||||
`?` {
|
||||
if first_bslash_and_match || src[spos] == pat[ppos] || pat[ppos] == `.` {
|
||||
res := regex_match_core(src, pat, spos + 1, ppos + 2, mut memo) || regex_match_core(src, pat, spos, ppos +
|
||||
2, mut memo)
|
||||
res := regex_match_core(src, pat, spos + 1, ppos + 2, mut memo)
|
||||
|| regex_match_core(src, pat, spos, ppos + 2, mut memo)
|
||||
memo[src_pos][pat_pos] = if res { 1 } else { 0 }
|
||||
return res
|
||||
} else {
|
||||
|
@ -93,13 +94,13 @@ fn regex_match_core(src string, pat string, src_pos int, pat_pos int, mut memo [
|
|||
}
|
||||
}
|
||||
if first_is_bslash {
|
||||
res := first_bslash_and_match && regex_match_core(src, pat, spos + 1, ppos + 1, mut memo)
|
||||
res := first_bslash_and_match
|
||||
&& regex_match_core(src, pat, spos + 1, ppos + 1, mut memo)
|
||||
memo[src_pos][pat_pos] = if res { 1 } else { 0 }
|
||||
return res
|
||||
} else {
|
||||
res := (src[spos] == pat[ppos] ||
|
||||
pat[ppos] == `.`) &&
|
||||
pat[ppos] != `\\` && regex_match_core(src, pat, spos + 1, ppos + 1, mut memo)
|
||||
res := (src[spos] == pat[ppos] || pat[ppos] == `.`) && pat[ppos] != `\\`
|
||||
&& regex_match_core(src, pat, spos + 1, ppos + 1, mut memo)
|
||||
memo[src_pos][pat_pos] = if res { 1 } else { 0 }
|
||||
return res
|
||||
}
|
|
@ -0,0 +1,197 @@
|
|||
[
|
||||
{
|
||||
"name": "www_threefold_io",
|
||||
"url": "https://github.com/threefoldfoundation/www_threefold_io",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 2,
|
||||
"alias": "tf",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_io",
|
||||
"domains": [
|
||||
"www.threefold.io",
|
||||
"www.threefold.me"
|
||||
],
|
||||
"descr": "is our entry point for everyone, redirect to the detailed websites underneith."
|
||||
},
|
||||
{
|
||||
"name": "www_threefold_cloud",
|
||||
"url": "https://github.com/threefoldfoundation/www_threefold_cloud",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 2,
|
||||
"alias": "cloud",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_cloud",
|
||||
"domains": [
|
||||
"cloud.threefold.io",
|
||||
"cloud.threefold.me"
|
||||
],
|
||||
"descr": "for people looking to deploy solutions on top of a cloud, alternative to e.g. digital ocean"
|
||||
},
|
||||
{
|
||||
"name": "www_threefold_farming",
|
||||
"url": "https://github.com/threefoldfoundation/www_threefold_farming",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 2,
|
||||
"alias": "farming",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_farming",
|
||||
"domains": [
|
||||
"farming.threefold.io",
|
||||
"farming.threefold.me"
|
||||
],
|
||||
"descr": "crypto & minining enthusiasts, be the internet, know about farming & tokens."
|
||||
},
|
||||
{
|
||||
"name": "www_threefold_twin",
|
||||
"url": "https://github.com/threefoldfoundation/www_threefold_twin",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 2,
|
||||
"alias": "twin",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_twin",
|
||||
"domains": [
|
||||
"twin.threefold.io",
|
||||
"twin.threefold.me"
|
||||
],
|
||||
"descr": "you digital life"
|
||||
},
|
||||
{
|
||||
"name": "www_threefold_marketplace",
|
||||
"url": "https://github.com/threefoldfoundation/www_threefold_marketplace",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 2,
|
||||
"alias": "marketplace",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_marketplace",
|
||||
"domains": [
|
||||
"now.threefold.io",
|
||||
"marketplace.threefold.io",
|
||||
"now.threefold.me",
|
||||
"marketplace.threefold.me"
|
||||
],
|
||||
"descr": "apps for community builders, runs on top of evdc"
|
||||
},
|
||||
{
|
||||
"name": "www_conscious_internet",
|
||||
"url": "https://github.com/threefoldfoundation/www_conscious_internet",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 2,
|
||||
"alias": "conscious_internet",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/www_conscious_internet",
|
||||
"domains": [
|
||||
"www.consciousinternet.org",
|
||||
"eco.threefold.io",
|
||||
"community.threefold.io",
|
||||
"eco.threefold.me",
|
||||
"community.threefold.me"
|
||||
],
|
||||
"descr": "community around threefold, partners, friends, ..."
|
||||
},
|
||||
{
|
||||
"name": "www_threefold_tech",
|
||||
"url": "https://github.com/threefoldtech/www_threefold_tech",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 2,
|
||||
"alias": "tech",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldtech/www_threefold_tech",
|
||||
"domains": [
|
||||
"www.threefold.tech"
|
||||
],
|
||||
"descr": "cyberpandemic, use the tech to build your own solutions with, certification for TFGrid"
|
||||
},
|
||||
{
|
||||
"name": "www_examplesite",
|
||||
"url": "https://github.com/threefoldfoundation/www_examplesite",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 2,
|
||||
"alias": "example",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/www_examplesite",
|
||||
"domains": [
|
||||
"example.threefold.io"
|
||||
],
|
||||
"descr": ""
|
||||
},
|
||||
{
|
||||
"name": "info_threefold",
|
||||
"url": "https://github.com/threefoldfoundation/info_foundation_archive",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 0,
|
||||
"alias": "threefold",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/info_foundation_archive",
|
||||
"domains": [
|
||||
"info.threefold.io"
|
||||
],
|
||||
"descr": "wiki for foundation, collaborate, what if farmings, tokens"
|
||||
},
|
||||
{
|
||||
"name": "info_sdk",
|
||||
"url": "https://github.com/threefoldfoundation/info_sdk",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 0,
|
||||
"alias": "sdk",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/info_sdk",
|
||||
"domains": [
|
||||
"sdk.threefold.io",
|
||||
"sdk_info.threefold.io"
|
||||
],
|
||||
"descr": "for IAC, devops, how to do Infrastruture As Code, 3bot, Ansible, tfgrid-sdk, ..."
|
||||
},
|
||||
{
|
||||
"name": "info_legal",
|
||||
"url": "https://github.com/threefoldfoundation/info_legal",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 0,
|
||||
"alias": "legal",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/info_legal",
|
||||
"domains": [
|
||||
"legal.threefold.io",
|
||||
"legal_info.threefold.io"
|
||||
],
|
||||
"descr": ""
|
||||
},
|
||||
{
|
||||
"name": "info_cloud",
|
||||
"url": "https://github.com/threefoldfoundation/info_cloud",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 0,
|
||||
"alias": "cloud",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/info_cloud",
|
||||
"domains": [
|
||||
"cloud_info.threefold.io"
|
||||
],
|
||||
"descr": "how to use the cloud for deploying apps: evdc, kubernetes, planetary fs, ... + marketplace solutions "
|
||||
},
|
||||
{
|
||||
"name": "info_tftech",
|
||||
"url": "https://github.com/threefoldtech/info_tftech",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 0,
|
||||
"alias": "tftech",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldtech/info_tftech",
|
||||
"domains": [
|
||||
"info.threefold.tech"
|
||||
],
|
||||
"descr": ""
|
||||
},
|
||||
{
|
||||
"name": "info_digitaltwin",
|
||||
"url": "https://github.com/threefoldfoundation/info_digitaltwin.git",
|
||||
"branch": "default",
|
||||
"pull": false,
|
||||
"cat": 0,
|
||||
"alias": "twin",
|
||||
"path_code": "/Users/despiegk/codewww/github/threefoldfoundation/info_digitaltwin",
|
||||
"domains": [
|
||||
"twin_info.threefold.io"
|
||||
],
|
||||
"descr": ""
|
||||
}
|
||||
]
|
|
@ -0,0 +1,14 @@
|
|||
# example how to work with templates
|
||||
|
||||
- templates support
|
||||
- if
|
||||
- for loops
|
||||
- even nesting of for loops
|
||||
- syntax checking
|
||||
- embed the template into the binary
|
||||
|
||||
Its a very cool way how to do also do e.g. system administration, fill in
|
||||
config files, etc...
|
||||
|
||||
The example there is also a good demonstration of how to use json on a more
|
||||
complex object and read/write to file.
|
|
@ -0,0 +1,101 @@
|
|||
# WIKIs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## info.threefold.io80
|
||||
|
||||
- [errors]("//info.threefold.io80/errors")
|
||||
|
||||
### domains
|
||||
|
||||
|
||||
- info.threefold.io
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## sdk.threefold.io80
|
||||
|
||||
- [errors]("//sdk.threefold.io80/errors")
|
||||
|
||||
### domains
|
||||
|
||||
|
||||
- sdk.threefold.io
|
||||
|
||||
- sdk_info.threefold.io
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## legal.threefold.io80
|
||||
|
||||
- [errors]("//legal.threefold.io80/errors")
|
||||
|
||||
### domains
|
||||
|
||||
|
||||
- legal.threefold.io
|
||||
|
||||
- legal_info.threefold.io
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## cloud_info.threefold.io80
|
||||
|
||||
- [errors]("//cloud_info.threefold.io80/errors")
|
||||
|
||||
### domains
|
||||
|
||||
|
||||
- cloud_info.threefold.io
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## info.threefold.tech80
|
||||
|
||||
- [errors]("//info.threefold.tech80/errors")
|
||||
|
||||
### domains
|
||||
|
||||
|
||||
- info.threefold.tech
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## twin_info.threefold.io80
|
||||
|
||||
- [errors]("//twin_info.threefold.io80/errors")
|
||||
|
||||
### domains
|
||||
|
||||
|
||||
- twin_info.threefold.io
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
# WIKIs
|
||||
|
||||
@for site in sites
|
||||
@if site.cat == .wiki
|
||||
|
||||
## @{site.domains[0]}@port_str
|
||||
|
||||
- [errors]("//@{site.domains[0]}@port_str/errors")
|
||||
|
||||
### domains
|
||||
|
||||
@for dom in site.domains
|
||||
- @dom
|
||||
@end
|
||||
@end
|
||||
@end
|
|
@ -0,0 +1,196 @@
|
|||
module main
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
pub struct SiteConfig {
|
||||
pub mut:
|
||||
name string
|
||||
url string
|
||||
branch string = 'default' // means is the default branch
|
||||
pull bool
|
||||
cat SiteCat
|
||||
alias string
|
||||
path_code string
|
||||
domains []string
|
||||
descr string
|
||||
}
|
||||
|
||||
pub enum SiteCat {
|
||||
wiki
|
||||
data
|
||||
web
|
||||
}
|
||||
|
||||
fn data_get() []SiteConfig {
|
||||
data := [SiteConfig{
|
||||
name: 'www_threefold_io'
|
||||
url: 'https://github.com/threefoldfoundation/www_threefold_io'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .web
|
||||
alias: 'tf'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_io'
|
||||
domains: ['www.threefold.io', 'www.threefold.me']
|
||||
descr: 'is our entry point for everyone, redirect to the detailed websites underneith.'
|
||||
}, SiteConfig{
|
||||
name: 'www_threefold_cloud'
|
||||
url: 'https://github.com/threefoldfoundation/www_threefold_cloud'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .web
|
||||
alias: 'cloud'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_cloud'
|
||||
domains: ['cloud.threefold.io', 'cloud.threefold.me']
|
||||
descr: 'for people looking to deploy solutions on top of a cloud, alternative to e.g. digital ocean'
|
||||
}, SiteConfig{
|
||||
name: 'www_threefold_farming'
|
||||
url: 'https://github.com/threefoldfoundation/www_threefold_farming'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .web
|
||||
alias: 'farming'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_farming'
|
||||
domains: ['farming.threefold.io', 'farming.threefold.me']
|
||||
descr: 'crypto & minining enthusiasts, be the internet, know about farming & tokens.'
|
||||
}, SiteConfig{
|
||||
name: 'www_threefold_twin'
|
||||
url: 'https://github.com/threefoldfoundation/www_threefold_twin'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .web
|
||||
alias: 'twin'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_twin'
|
||||
domains: ['twin.threefold.io', 'twin.threefold.me']
|
||||
descr: 'you digital life'
|
||||
}, SiteConfig{
|
||||
name: 'www_threefold_marketplace'
|
||||
url: 'https://github.com/threefoldfoundation/www_threefold_marketplace'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .web
|
||||
alias: 'marketplace'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_threefold_marketplace'
|
||||
domains: ['now.threefold.io', 'marketplace.threefold.io', 'now.threefold.me', 'marketplace.threefold.me']
|
||||
descr: 'apps for community builders, runs on top of evdc'
|
||||
}, SiteConfig{
|
||||
name: 'www_conscious_internet'
|
||||
url: 'https://github.com/threefoldfoundation/www_conscious_internet'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .web
|
||||
alias: 'conscious_internet'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_conscious_internet'
|
||||
domains: ['www.consciousinternet.org', 'eco.threefold.io', 'community.threefold.io', 'eco.threefold.me',
|
||||
'community.threefold.me',
|
||||
]
|
||||
descr: 'community around threefold, partners, friends, ...'
|
||||
}, SiteConfig{
|
||||
name: 'www_threefold_tech'
|
||||
url: 'https://github.com/threefoldtech/www_threefold_tech'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .web
|
||||
alias: 'tech'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldtech/www_threefold_tech'
|
||||
domains: ['www.threefold.tech']
|
||||
descr: 'cyberpandemic, use the tech to build your own solutions with, certification for TFGrid'
|
||||
}, SiteConfig{
|
||||
name: 'www_examplesite'
|
||||
url: 'https://github.com/threefoldfoundation/www_examplesite'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .web
|
||||
alias: 'example'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/www_examplesite'
|
||||
domains: ['example.threefold.io']
|
||||
descr: ''
|
||||
}, SiteConfig{
|
||||
name: 'info_threefold'
|
||||
url: 'https://github.com/threefoldfoundation/info_foundation_archive'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .wiki
|
||||
alias: 'threefold'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/info_foundation_archive'
|
||||
domains: ['info.threefold.io']
|
||||
descr: 'wiki for foundation, collaborate, what if farmings, tokens'
|
||||
}, SiteConfig{
|
||||
name: 'info_sdk'
|
||||
url: 'https://github.com/threefoldfoundation/info_sdk'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .wiki
|
||||
alias: 'sdk'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/info_sdk'
|
||||
domains: ['sdk.threefold.io', 'sdk_info.threefold.io']
|
||||
descr: 'for IAC, devops, how to do Infrastruture As Code, 3bot, Ansible, tfgrid-sdk, ...'
|
||||
}, SiteConfig{
|
||||
name: 'info_legal'
|
||||
url: 'https://github.com/threefoldfoundation/info_legal'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .wiki
|
||||
alias: 'legal'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/info_legal'
|
||||
domains: ['legal.threefold.io', 'legal_info.threefold.io']
|
||||
descr: ''
|
||||
}, SiteConfig{
|
||||
name: 'info_cloud'
|
||||
url: 'https://github.com/threefoldfoundation/info_cloud'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .wiki
|
||||
alias: 'cloud'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/info_cloud'
|
||||
domains: ['cloud_info.threefold.io']
|
||||
descr: 'how to use the cloud for deploying apps: evdc, kubernetes, planetary fs, ... + marketplace solutions '
|
||||
}, SiteConfig{
|
||||
name: 'info_tftech'
|
||||
url: 'https://github.com/threefoldtech/info_tftech'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .wiki
|
||||
alias: 'tftech'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldtech/info_tftech'
|
||||
domains: ['info.threefold.tech']
|
||||
descr: ''
|
||||
}, SiteConfig{
|
||||
name: 'info_digitaltwin'
|
||||
url: 'https://github.com/threefoldfoundation/info_digitaltwin.git'
|
||||
branch: 'default'
|
||||
pull: false
|
||||
cat: .wiki
|
||||
alias: 'twin'
|
||||
path_code: '/Users/despiegk/codewww/github/threefoldfoundation/info_digitaltwin'
|
||||
domains: ['twin_info.threefold.io']
|
||||
descr: ''
|
||||
}]
|
||||
return data
|
||||
}
|
||||
|
||||
fn data_dump(data []SiteConfig) {
|
||||
a := json.encode_pretty(data)
|
||||
os.write_file('data.json', a) or { panic(err) }
|
||||
}
|
||||
|
||||
fn data_load() []SiteConfig {
|
||||
data := os.read_file('data.json') or { panic(err) }
|
||||
a := json.decode([]SiteConfig, data) or { panic(err) }
|
||||
return a
|
||||
}
|
||||
|
||||
fn filled_in_template() string {
|
||||
port_str := '80'
|
||||
sites := data_load()
|
||||
return $tmpl('template.md')
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// A NICE test how to work with the json module
|
||||
// data := data_get()
|
||||
// data_dump(data)
|
||||
b := filled_in_template()
|
||||
println(b)
|
||||
os.write_file('result.md', b) or { panic(err) }
|
||||
}
|
|
@ -134,7 +134,7 @@ fn (mut p Parser) comp_call() ast.ComptimeCall {
|
|||
path += '.html'
|
||||
path = os.real_path(path)
|
||||
if !is_html {
|
||||
path = tmpl_path
|
||||
path = os.join_path(dir, tmpl_path)
|
||||
}
|
||||
if !os.exists(path) {
|
||||
// can be in `templates/`
|
||||
|
|
|
@ -2,7 +2,7 @@ fn one() string {
|
|||
name := 'Peter'
|
||||
age := 25
|
||||
numbers := [1, 2, 3]
|
||||
return $tmpl('vlib/v/tests/tmpl/1.txt')
|
||||
return $tmpl('tmpl/1.txt')
|
||||
}
|
||||
|
||||
fn test_tmpl() {
|
||||
|
|
Loading…
Reference in New Issue