[pseudo] Start rules are `_ := start-symbol EOF`, improve recovery.
authorSam McCall <sam.mccall@gmail.com>
Fri, 19 Aug 2022 13:53:50 +0000 (15:53 +0200)
committerSam McCall <sam.mccall@gmail.com>
Fri, 19 Aug 2022 14:49:37 +0000 (16:49 +0200)
commitbd5cc6575bdbe1d091f1cc70fb7f0b3c07cb894b
tree93f739266dc310e7c59165df4c2eb8f4cf0cb6d5
parent4d931b6e1e7e6003fa6c68aec9223b06e31c982d
[pseudo] Start rules are `_ := start-symbol EOF`, improve recovery.

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
clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
clang-tools-extra/pseudo/lib/Forest.cpp
clang-tools-extra/pseudo/lib/GLR.cpp
clang-tools-extra/pseudo/lib/cxx/cxx.bnf
clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
clang-tools-extra/pseudo/test/lr-build-basic.test
clang-tools-extra/pseudo/test/lr-build-conflicts.test
clang-tools-extra/pseudo/unittests/ForestTest.cpp
clang-tools-extra/pseudo/unittests/GLRTest.cpp