[flang] Recover better from syntax errors on USE statements

Original-commit: flang-compiler/f18@29968698d9
Reviewed-on: https://github.com/flang-compiler/f18/pull/731
This commit is contained in:
peter klausler 2019-09-10 15:29:09 -07:00
parent 98a7408347
commit f9ed573b1d
2 changed files with 6 additions and 2 deletions

View File

@ -208,6 +208,7 @@ public:
state.set_anyTokenMatched(); state.set_anyTokenMatched();
} }
} else if (state.anyTokenMatched()) { } else if (state.anyTokenMatched()) {
emitMessage = state.messages().empty();
messages.Annex(std::move(state.messages())); messages.Annex(std::move(state.messages()));
backtrack.set_anyTokenMatched(); backtrack.set_anyTokenMatched();
if (state.anyDeferredMessages()) { if (state.anyDeferredMessages()) {

View File

@ -307,7 +307,7 @@ TYPE_PARSER(construct<ProgramUnit>(indirect(Parser<Module>{})) ||
// [declaration-construct]... // [declaration-construct]...
TYPE_CONTEXT_PARSER("specification part"_en_US, TYPE_CONTEXT_PARSER("specification part"_en_US,
construct<SpecificationPart>(many(openmpDeclarativeConstruct), construct<SpecificationPart>(many(openmpDeclarativeConstruct),
many(unambiguousStatement(indirect(Parser<UseStmt>{}))), many(statement(indirect(Parser<UseStmt>{}))),
many(unambiguousStatement(indirect(Parser<ImportStmt>{}))), many(unambiguousStatement(indirect(Parser<ImportStmt>{}))),
implicitPart, many(declarationConstruct))) implicitPart, many(declarationConstruct)))
@ -318,7 +318,7 @@ TYPE_CONTEXT_PARSER("specification part"_en_US,
// statement. // statement.
constexpr auto limitedSpecificationPart{inContext("specification part"_en_US, constexpr auto limitedSpecificationPart{inContext("specification part"_en_US,
construct<SpecificationPart>(many(openmpDeclarativeConstruct), construct<SpecificationPart>(many(openmpDeclarativeConstruct),
many(unambiguousStatement(indirect(Parser<UseStmt>{}))), many(statement(indirect(Parser<UseStmt>{}))),
many(unambiguousStatement(indirect(Parser<ImportStmt>{}))), many(unambiguousStatement(indirect(Parser<ImportStmt>{}))),
implicitPart, many(limitedDeclarationConstruct)))}; implicitPart, many(limitedDeclarationConstruct)))};
@ -3110,6 +3110,9 @@ constexpr auto moduleNature{
// R1409 use-stmt -> // R1409 use-stmt ->
// USE [[, module-nature] ::] module-name [, rename-list] | // USE [[, module-nature] ::] module-name [, rename-list] |
// USE [[, module-nature] ::] module-name , ONLY : [only-list] // USE [[, module-nature] ::] module-name , ONLY : [only-list]
// N.B. Lookahead to the end of the statement is necessary to resolve
// ambiguity with assignments and statement function definitions that
// begin with the letters "USE".
TYPE_PARSER(construct<UseStmt>("USE" >> optionalBeforeColons(moduleNature), TYPE_PARSER(construct<UseStmt>("USE" >> optionalBeforeColons(moduleNature),
name, ", ONLY :" >> optionalList(Parser<Only>{})) || name, ", ONLY :" >> optionalList(Parser<Only>{})) ||
construct<UseStmt>("USE" >> optionalBeforeColons(moduleNature), name, construct<UseStmt>("USE" >> optionalBeforeColons(moduleNature), name,