File tree Expand file tree Collapse file tree 9 files changed +101
-0
lines changed
src/GrammarProcessing/Vocabulary Expand file tree Collapse file tree 9 files changed +101
-0
lines changed Original file line number Diff line number Diff line change @@ -37,4 +37,11 @@ public function acceptNode(
3737 return new GrammarProcessing \TokenNode ($ token );
3838 }
3939
40+
41+
42+ public function visit (callable $ visitor ): Symbol
43+ {
44+ return $ visitor ($ this );
45+ }
46+
4047}
Original file line number Diff line number Diff line change @@ -33,4 +33,11 @@ public function acceptNode(
3333 return new GrammarProcessing \EmptyNode ('NegativeLookahead ' );
3434 }
3535
36+
37+
38+ public function visit (callable $ visitor ): Symbol
39+ {
40+ return $ visitor ($ this );
41+ }
42+
3643}
Original file line number Diff line number Diff line change @@ -32,4 +32,11 @@ public function acceptNode(
3232 : new GrammarProcessing \TokenNode ($ tokenStream ->consumeTokenWithType ($ this ->nonterminal ));
3333 }
3434
35+
36+
37+ public function visit (callable $ visitor ): Symbol
38+ {
39+ return $ visitor ($ this );
40+ }
41+
3542}
Original file line number Diff line number Diff line change @@ -67,4 +67,21 @@ public function acceptNode(
6767 return $ result ['node ' ];
6868 }
6969
70+
71+
72+ public function visit (callable $ visitor ): Symbol
73+ {
74+ $ result = [];
75+
76+ foreach ($ this ->symbols as $ symbol ) {
77+ $ result [] = $ symbol ->visit ($ visitor );
78+ }
79+
80+ return $ visitor (
81+ $ result === $ this ->symbols
82+ ? $ this
83+ : new self ($ result ),
84+ );
85+ }
86+
7087}
Original file line number Diff line number Diff line change @@ -37,4 +37,11 @@ public function acceptNode(
3737 );
3838 }
3939
40+
41+
42+ public function visit (callable $ visitor ): Symbol
43+ {
44+ return $ visitor ($ this );
45+ }
46+
4047}
Original file line number Diff line number Diff line change @@ -69,4 +69,19 @@ public function acceptNode(
6969 return new GrammarProcessing \ListNode ($ result );
7070 }
7171
72+
73+
74+ public function visit (callable $ visitor ): Symbol
75+ {
76+ $ visitedSymbol = $ this ->symbol ->visit ($ visitor );
77+
78+ return $ visitor (
79+ $ visitedSymbol === $ this ->symbol ? $ this : new self (
80+ $ visitedSymbol ,
81+ $ this ->min ,
82+ $ this ->max ,
83+ ),
84+ );
85+ }
86+
7287}
Original file line number Diff line number Diff line change @@ -42,4 +42,21 @@ public function acceptNode(
4242 return new GrammarProcessing \ListNode ($ result );
4343 }
4444
45+
46+
47+ public function visit (callable $ visitor ): Symbol
48+ {
49+ $ visitedSymbols = [];
50+
51+ foreach ($ this ->symbols as $ symbol ) {
52+ $ visitedSymbols [] = $ symbol ->visit ($ visitor );
53+ }
54+
55+ return $ visitor (
56+ $ visitedSymbols === $ this ->symbols
57+ ? $ this
58+ : new self ($ visitedSymbols ),
59+ );
60+ }
61+
4562}
Original file line number Diff line number Diff line change @@ -55,4 +55,21 @@ public function acceptNode(
5555 return $ node ;
5656 }
5757
58+
59+
60+ public function visit (callable $ visitor ): Symbol
61+ {
62+ $ visitedBaseSymbol = $ this ->baseSymbol ->visit ($ visitor );
63+ $ visitedSubtractedSymbol = $ this ->subtractedSymbol ->visit ($ visitor );
64+
65+ $ isDifferent = $ visitedBaseSymbol !== $ this ->baseSymbol || $ visitedSubtractedSymbol !== $ this ->subtractedSymbol ;
66+
67+ return $ visitor (
68+ $ isDifferent ? $ this : new self (
69+ $ visitedBaseSymbol ,
70+ $ visitedSubtractedSymbol ,
71+ ),
72+ );
73+ }
74+
5875}
Original file line number Diff line number Diff line change @@ -24,4 +24,11 @@ function acceptNode(
2424 array $ nonterminals ,
2525 ): GrammarProcessing \Node ;
2626
27+
28+
29+ /**
30+ * @param callable(Symbol): Symbol $visitor
31+ */
32+ function visit (callable $ visitor ): Symbol ;
33+
2734}
You can’t perform that action at this time.
0 commit comments