`match%spat` generates unusable cases
Opened this issue · 0 comments
pdarragh commented
For example:
match%spat sexp with
| "{lambda {SYMBOL ...} ANY ...}" -> "LAMBDA EXPRESSION"
| _ -> "OTHER"
expands to:
match sexp with
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp [])::[]) ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.Symbol _)::[]))::[]) ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.Symbol _)::(Camlrack.Symbol _)::[]))::[]) ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.SExp subgroup1)::[]))::[])
when List.for_all (Camlrack.sexp_match Camlrack.SYMBOL) subgroup1 ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp [])::_::[]) ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.Symbol _)::[]))::_::[]) ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.Symbol _)::(Camlrack.Symbol _)::[]))::_::[]) ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.SExp subgroup1)::[]))::_::[])
when List.for_all (Camlrack.sexp_match Camlrack.SYMBOL) subgroup1 ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp [])::_::_::[]) ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.Symbol _)::[]))::_::_::[]) ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.Symbol _)::(Camlrack.Symbol _)::[]))::_::_::[]) ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.SExp subgroup1)::[]))::_::_::[])
when List.for_all (Camlrack.sexp_match Camlrack.SYMBOL) subgroup1 ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp [])::(Camlrack.SExp subgroup2)::[])
when List.for_all (Camlrack.sexp_match Camlrack.ANY) subgroup2 ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.Symbol _)::[]))::(Camlrack.SExp subgroup2)::[])
when List.for_all (Camlrack.sexp_match Camlrack.ANY) subgroup2 ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.Symbol _)::(Camlrack.Symbol _)::[]))::(Camlrack.SExp subgroup2)::[])
when List.for_all (Camlrack.sexp_match Camlrack.ANY) subgroup2 ->
"LAMBDA EXPRESSION"
| Camlrack.SExp ((Camlrack.Symbol "lambda")::(Camlrack.SExp ((Camlrack.SExp subgroup1)::[]))::(Camlrack.SExp subgroup2)::[])
when (List.for_all (Camlrack.sexp_match Camlrack.ANY) subgroup2) &&
(List.for_all (Camlrack.sexp_match Camlrack.SYMBOL) subgroup1) ->
"LAMBDA EXPRESSION"
| _ -> "OTHER"
In this expansion, the first three of the last four LAMBDA EXPRESSION
cases are superseded by the case preceding those.
Perhaps generic cases should be accumulated and placed at the end of the generated lists? Or else perhaps only generate generic matching variables at the top level?