mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 11:36:46 +00:00

Previously we were calling glrRecover() ad-hoc at the end of input. Two main problems with this: - glrRecover() on two separate code paths is inelegant - We may have to recover several times in succession (e.g. to exit from nested scopes), so we need a loop at end-of-file Having an actual shift action for an EOF terminal allows us to handle both concerns in the main shift/recover/reduce loop. This revealed a recovery design bug where recovery could enter a loop by repeatedly choosing the same parent to identically recover from. Addressed this by allowing each node to be used as a recovery base once. Differential Revision: https://reviews.llvm.org/D130550
33 lines
996 B
Plaintext
33 lines
996 B
Plaintext
_ := expr EOF
|
|
expr := id
|
|
id := IDENTIFIER
|
|
|
|
# RUN: clang-pseudo -grammar %s -print-graph | FileCheck %s --check-prefix=GRAPH
|
|
# GRAPH: States:
|
|
# GRAPH-NEXT: State 0
|
|
# GRAPH-NEXT: _ := • expr EOF
|
|
# GRAPH-NEXT: expr := • id
|
|
# GRAPH-NEXT: id := • IDENTIFIER
|
|
# GRAPH-NEXT: State 1
|
|
# GRAPH-NEXT: _ := expr • EOF
|
|
# GRAPH-NEXT: State 2
|
|
# GRAPH-NEXT: expr := id •
|
|
# GRAPH-NEXT: State 3
|
|
# GRAPH-NEXT: id := IDENTIFIER •
|
|
# GRAPH-NEXT: State 4
|
|
# GRAPH-NEXT: _ := expr EOF •
|
|
|
|
# RUN: clang-pseudo -grammar %s -print-table | FileCheck %s --check-prefix=TABLE
|
|
# TABLE: LRTable:
|
|
# TABLE-NEXT: State 0
|
|
# TABLE-NEXT: IDENTIFIER: shift state 3
|
|
# TABLE-NEXT: expr: go to state 1
|
|
# TABLE-NEXT: id: go to state 2
|
|
# TABLE-NEXT: State 1
|
|
# TABLE-NEXT: EOF: shift state 4
|
|
# TABLE-NEXT: State 2
|
|
# TABLE-NEXT: EOF: reduce by rule 2 'expr := id'
|
|
# TABLE-NEXT: State 3
|
|
# TABLE-NEXT: EOF: reduce by rule 1 'id := IDENTIFIER'
|
|
# TABLE-NEXT: State 4
|