mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
31 lines
743 B
Plaintext
31 lines
743 B
Plaintext
module madlibs;
|
|
import regex, stdio;
|
|
|
|
func void main()
|
|
{
|
|
println("Enter a story template, terminated by an empty line:");
|
|
string@ story = "";
|
|
while (1)
|
|
{
|
|
try string line = stdin.readln().strip();
|
|
if (!line.size) break;
|
|
story += line + "\n";
|
|
}
|
|
|
|
Regex* r = try regex::regexWithOptions("<.+?>", RegexOpt.GLOBAL) catch @unreachable;
|
|
|
|
foreach (RegexMatch* match : r.match(story))
|
|
{
|
|
string s = match.string;
|
|
printf("Enter a value for '%s': ", s.slice(1, s.size - 2));
|
|
try string word = strin.readln().strip();
|
|
story = story.replace(s, word);
|
|
}
|
|
|
|
println("\nThe story becomes:\n%s\n", story);
|
|
|
|
catch (error e)
|
|
{
|
|
// Ignore any error
|
|
}
|
|
} |