diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-09-07 01:35:58 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-09-07 02:17:41 +0900 |
commit | a57fda765cd32b44cd069da1c9a442b701b36dc2 (patch) | |
tree | e8f72fbcac83fc18525263051e50d2b17f11ef24 /driver/semantic_action.go | |
parent | Call the 'MissError' when input doesn't meet an error production (diff) | |
download | cotia-a57fda765cd32b44cd069da1c9a442b701b36dc2.tar.gz cotia-a57fda765cd32b44cd069da1c9a442b701b36dc2.tar.xz |
Pass a token that caused a syntax error to the semantic action APIs
Diffstat (limited to 'driver/semantic_action.go')
-rw-r--r-- | driver/semantic_action.go | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/driver/semantic_action.go b/driver/semantic_action.go index 5bec385..1db703b 100644 --- a/driver/semantic_action.go +++ b/driver/semantic_action.go @@ -22,13 +22,14 @@ type SemanticActionSet interface { Accept() // TrapAndShiftError runs when the driver traps a syntax error and shifts a error symbol onto the state stack. - // `n` is the number of frames that the driver discards from the state stack. - // Unlike `Shift` function, this function doesn't take a token as an argument because a token corresponding to - // the error symbol doesn't exist. - TrapAndShiftError(n int) - - // MissError runs when the driver fails to trap a syntax error. - MissError() + // `cause` is a token that caused a syntax error. `popped` is the number of frames that the driver discards + // from the state stack. + // Unlike `Shift` function, this function doesn't take a token to be shifted as an argument because a token + // corresponding to the error symbol doesn't exist. + TrapAndShiftError(cause *mldriver.Token, popped int) + + // MissError runs when the driver fails to trap a syntax error. `cause` is a token that caused a syntax error. + MissError(cause *mldriver.Token) } var _ SemanticActionSet = &SyntaxTreeActionSet{} @@ -204,8 +205,8 @@ func (a *SyntaxTreeActionSet) Accept() { a.ast = top[0].ast } -func (a *SyntaxTreeActionSet) TrapAndShiftError(n int) { - a.semStack.pop(n) +func (a *SyntaxTreeActionSet) TrapAndShiftError(cause *mldriver.Token, popped int) { + a.semStack.pop(popped) errSym := a.gram.ParsingTable.ErrorSymbol @@ -228,7 +229,7 @@ func (a *SyntaxTreeActionSet) TrapAndShiftError(n int) { }) } -func (a *SyntaxTreeActionSet) MissError() { +func (a *SyntaxTreeActionSet) MissError(cause *mldriver.Token) { } func (a *SyntaxTreeActionSet) CST() *Node { |