Skip to content

Commit 1db26d5

Browse files
committed
Add docmentation
1 parent f04972f commit 1db26d5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

library/src-bootstrapped/scala/runtime/quoted/Matcher.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ object Matcher {
3333
import reflection._
3434
// TODO improve performance
3535

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+
*/
3644
def treeMatches(scrutinee: Tree, pattern: Tree)(implicit env: Set[(Symbol, Symbol)]): Option[Tuple] = {
3745

3846
/** Check that both are `val` or both are `lazy val` or both are `var` **/
@@ -47,6 +55,7 @@ object Matcher {
4755
if (scrutinees.size != patterns.size) None
4856
else foldMatchings(scrutinees.zip(patterns).map(treeMatches): _*)
4957

58+
/** Normalieze the tree */
5059
def normalize(tree: Tree): Tree = tree match {
5160
case Block(Nil, expr) => normalize(expr)
5261
case Inlined(_, Nil, expr) => normalize(expr)
@@ -204,6 +213,16 @@ object Matcher {
204213
foldMatchings(patternMatch, guardMatch, rhsMatch)
205214
}
206215

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+
*/
207226
def patternMatches(scrutinee: Pattern, pattern: Pattern)(implicit env: Set[(Symbol, Symbol)]): (Set[(Symbol, Symbol)], Option[Tuple]) = (scrutinee, pattern) match {
208227
case (Pattern.Value(v1), Pattern.Unapply(TypeApply(Select(patternHole @ Ident("patternHole"), "unapply"), List(tpt)), Nil, Nil))
209228
if patternHole.symbol.owner.fullName == "scala.runtime.quoted.Matcher$" =>

0 commit comments

Comments
 (0)