mirror of
https://github.com/comby-tools/comby.git
synced 2024-09-11 13:25:36 +03:00
update
This commit is contained in:
parent
98df3f795d
commit
d0d4c61118
@ -103,9 +103,11 @@ module Make (Metasyntax : Matchers.Metasyntax.S) = struct
|
|||||||
let hole_prefixes =
|
let hole_prefixes =
|
||||||
List.map Metasyntax.syntax ~f:(function
|
List.map Metasyntax.syntax ~f:(function
|
||||||
| Hole (_, Delimited (Some left, _))
|
| Hole (_, Delimited (Some left, _))
|
||||||
| Regex (left, _, _) -> Some left
|
| Regex (left, _, _) -> Some [left]
|
||||||
|
| Hole (_, Reserved_identifiers l) -> Some l
|
||||||
| _ -> None)
|
| _ -> None)
|
||||||
|> List.filter_opt
|
|> List.filter_opt
|
||||||
|
|> List.concat
|
||||||
|
|
||||||
(** Not smart enough: only looks for hole prefix to stop scanning constant,
|
(** Not smart enough: only looks for hole prefix to stop scanning constant,
|
||||||
because there isn't a good 'not' parser *)
|
because there isn't a good 'not' parser *)
|
||||||
|
@ -34,4 +34,35 @@ let%expect_test "interpret_incomplete_hole_as_constant_metasyntax" =
|
|||||||
in
|
in
|
||||||
parse metasyntax template |> print_string;
|
parse metasyntax template |> print_string;
|
||||||
[%expect_exact {|((Constant $) (Constant ":x ") (Hole ((variable B) (pattern "$B:x ")))
|
[%expect_exact {|((Constant $) (Constant ":x ") (Hole ((variable B) (pattern "$B:x ")))
|
||||||
(Constant " ") (Hole ((variable A) (pattern $A))))|}];
|
(Constant " ") (Hole ((variable A) (pattern $A))))|}]
|
||||||
|
|
||||||
|
let%expect_test "interpret_incomplete_hole_as_constant_metasyntax" =
|
||||||
|
let template = "( , , )" in
|
||||||
|
let metasyntax =
|
||||||
|
Matchers.Metasyntax.{
|
||||||
|
syntax =
|
||||||
|
[ Hole (Everything, Delimited (Some "NOTHING", None))
|
||||||
|
; Hole (Everything, Reserved_identifiers [" "; " "])
|
||||||
|
]
|
||||||
|
; identifier = "AB"
|
||||||
|
}
|
||||||
|
in
|
||||||
|
parse metasyntax template |> print_string;
|
||||||
|
[%expect_exact {|((Constant "(") (Hole ((variable " ") (pattern " "))) (Constant ,)
|
||||||
|
(Hole ((variable " ") (pattern " "))) (Constant ,)
|
||||||
|
(Hole ((variable " ") (pattern " "))) (Constant ")"))|}]
|
||||||
|
|
||||||
|
let%expect_test "interpret_incomplete_hole_as_constant_metasyntax" =
|
||||||
|
let template = "(..,.)" in
|
||||||
|
let metasyntax =
|
||||||
|
Matchers.Metasyntax.{
|
||||||
|
syntax =
|
||||||
|
[ Hole (Everything, Delimited (Some "NOTHING", None))
|
||||||
|
; Hole (Everything, Reserved_identifiers [".."; "."])
|
||||||
|
]
|
||||||
|
; identifier = "AB"
|
||||||
|
}
|
||||||
|
in
|
||||||
|
parse metasyntax template |> print_string;
|
||||||
|
[%expect_exact {|((Constant "(") (Hole ((variable ..) (pattern ..))) (Constant ,)
|
||||||
|
(Hole ((variable .) (pattern .))) (Constant ")"))|}]
|
||||||
|
11
test/example/metasyntax/dangling.json
Normal file
11
test/example/metasyntax/dangling.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"syntax": [
|
||||||
|
[ "Hole", [ "Everything" ], [ "Delimited", ")", null ] ],
|
||||||
|
[ "Hole", [ "Expression" ], [ "Delimited", "))", null ] ]
|
||||||
|
],
|
||||||
|
"identifier":
|
||||||
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||||
|
}
|
||||||
|
// echo 'swap(x, y)' | \
|
||||||
|
// ./comby -stdin -custom-metasyntax test/example/metasyntax/dangling.json \
|
||||||
|
// 'swap()1, ))2)' 'swap()2, )1)'
|
24
test/example/metasyntax/emoji.json
Normal file
24
test/example/metasyntax/emoji.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"syntax": [
|
||||||
|
[ "Hole", [ "Everything" ], [ "Delimited", "place-holder", null ] ],
|
||||||
|
[ "Hole", [ "Everything" ],
|
||||||
|
[ "Reserved_identifiers",
|
||||||
|
[ "❤️", "💙", "💚", "💜", "💛", "🧡" ]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[ "Hole", [ "Expression" ],
|
||||||
|
[ "Reserved_identifiers",
|
||||||
|
[ "😂", "🚡", "😃", "😬", "😈", "🐵", "✋", "😻", "🍌" ]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"identifier":
|
||||||
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||||
|
}
|
||||||
|
// echo 'swap(x, y)' | \
|
||||||
|
// ./comby -stdin -custom-metasyntax test/example/metasyntax/emoji.json \
|
||||||
|
// 'swap(🐵, 🍌)' 'swap(🍌, 🐵)'
|
||||||
|
|
||||||
|
// echo 'add(x, x)' | \ [17:25:08]
|
||||||
|
// ./comby -stdin -custom-metasyntax test/example/metasyntax/emoji.json \
|
||||||
|
// 'add(😂, 😂)' 'multiply(2, 😂)'
|
11
test/example/metasyntax/inverted-parens.json
Normal file
11
test/example/metasyntax/inverted-parens.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"syntax": [
|
||||||
|
[ "Hole", [ "Everything" ], [ "Delimited", ")", "(" ] ],
|
||||||
|
[ "Hole", [ "Expression" ], [ "Delimited", "))", "((" ] ]
|
||||||
|
],
|
||||||
|
"identifier":
|
||||||
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||||
|
}
|
||||||
|
// echo 'swap(x, y)' | \
|
||||||
|
// ./comby -stdin -custom-metasyntax test/example/metasyntax/inverted-parens.json \
|
||||||
|
// 'swap()1(, )2()' 'swap()2(, )1()'
|
25
test/example/metasyntax/lambda.json
Normal file
25
test/example/metasyntax/lambda.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"syntax": [
|
||||||
|
[ "Hole", [ "Everything" ], [ "Delimited", "place-holder", null ] ],
|
||||||
|
[ "Hole", [ "Everything" ],
|
||||||
|
[ "Reserved_identifiers",
|
||||||
|
[ "Γ", "Δ", "Θ", "Λ", "Ξ", "Π", "Σ", "Φ", "Ψ", "Ω" ]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[ "Hole", [ "Expression" ],
|
||||||
|
[ "Reserved_identifiers",
|
||||||
|
[
|
||||||
|
"α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ",
|
||||||
|
"μ", "ξ", "π", "ρ", "ς", "σ", "τ", "υ", "φ", "χ", "ψ",
|
||||||
|
"ω"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"identifier":
|
||||||
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||||
|
}
|
||||||
|
// echo 'swap(x, y)' | \
|
||||||
|
// ./comby -stdin -custom-metasyntax test/example/metasyntax/lambda.json \
|
||||||
|
// 'λ(α, β)' 'λ(β, α)'
|
||||||
|
|
17
test/example/metasyntax/wutspace.json
Normal file
17
test/example/metasyntax/wutspace.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"syntax": [
|
||||||
|
// Currently a placeholder is needed if we only care about Reserved_idenitifersl to avoid trickery.
|
||||||
|
// Order is significant.
|
||||||
|
[ "Hole", [ "Everything" ], [ "Delimited", "place-holder", null ] ],
|
||||||
|
[ "Hole", [ "Everything" ],
|
||||||
|
[ "Reserved_identifiers",
|
||||||
|
[ " ", " " ]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"identifier":
|
||||||
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
|
||||||
|
}
|
||||||
|
// echo 'swap(x,y)' | \
|
||||||
|
// ./comby -stdin -custom-metasyntax test/example/metasyntax/wutspace.json \
|
||||||
|
// 'swap( , )' 'swap( , )'
|
Loading…
Reference in New Issue
Block a user