================ @@ -148,6 +148,347 @@ bool RootSignatureLexer::LexToken(RootSignatureToken &Result) { return false; } +// Parser Definitions + +RootSignatureParser::RootSignatureParser( + SmallVector<RootElement> &Elements, + const SmallVector<RootSignatureToken> &Tokens) + : Elements(Elements) { + CurTok = Tokens.begin(); + LastTok = Tokens.end(); +} + +bool RootSignatureParser::ReportError() { return true; } + +bool RootSignatureParser::Parse() { + // Handle edge-case of empty RootSignature() + if (CurTok == LastTok) + return false; + + // Iterate as many RootElements as possible + bool HasComma = true; + while (HasComma && + IsCurExpectedToken(ArrayRef{TokenKind::kw_DescriptorTable})) { + if (ParseRootElement()) + return true; + HasComma = !TryConsumeExpectedToken(TokenKind::pu_comma); + if (HasComma) + ConsumeNextToken(); + } + + if (HasComma) + return ReportError(); // report 'comma' denotes a required extra item + + // Ensure that we are at the end of the tokens + CurTok++; + if (CurTok != LastTok) + return ReportError(); // report expected end of input but got more + return false; +} + +bool RootSignatureParser::ParseRootElement() { + // Dispatch onto the correct parse method + switch (CurTok->Kind) { + case TokenKind::kw_DescriptorTable: + return ParseDescriptorTable(); + default: + llvm_unreachable("Switch for an expected token was not provided"); + return true; ---------------- inbelic wrote:
Return `true` denotes that we occurred an error, so after hitting the unreachable state, this will just let the parser error out. https://github.com/llvm/llvm-project/pull/122982 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits