aboutsummaryrefslogtreecommitdiff
path: root/driver/parser.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-09-06 23:59:43 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-09-07 02:17:35 +0900
commited2c20102659f4c8aef0e88ea604e91fb56f25f6 (patch)
treec46e6bc40e9373237fb7cad2730d410132b27caa /driver/parser.go
parentUpdate CHANGELOG (diff)
downloadurubu-ed2c20102659f4c8aef0e88ea604e91fb56f25f6.tar.gz
urubu-ed2c20102659f4c8aef0e88ea604e91fb56f25f6.tar.xz
Change semantic action APIs
The driver reports whether it recovered from an error to the semantic action APIs via the argument `recovered`.
Diffstat (limited to 'driver/parser.go')
-rw-r--r--driver/parser.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/driver/parser.go b/driver/parser.go
index 1e7af29..af257e2 100644
--- a/driver/parser.go
+++ b/driver/parser.go
@@ -85,20 +85,22 @@ ACTION_LOOP:
case act < 0: // Shift
nextState := act * -1
+ recovered := false
if p.onError {
+ p.shiftCount++
+
// When the parser performs shift three times, the parser recovers from the error state.
- if p.shiftCount < 3 {
- p.shiftCount++
- } else {
+ if p.shiftCount >= 3 {
p.onError = false
p.shiftCount = 0
+ recovered = true
}
}
p.shift(nextState)
if p.semAct != nil {
- p.semAct.Shift(tok)
+ p.semAct.Shift(tok, recovered)
}
tok, err = p.nextToken()
@@ -108,9 +110,11 @@ ACTION_LOOP:
case act > 0: // Reduce
prodNum := act
+ recovered := false
if p.onError && p.gram.ParsingTable.RecoverProductions[prodNum] != 0 {
p.onError = false
p.shiftCount = 0
+ recovered = true
}
accepted := p.reduce(prodNum)
@@ -123,7 +127,7 @@ ACTION_LOOP:
}
if p.semAct != nil {
- p.semAct.Reduce(prodNum)
+ p.semAct.Reduce(prodNum, recovered)
}
default: // Error
if p.onError {