This commit is contained in:
Rijnard van Tonder 2021-04-25 14:39:08 -07:00
parent 98df3f795d
commit d0d4c61118
7 changed files with 123 additions and 2 deletions

View File

@ -103,9 +103,11 @@ module Make (Metasyntax : Matchers.Metasyntax.S) = struct
let hole_prefixes =
List.map Metasyntax.syntax ~f:(function
| Hole (_, Delimited (Some left, _))
| Regex (left, _, _) -> Some left
| Regex (left, _, _) -> Some [left]
| Hole (_, Reserved_identifiers l) -> Some l
| _ -> None)
|> List.filter_opt
|> List.concat
(** Not smart enough: only looks for hole prefix to stop scanning constant,
because there isn't a good 'not' parser *)

View File

@ -34,4 +34,35 @@ let%expect_test "interpret_incomplete_hole_as_constant_metasyntax" =
in
parse metasyntax template |> print_string;
[%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 ")"))|}]

View 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)'

View 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, 😂)'

View 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()'

View 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 \
// 'λ(α, β)' 'λ(β, α)'

View 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( , )'