1
0
forked from GitHub/gf-core

pattern matching on strings

This commit is contained in:
krangelov
2021-09-29 09:18:52 +02:00
parent fee186feca
commit 86326d282f
3 changed files with 101 additions and 20 deletions

View File

@@ -0,0 +1,23 @@
i -retain testsuite/compiler/compute/param_table.gf
cc "a b c"
cc case "abc" of {"abc" => Q1; _ => Q2}
cc case "def" of {"abc" => Q1; _ => Q2}
cc case "x" of {? => Q1; _ => Q2}
cc case "xy" of {? => Q1; _ => Q2}
cc case "x" of {["abc"] => Q1; _ => Q2}
cc case "b" of {["abc"] => Q1; _ => Q2}
cc case "xy" of {["abc"] => Q1; _ => Q2}
cc case "abc" of {"abc"|"xyz" => Q1; _ => Q2}
cc case "xyz" of {"abc"|"xyz" => Q1; _ => Q2}
cc case "def" of {"abc"|"xyz" => Q1; _ => Q2}
cc case <<"start","abc","end"> : Str*Str*Str> of {<s,m@("abc"|"xyz"),e> => s++m++e; _ => "zero"}
cc case <<"start","xyz","end"> : Str*Str*Str> of {<s,m@("abc"|"xyz"),e> => s++m++e; _ => "zero"}
cc case <<"start","def","end"> : Str*Str*Str> of {<s,m@("abc"|"xyz"),e> => s++m++e; _ => "zero"}
cc <case "abcdefghi" of {"abc"+x+"ghi" => x; _ => "?"} : Str>
cc <case "abcdef" of {"abc"+x+"ghi" => x; _ => "?"} : Str>
cc <case "defghi" of {"abc"+x+"ghi" => x; _ => "?"} : Str>
cc <case "abc def ghi" of {"ab"+x+"hi" => x; _ => "?"} : Str>
cc <case "abc def ghi" of {"ab"+x => x; _ => "?"} : Str>
cc <case "abc def ghi" of {x+"hi" => x; _ => "?"} : Str>
cc <case "abcdefghi" of {""+x => x; _ => "?"} : Str>
cc <case "abcdefghi" of {x+"" => x; _ => "?"} : Str>

View File

@@ -0,0 +1,22 @@
"a" ++ "b" ++ "c"
param_table.Q1
param_table.Q2
param_table.Q1
param_table.Q2
param_table.Q2
param_table.Q1
param_table.Q2
param_table.Q1
param_table.Q1
param_table.Q2
"start" ++ "abc" ++ "end"
"start" ++ "xyz" ++ "end"
"zero"
"def"
"?"
"?"
"c" ++ "def" ++ "g"
"c" ++ "def" ++ "ghi"
"abc" ++ "def" ++ "g"
"abcdefghi"
"abcdefghi"