diff --git a/doc/ideas/MatchRange.v3 b/doc/ideas/MatchRange.v3 new file mode 100644 index 000000000..6934b367f --- /dev/null +++ b/doc/ideas/MatchRange.v3 @@ -0,0 +1,36 @@ +//Idea: allow matching within a range and the rest of a range + +type T { + case A(f: int); + case B(g: int); +} + +def m(t: Range) -> (int, Range) { + match (t) { + A(f) ... rest => return (f + 77, rest); // "rest" has type Range + B(g) ... rest => return (g + 99, rest); // "rest" has type Range + } +} + +def keywords(str: Range) -> (int, Range) { + match(str) { + "if" ... rest => return (11, rest); + "case" ... rest => return (12, rest); + "match" ... rest => return (13, rest); + } + return (-1, str); +} + +def parse_literal(str: Range) -> (Lit, Range) { + match (str) { + IntLiteralMatch(x) ... rest => (Lit.Int(x), rest); + BoolLiteralMatch(x) ... rest => (Lit.Bool(x), rest); + "case ${x: int} of foo" ... rest => (Lit.CaseInt(x), rest); + } +} + +def match(str: Range) -> IntLiteralMatch(x: int) { + for (i < str.length) ... + return false; + return (true, length, val) +}