Skip to content

Commit 79e4483

Browse files
authored
Merge pull request #23 from KuterBora/left/rightSibling
rightSibling and leftSibling
2 parents e8697aa + 01b8ea9 commit 79e4483

6 files changed

Lines changed: 68 additions & 12 deletions

File tree

project.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
//> using javaProperty distcompiler.Node.assertErrorRefCorrectness=no
55

66
//> using dependency com.github.scopt::scopt:4.1.0
7-
//> using dependency com.lihaoyi::os-lib:0.11.4
8-
//> using dependency com.lihaoyi::pprint:0.9.0
9-
//> using dependency com.lihaoyi::sourcecode:0.4.2
10-
//> using dependency com.lihaoyi::ujson::4.2.1
11-
//> using dependency dev.zio::izumi-reflect:3.0.3
7+
//> using dependency com.lihaoyi::os-lib:0.11.5
8+
//> using dependency com.lihaoyi::pprint:0.9.3
9+
//> using dependency com.lihaoyi::sourcecode:0.4.4
10+
//> using dependency com.lihaoyi::ujson::4.3.0
11+
//> using dependency dev.zio::izumi-reflect:3.0.6
1212
//> using dependency edu.berkeley.cs.jqf:jqf-fuzz:2.1
1313
//> using dependency edu.berkeley.cs.jqf:jqf-instrument:2.1
14-
//> using dependency io.github.java-diff-utils:java-diff-utils:4.15
14+
//> using dependency io.github.java-diff-utils:java-diff-utils:4.16
1515
//> using dependency org.typelevel::cats-core:2.13.0
1616

1717
// Test

src/Node.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ object Node:
520520
else throw NodeError("node already has a parent")
521521

522522
if oldParent ne null
523-
then oldParent.nn.assertErrorRefCounts()
523+
then oldParent.assertErrorRefCounts()
524524
if parent ne null
525-
then parent.nn.assertErrorRefCounts()
525+
then parent.assertErrorRefCounts()
526526

527527
this
528528

@@ -538,7 +538,7 @@ object Node:
538538
_idxInParent = -1
539539

540540
if safe && (oldParent ne null)
541-
then oldParent.nn.assertErrorRefCounts()
541+
then oldParent.assertErrorRefCounts()
542542

543543
this
544544

src/Token.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ object Token:
116116
* is null, go around again. */
117117
sym = ref.get()
118118
end while
119-
sym.nn
119+
sym
120120
end TokenSym
121121

122122
/** Helper trait that overrides [[forja.Token#showSource]] to return true.

src/manip/SegmentedStack.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class SegmentedStack[T <: AnyRef](using NotGiven[Array[?] <:< T]):
2525
def consumeInReverse(fn: T => Unit): Unit =
2626
var idx = 0
2727
while base ne stack do
28-
base(idx).nn match
28+
base(idx) match
2929
case next: Array[AnyRef] if idx == 0 =>
3030
idx += 1 // back ref, skip
3131
case next: Array[AnyRef] if idx == base.length - 1 =>
@@ -37,7 +37,7 @@ final class SegmentedStack[T <: AnyRef](using NotGiven[Array[?] <:< T]):
3737
end while
3838

3939
while idx < stackSize do
40-
base(idx).nn match
40+
base(idx) match
4141
case _: Array[AnyRef] if idx == 0 => // skip
4242
case elem =>
4343
fn(elem.asInstanceOf[T])

src/manip/SeqPattern.test.scala

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,56 @@ class SeqPatternTests extends munit.FunSuite:
8585
.onChildren("fields skip: last missing")(tok1(), tok2())("no")
8686
.onChildren("fields skip: empty")()("no")
8787

88+
on(
89+
field(
90+
tok(tok1).withChildren:
91+
field(tok(tok2))
92+
~ eof,
93+
)
94+
~ eof
95+
| SeqPattern.pure("no"),
96+
)
97+
.onChildren("fields withChildren: exact")(tok1(tok2()))(tok2())
98+
.onChildren("fields withChildren: missing parent")(tok2(tok2()))("no")
99+
.onChildren("fields withChildren: missing child")(tok1(tok1()))("no")
100+
.onChildren("fields parent: empty")()("no")
101+
102+
on(
103+
field(
104+
anyNode.withChildren:
105+
parent(tok(tok1)) *> field(tok(tok2))
106+
~ eof,
107+
)
108+
~ eof
109+
| SeqPattern.pure("no"),
110+
)
111+
.onChildren("fields parent: exact")(tok1(tok2()))(tok2())
112+
.onChildren("fields parent: missing parent")(tok2(tok2()))("no")
113+
.onChildren("fields parent: missing child")(tok1(tok1()))("no")
114+
.onChildren("fields parent: empty")()("no")
115+
116+
on(
117+
skip(anyNode)
118+
~ field(leftSibling(tok(tok1)) *> tok(tok2))
119+
~ eof
120+
| SeqPattern.pure("no"),
121+
)
122+
.onChildren("fields leftSibling: exact")(tok1(), tok2())(tok2())
123+
.onChildren("fields leftSibling: different left")(tok2(), tok2())("no")
124+
.onChildren("fields leftSibling: different right")(tok1(), tok1())("no")
125+
.onChildren("fields leftSibling: empty")()("no")
126+
127+
on(
128+
field(rightSibling(tok(tok2)) *> tok(tok1))
129+
~ skip(anyNode)
130+
~ eof
131+
| SeqPattern.pure("no"),
132+
)
133+
.onChildren("fields rightSibling: exact")(tok1(), tok2())(tok1())
134+
.onChildren("fields rightSibling: different left")(tok2(), tok2())("no")
135+
.onChildren("fields rightSibling: different right")(tok1(), tok1())("no")
136+
.onChildren("fields rightSibling: empty")()("no")
137+
88138
object PatternTests:
89139
object tok1 extends Token
90140
object tok2 extends Token

src/manip/SeqPatternOps.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ trait SeqPatternOps:
178178
def parent[T](using DebugInfo)(pattern: SeqPattern[T]): SeqPattern[T] =
179179
refine(atParent(on(pattern).value))
180180

181+
def leftSibling[T](using DebugInfo)(pattern: SeqPattern[T]): SeqPattern[T] =
182+
refine(atLeftSibling(on(pattern).value))
183+
184+
def rightSibling[T](using DebugInfo)(pattern: SeqPattern[T]): SeqPattern[T] =
185+
refine(atRightSibling(on(pattern).value))
186+
181187
def ancestor[T](using DebugInfo)(pattern: SeqPattern[T]): SeqPattern[T] =
182188
refine(atAncestor(on(pattern).value))
183189

0 commit comments

Comments
 (0)