@@ -33,6 +33,14 @@ object Matcher {
33
33
import reflection ._
34
34
// TODO improve performance
35
35
36
+ /** Check that the trees match and return the contents from the pattern holes.
37
+ * Return None if the trees do not match otherwise return Some of a tuple containing all the contents in the holes.
38
+ *
39
+ * @param scrutinee The tree beeing matched
40
+ * @param pattern The pattern tree that the scrutinee should match. Contains `patternHole` holes.
41
+ * @param env Set of tuples containing pairs of symbols (s, p) where s defines a symbol in `scrutinee` which corresponds to symbol p in `pattern`.
42
+ * @return `None` if it did not match or `Some(tup: Tuple)` if it matched where `tup` contains the contents of the holes.
43
+ */
36
44
def treeMatches (scrutinee : Tree , pattern : Tree )(implicit env : Set [(Symbol , Symbol )]): Option [Tuple ] = {
37
45
38
46
/** Check that both are `val` or both are `lazy val` or both are `var` **/
@@ -47,6 +55,7 @@ object Matcher {
47
55
if (scrutinees.size != patterns.size) None
48
56
else foldMatchings(scrutinees.zip(patterns).map(treeMatches): _* )
49
57
58
+ /** Normalieze the tree */
50
59
def normalize (tree : Tree ): Tree = tree match {
51
60
case Block (Nil , expr) => normalize(expr)
52
61
case Inlined (_, Nil , expr) => normalize(expr)
@@ -204,6 +213,16 @@ object Matcher {
204
213
foldMatchings(patternMatch, guardMatch, rhsMatch)
205
214
}
206
215
216
+ /** Check that the pattern trees match and return the contents from the pattern holes.
217
+ * Return a tuple with the new environment containing the bindings defined in this pattern and a matching.
218
+ * The matching is None if the pattern trees do not match otherwise return Some of a tuple containing all the contents in the holes.
219
+ *
220
+ * @param scrutinee The pattern tree beeing matched
221
+ * @param pattern The pattern tree that the scrutinee should match. Contains `patternHole` holes.
222
+ * @param env Set of tuples containing pairs of symbols (s, p) where s defines a symbol in `scrutinee` which corresponds to symbol p in `pattern`.
223
+ * @return The new environment containing the bindings defined in this pattern tuppled with
224
+ * `None` if it did not match or `Some(tup: Tuple)` if it matched where `tup` contains the contents of the holes.
225
+ */
207
226
def patternMatches (scrutinee : Pattern , pattern : Pattern )(implicit env : Set [(Symbol , Symbol )]): (Set [(Symbol , Symbol )], Option [Tuple ]) = (scrutinee, pattern) match {
208
227
case (Pattern .Value (v1), Pattern .Unapply (TypeApply (Select (patternHole @ Ident (" patternHole" ), " unapply" ), List (tpt)), Nil , Nil ))
209
228
if patternHole.symbol.owner.fullName == " scala.runtime.quoted.Matcher$" =>
0 commit comments