Skip to content

Commit

Permalink
[pseudo] Add guards for module contextual keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-mccall committed Jul 18, 2022
1 parent 315072b commit fa0c763
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions clang-tools-extra/pseudo/lib/cxx/CXX.cpp
Expand Up @@ -33,11 +33,26 @@ bool guardFinal(llvm::ArrayRef<const ForestNode *> RHS,
RHS.front()->symbol() == tokenSymbol(clang::tok::identifier));
return Tokens.tokens()[RHS.front()->startTokenIndex()].text() == "final";
}
bool guardModule(llvm::ArrayRef<const ForestNode *> RHS,
const TokenStream &Tokens) {
return Tokens.tokens()[RHS.front()->startTokenIndex()].text() == "module";
}
bool guardImport(llvm::ArrayRef<const ForestNode *> RHS,
const TokenStream &Tokens) {
return Tokens.tokens()[RHS.front()->startTokenIndex()].text() == "import";
}
bool guardExport(llvm::ArrayRef<const ForestNode *> RHS,
const TokenStream &Tokens) {
return Tokens.tokens()[RHS.front()->startTokenIndex()].text() == "export";
}

llvm::DenseMap<ExtensionID, RuleGuard> buildGuards() {
return {
{(ExtensionID)Extension::Override, guardOverride},
{(ExtensionID)Extension::Final, guardFinal},
{(ExtensionID)Extension::Import, guardImport},
{(ExtensionID)Extension::Export, guardExport},
{(ExtensionID)Extension::Module, guardModule},
};
}

Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/pseudo/lib/cxx/cxx.bnf
Expand Up @@ -748,10 +748,10 @@ pointer-literal := NULLPTR
#! Placeholders for literal text in the grammar that lex as other things.
contextual-override := IDENTIFIER [guard=Override]
contextual-final := IDENTIFIER [guard=Final]
contextual-zero := NUMERIC_CONSTANT
module-keyword := IDENTIFIER
import-keyword := IDENTIFIER
export-keyword := IDENTIFIER
contextual-zero := NUMERIC_CONSTANT [guard=Zero]
module-keyword := IDENTIFIER [guard=Module]
import-keyword := IDENTIFIER [guard=Import]
export-keyword := IDENTIFIER [guard=Export]

#! greatergreater token -- clang lexer always lexes it as a single token, we
#! split it into two tokens to make the GLR parser aware of the nested-template
Expand Down

0 comments on commit fa0c763

Please sign in to comment.