本文整理汇总了C++中ParserStatus类的典型用法代码示例。如果您正苦于以下问题:C++ ParserStatus类的具体用法?C++ ParserStatus怎么用?C++ ParserStatus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParserStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParsingPatternTuple
/// Parse a tuple pattern.
///
/// pattern-tuple:
/// '(' pattern-tuple-body? ')'
/// pattern-tuple-body:
/// pattern-tuple-element (',' pattern-tuple-body)*
ParserResult<Pattern> Parser::parsePatternTuple() {
StructureMarkerRAII ParsingPatternTuple(*this, Tok);
SourceLoc LPLoc = consumeToken(tok::l_paren);
SourceLoc RPLoc;
// Parse all the elements.
SmallVector<TuplePatternElt, 8> elts;
ParserStatus ListStatus =
parseList(tok::r_paren, LPLoc, RPLoc, tok::comma, /*OptionalSep=*/false,
/*AllowSepAfterLast=*/false,
diag::expected_rparen_tuple_pattern_list,
[&] () -> ParserStatus {
// Parse the pattern tuple element.
ParserStatus EltStatus;
Optional<TuplePatternElt> elt;
std::tie(EltStatus, elt) = parsePatternTupleElement();
if (EltStatus.hasCodeCompletion())
return makeParserCodeCompletionStatus();
if (!elt)
return makeParserError();
// Add this element to the list.
elts.push_back(*elt);
return makeParserSuccess();
});
return makeParserResult(
ListStatus,
TuplePattern::createSimple(Context, LPLoc, elts, RPLoc));
}
示例2: warning
bool StateActions::warning(const ParserStatus & parser, const QString & argument)
{
if (! parser.errorHandler())
return true;
QXmlParseException exception(argument, parser.m_locator->columnNumber(), parser.m_locator->lineNumber());
return parser.errorHandler()->warning(exception);
}
示例3: parsePattern
/// Parse a pattern with an optional type annotation.
///
/// typed-pattern ::= pattern (':' type)?
///
ParserResult<Pattern> Parser::parseTypedPattern() {
auto result = parsePattern();
// Now parse an optional type annotation.
if (Tok.is(tok::colon)) {
SourceLoc colonLoc = consumeToken(tok::colon);
if (result.isNull()) // Recover by creating AnyPattern.
result = makeParserErrorResult(new (Context) AnyPattern(colonLoc));
ParserResult<TypeRepr> Ty = parseType();
if (Ty.hasCodeCompletion())
return makeParserCodeCompletionResult<Pattern>();
if (!Ty.isNull()) {
// Attempt to diagnose initializer calls incorrectly written
// as typed patterns, such as "var x: [Int]()".
if (Tok.isFollowingLParen()) {
BacktrackingScope backtrack(*this);
// Create a local context if needed so we can parse trailing closures.
LocalContext dummyContext;
Optional<ContextChange> contextChange;
if (!CurLocalContext) {
contextChange.emplace(*this, CurDeclContext, &dummyContext);
}
SourceLoc lParenLoc, rParenLoc;
SmallVector<Expr *, 2> args;
SmallVector<Identifier, 2> argLabels;
SmallVector<SourceLoc, 2> argLabelLocs;
Expr *trailingClosure;
ParserStatus status = parseExprList(tok::l_paren, tok::r_paren,
/*isPostfix=*/true,
/*isExprBasic=*/false,
lParenLoc, args, argLabels,
argLabelLocs, rParenLoc,
trailingClosure);
if (status.isSuccess()) {
backtrack.cancelBacktrack();
// Suggest replacing ':' with '='
diagnose(lParenLoc, diag::initializer_as_typed_pattern)
.highlight({Ty.get()->getStartLoc(), rParenLoc})
.fixItReplace(colonLoc, " = ");
result.setIsParseError();
}
}
} else {
Ty = makeParserResult(new (Context) ErrorTypeRepr(PreviousLoc));
}
result = makeParserResult(result,
new (Context) TypedPattern(result.get(), Ty.get()));
}
return result;
}
示例4: fatalError
bool StateActions::fatalError(const ParserStatus & parser, const QString & argument)
{
kError(24001) << argument << endl;
if (! parser.errorHandler())
return false;
QXmlParseException exception(argument, parser.m_locator->columnNumber(), parser.m_locator->lineNumber());
return parser.errorHandler()->fatalError(exception);
}
示例5: createComment
bool StateActions::createComment(const ParserStatus & parser, const QString & argument)
{
Q_UNUSED(argument);
if (! parser.lexicalHandler())
return true;
parser.m_tagRange.end().setPosition(parser.m_locator->lineNumber(), parser.m_locator->columnNumber() + 1);
REPORTRANGES
bool result = parser.lexicalHandler()->comment(parser.m_buffer);
parser.m_buffer.clear();
parser.m_buffer.reserve(1000);
return result;
}
示例6: consumeToken
/// parseTypeComposition
///
/// type-composition:
/// 'protocol' '<' type-composition-list? '>'
///
/// type-composition-list:
/// type-identifier (',' type-identifier)*
///
ParserResult<ProtocolCompositionTypeRepr> Parser::parseTypeComposition() {
SourceLoc ProtocolLoc = consumeToken(tok::kw_protocol);
// Check for the starting '<'.
if (!startsWithLess(Tok)) {
diagnose(Tok, diag::expected_langle_protocol);
return nullptr;
}
SourceLoc LAngleLoc = consumeStartingLess();
// Check for empty protocol composition.
if (startsWithGreater(Tok)) {
SourceLoc RAngleLoc = consumeStartingGreater();
return makeParserResult(new (Context) ProtocolCompositionTypeRepr(
ArrayRef<IdentTypeRepr *>(),
ProtocolLoc,
SourceRange(LAngleLoc,
RAngleLoc)));
}
// Parse the type-composition-list.
ParserStatus Status;
SmallVector<IdentTypeRepr *, 4> Protocols;
do {
// Parse the type-identifier.
ParserResult<IdentTypeRepr> Protocol = parseTypeIdentifier();
Status |= Protocol;
if (Protocol.isNonNull())
Protocols.push_back(Protocol.get());
} while (consumeIf(tok::comma));
// Check for the terminating '>'.
SourceLoc EndLoc = PreviousLoc;
if (startsWithGreater(Tok)) {
EndLoc = consumeStartingGreater();
} else {
if (Status.isSuccess()) {
diagnose(Tok, diag::expected_rangle_protocol);
diagnose(LAngleLoc, diag::opening_angle);
Status.setIsParseError();
}
// Skip until we hit the '>'.
EndLoc = skipUntilGreaterInTypeList(/*protocolComposition=*/true);
}
return makeParserResult(Status, ProtocolCompositionTypeRepr::create(
Context, Protocols, ProtocolLoc, SourceRange(LAngleLoc, EndLoc)));
}
示例7: createTag
bool StateActions::createTag(const ParserStatus & parser, const QString & argument)
{
Q_UNUSED(argument);
parser.m_tagRange.end().setPosition(parser.m_locator->lineNumber(), parser.m_locator->columnNumber() + 1);
REPORTRANGES
bool result;
if (parser.m_namespace.isEmpty())
result = parser.contentHandler()->startElement("", parser.m_tagName, "", parser.m_attributes);
else
result = parser.contentHandler()->startElement(parser.m_namespace, parser.m_tagName, parser.m_namespace + ':' + parser.m_tagName, parser.m_attributes);
parser.m_tagName.clear();
parser.m_namespace.clear();
parser.m_attributes.clear();
return result;
}
示例8: createText
bool StateActions::createText(const ParserStatus & parser, const QString & argument)
{
Q_UNUSED(argument);
parser.m_tagRange.end().setPosition(parser.m_locator->lineNumber(), parser.m_locator->columnNumber());
REPORTRANGES
bool result = parser.contentHandler()->characters(parser.m_buffer);
parser.m_buffer.clear();
parser.m_buffer.reserve(1000);
return result;
}
示例9: createEndTag
bool StateActions::createEndTag(const ParserStatus & parser, const QString & argument)
{
Q_UNUSED(argument);
parser.m_tagRange.end().setPosition(parser.m_locator->lineNumber(), parser.m_locator->columnNumber() + 1);
REPORTRANGES
bool result = parser.contentHandler()->endElement(
parser.m_namespace + ':' + parser.m_tagName, "", parser.m_tagName);
parser.m_tagName.clear();
parser.m_namespace.clear();
parser.m_attributes.clear(); // just in case
return result;
}
示例10: startParsing
void ParserManager::parse(EditorSource *source, QuantaXmlInputSource *inputSource, ParseResult *base, const DTDStruct *dtd, bool detailed)
{
emit startParsing(source);
ParserStatus *parser = new ParserStatus(inputSource->newLocator(), xmlStateMachine());
DomBuilder *builder = new DomBuilder();
parser->setContentHandler(builder);
parser->setLexicalHandler(builder);
parser->setErrorHandler(builder);
parser->setQuantaHandler(builder);
parser->parse(inputSource);
base->model = builder->model();
delete parser;
delete builder;
// m_parser->parse(source, base, dtd, detailed);
emit finishedParsing(source, base);
}
示例11: consumeToken
/// parseTypeIdentifierOrTypeComposition
/// - Identifiers and compositions both start with the same identifier
/// token, parse it and continue constructing a composition if the
/// next token is '&'
///
/// type-composition:
/// type-identifier ('&' type-identifier)*
/// 'protocol' '<' type-composition-list-deprecated? '>'
///
/// type-composition-list-deprecated:
/// type-identifier (',' type-identifier)*
ParserResult<TypeRepr> Parser::parseTypeIdentifierOrTypeComposition() {
// Handle deprecated case
if (Tok.getKind() == tok::kw_protocol && startsWithLess(peekToken())) {
SourceLoc ProtocolLoc = consumeToken(tok::kw_protocol);
SourceLoc LAngleLoc = consumeStartingLess();
// Parse the type-composition-list.
ParserStatus Status;
SmallVector<IdentTypeRepr *, 4> Protocols;
bool IsEmpty = startsWithGreater(Tok);
if (!IsEmpty) {
do {
// Parse the type-identifier.
ParserResult<TypeRepr> Protocol = parseTypeIdentifier();
Status |= Protocol;
if (auto *ident = dyn_cast_or_null<IdentTypeRepr>(
Protocol.getPtrOrNull()))
Protocols.push_back(ident);
} while (consumeIf(tok::comma));
}
// Check for the terminating '>'.
SourceLoc RAngleLoc = PreviousLoc;
if (startsWithGreater(Tok)) {
RAngleLoc = consumeStartingGreater();
} else {
if (Status.isSuccess()) {
diagnose(Tok, diag::expected_rangle_protocol);
diagnose(LAngleLoc, diag::opening_angle);
Status.setIsParseError();
}
// Skip until we hit the '>'.
RAngleLoc = skipUntilGreaterInTypeList(/*protocolComposition=*/true);
}
auto composition = ProtocolCompositionTypeRepr::create(
Context, Protocols, ProtocolLoc, {LAngleLoc, RAngleLoc});
if (Status.isSuccess()) {
// Only if we have complete protocol<...> construct, diagnose deprecated.
SmallString<32> replacement;
if (Protocols.empty()) {
replacement = "Any";
} else {
auto extractText = [&](IdentTypeRepr *Ty) -> StringRef {
auto SourceRange = Ty->getSourceRange();
return SourceMgr.extractText(
Lexer::getCharSourceRangeFromSourceRange(SourceMgr, SourceRange));
};
auto Begin = Protocols.begin();
replacement += extractText(*Begin);
while (++Begin != Protocols.end()) {
replacement += " & ";
replacement += extractText(*Begin);
}
}
// Copy trailing content after '>' to the replacement string.
// FIXME: lexer should smartly separate '>' and trailing contents like '?'.
StringRef TrailingContent = L->getTokenAt(RAngleLoc).getRange().str().
substr(1);
if (!TrailingContent.empty()) {
if (Protocols.size() > 1) {
replacement.insert(replacement.begin(), '(');
replacement += ")";
}
replacement += TrailingContent;
}
// Replace 'protocol<T1, T2>' with 'T1 & T2'
diagnose(ProtocolLoc,
IsEmpty ? diag::deprecated_any_composition :
Protocols.size() > 1 ? diag::deprecated_protocol_composition :
diag::deprecated_protocol_composition_single)
.highlight(composition->getSourceRange())
.fixItReplace(composition->getSourceRange(), replacement);
}
return makeParserResult(Status, composition);
}
SourceLoc FirstTypeLoc = Tok.getLoc();
// Parse the first type
ParserResult<TypeRepr> FirstType = parseTypeIdentifier();
if (!Tok.isContextualPunctuator("&"))
//.........这里部分代码省略.........
示例12: parseAnyType
/// parseTypeIdentifier
///
/// type-identifier:
/// identifier generic-args? ('.' identifier generic-args?)*
///
ParserResult<TypeRepr> Parser::parseTypeIdentifier() {
if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_Self)) {
// is this the 'Any' type
if (Tok.is(tok::kw_Any)) {
return parseAnyType();
} else if (Tok.is(tok::code_complete)) {
if (CodeCompletion)
CodeCompletion->completeTypeSimpleBeginning();
// Eat the code completion token because we handled it.
consumeToken(tok::code_complete);
return makeParserCodeCompletionResult<IdentTypeRepr>();
}
diagnose(Tok, diag::expected_identifier_for_type);
// If there is a keyword at the start of a new line, we won't want to
// skip it as a recovery but rather keep it.
if (Tok.isKeyword() && !Tok.isAtStartOfLine())
consumeToken();
return nullptr;
}
ParserStatus Status;
SmallVector<ComponentIdentTypeRepr *, 4> ComponentsR;
SourceLoc EndLoc;
while (true) {
SourceLoc Loc;
Identifier Name;
if (Tok.is(tok::kw_Self)) {
Loc = consumeIdentifier(&Name);
} else {
// FIXME: specialize diagnostic for 'Type': type cannot start with
// 'metatype'
// FIXME: offer a fixit: 'self' -> 'Self'
if (parseIdentifier(Name, Loc, diag::expected_identifier_in_dotted_type))
Status.setIsParseError();
}
if (Loc.isValid()) {
SourceLoc LAngle, RAngle;
SmallVector<TypeRepr*, 8> GenericArgs;
if (startsWithLess(Tok)) {
if (parseGenericArguments(GenericArgs, LAngle, RAngle))
return nullptr;
}
EndLoc = Loc;
ComponentIdentTypeRepr *CompT;
if (!GenericArgs.empty())
CompT = new (Context) GenericIdentTypeRepr(Loc, Name,
Context.AllocateCopy(GenericArgs),
SourceRange(LAngle, RAngle));
else
CompT = new (Context) SimpleIdentTypeRepr(Loc, Name);
ComponentsR.push_back(CompT);
}
// Treat 'Foo.<anything>' as an attempt to write a dotted type
// unless <anything> is 'Type'.
if ((Tok.is(tok::period) || Tok.is(tok::period_prefix))) {
if (peekToken().is(tok::code_complete)) {
Status.setHasCodeCompletion();
break;
}
if (!peekToken().isContextualKeyword("Type")
&& !peekToken().isContextualKeyword("Protocol")) {
consumeToken();
continue;
}
} else if (Tok.is(tok::code_complete)) {
if (!Tok.isAtStartOfLine())
Status.setHasCodeCompletion();
break;
}
break;
}
IdentTypeRepr *ITR = nullptr;
if (!ComponentsR.empty()) {
// Lookup element #0 through our current scope chains in case it is some
// thing local (this returns null if nothing is found).
if (auto Entry = lookupInScope(ComponentsR[0]->getIdentifier()))
if (isa<TypeDecl>(Entry))
ComponentsR[0]->setValue(Entry);
ITR = IdentTypeRepr::create(Context, ComponentsR);
}
if (Status.hasCodeCompletion() && CodeCompletion) {
if (Tok.isNot(tok::code_complete)) {
// We have a dot.
consumeToken();
CodeCompletion->completeTypeIdentifierWithDot(ITR);
} else {
//.........这里部分代码省略.........
示例13: getListElementKind
ParserStatus
Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
bool AllowSepAfterLast, Diag<> ErrorDiag, SyntaxKind Kind,
std::function<ParserStatus()> callback) {
llvm::Optional<SyntaxParsingContext> ListContext;
ListContext.emplace(SyntaxContext, Kind);
if (Kind == SyntaxKind::Unknown)
ListContext->setTransparent();
SyntaxKind ElementKind = getListElementKind(Kind);
if (Tok.is(RightK)) {
ListContext.reset();
RightLoc = consumeToken(RightK);
return makeParserSuccess();
}
ParserStatus Status;
while (true) {
while (Tok.is(tok::comma)) {
diagnose(Tok, diag::unexpected_separator, ",")
.fixItRemove(SourceRange(Tok.getLoc()));
consumeToken();
}
SourceLoc StartLoc = Tok.getLoc();
SyntaxParsingContext ElementContext(SyntaxContext, ElementKind);
if (ElementKind == SyntaxKind::Unknown)
ElementContext.setTransparent();
Status |= callback();
if (Tok.is(RightK))
break;
// If the lexer stopped with an EOF token whose spelling is ")", then this
// is actually the tuple that is a string literal interpolation context.
// Just accept the ")" and build the tuple as we usually do.
if (Tok.is(tok::eof) && Tok.getText() == ")" && RightK == tok::r_paren) {
RightLoc = Tok.getLoc();
return Status;
}
// If we haven't made progress, or seeing any error, skip ahead.
if (Tok.getLoc() == StartLoc || Status.isError()) {
assert(Status.isError() && "no progress without error");
skipUntilDeclRBrace(RightK, tok::comma);
if (Tok.is(RightK) || Tok.isNot(tok::comma))
break;
}
if (consumeIf(tok::comma)) {
if (Tok.isNot(RightK))
continue;
if (!AllowSepAfterLast) {
diagnose(Tok, diag::unexpected_separator, ",")
.fixItRemove(SourceRange(PreviousLoc));
}
break;
}
// If we're in a comma-separated list, the next token is at the
// beginning of a new line and can never start an element, break.
if (Tok.isAtStartOfLine() &&
(Tok.is(tok::r_brace) || isStartOfDecl() || isStartOfStmt())) {
break;
}
// If we found EOF or such, bailout.
if (Tok.isAny(tok::eof, tok::pound_endif)) {
IsInputIncomplete = true;
break;
}
diagnose(Tok, diag::expected_separator, ",")
.fixItInsertAfter(PreviousLoc, ",");
Status.setIsParseError();
}
ListContext.reset();
if (Status.isError()) {
// If we've already got errors, don't emit missing RightK diagnostics.
RightLoc = Tok.is(RightK) ? consumeToken() : PreviousLoc;
} else if (parseMatchingToken(RightK, RightLoc, ErrorDiag, LeftLoc)) {
Status.setIsParseError();
}
return Status;
}
示例14: assert
ParserStatus
Parser::parseParameterClause(SourceLoc &leftParenLoc,
SmallVectorImpl<ParsedParameter> ¶ms,
SourceLoc &rightParenLoc,
DefaultArgumentInfo *defaultArgs,
ParameterContextKind paramContext) {
assert(params.empty() && leftParenLoc.isInvalid() &&
rightParenLoc.isInvalid() && "Must start with empty state");
// Consume the starting '(';
leftParenLoc = consumeToken(tok::l_paren);
// Trivial case: empty parameter list.
if (Tok.is(tok::r_paren)) {
rightParenLoc = consumeToken(tok::r_paren);
return ParserStatus();
}
// Parse the parameter list.
bool isClosure = paramContext == ParameterContextKind::Closure;
return parseList(tok::r_paren, leftParenLoc, rightParenLoc, tok::comma,
/*OptionalSep=*/false, /*AllowSepAfterLast=*/false,
diag::expected_rparen_parameter,
[&]() -> ParserStatus {
ParsedParameter param;
ParserStatus status;
SourceLoc StartLoc = Tok.getLoc();
unsigned defaultArgIndex = defaultArgs ? defaultArgs->NextIndex++ : 0;
// Attributes.
bool FoundCCToken;
parseDeclAttributeList(param.Attrs, FoundCCToken);
if (FoundCCToken) {
if (CodeCompletion) {
CodeCompletion->completeDeclAttrKeyword(nullptr, isInSILMode(), true);
} else {
status |= makeParserCodeCompletionStatus();
}
}
// ('inout' | 'let' | 'var')?
bool hasSpecifier = false;
while (Tok.isAny(tok::kw_inout, tok::kw_let, tok::kw_var)) {
if (!hasSpecifier) {
if (Tok.is(tok::kw_let)) {
diagnose(Tok, diag::parameter_let_as_attr)
.fixItRemove(Tok.getLoc());
} else {
// We handle the var error in sema for a better fixit and inout is
// handled later in this function for better fixits.
param.SpecifierKind = Tok.is(tok::kw_inout) ? ParsedParameter::InOut :
ParsedParameter::Var;
}
param.LetVarInOutLoc = consumeToken();
hasSpecifier = true;
} else {
// Redundant specifiers are fairly common, recognize, reject, and recover
// from this gracefully.
diagnose(Tok, diag::parameter_inout_var_let_repeated)
.fixItRemove(Tok.getLoc());
consumeToken();
}
}
if (startsParameterName(*this, isClosure)) {
// identifier-or-none for the first name
if (Tok.is(tok::kw__)) {
param.FirstNameLoc = consumeToken();
} else {
assert(Tok.canBeArgumentLabel() && "startsParameterName() lied");
param.FirstName = Context.getIdentifier(Tok.getText());
param.FirstNameLoc = consumeToken();
}
// identifier-or-none? for the second name
if (Tok.canBeArgumentLabel()) {
if (!Tok.is(tok::kw__))
param.SecondName = Context.getIdentifier(Tok.getText());
param.SecondNameLoc = consumeToken();
}
// Operators and closures cannot have API names.
if ((paramContext == ParameterContextKind::Operator ||
paramContext == ParameterContextKind::Closure) &&
!param.FirstName.empty() &&
param.SecondNameLoc.isValid()) {
diagnose(param.FirstNameLoc, diag::parameter_operator_keyword_argument,
isClosure)
.fixItRemoveChars(param.FirstNameLoc, param.SecondNameLoc);
param.FirstName = param.SecondName;
param.FirstNameLoc = param.SecondNameLoc;
param.SecondName = Identifier();
param.SecondNameLoc = SourceLoc();
}
// (':' type)?
if (consumeIf(tok::colon)) {
//.........这里部分代码省略.........
示例15: createEntity
bool StateActions::createEntity(const ParserStatus & parser, const QString & argument)
{
Q_UNUSED(argument);
bool result = parser.contentHandler()->skippedEntity(parser.m_buffer);
return result;
}