use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class StatementParsing method parseImportElements.
private void parseImportElements(IElementType elementType, boolean is_module_import, boolean in_parens, final boolean from_future) {
PsiBuilder builder = myContext.getBuilder();
while (true) {
final PsiBuilder.Marker asMarker = builder.mark();
if (is_module_import) {
// import _
if (!parseDottedNameAsAware(true, false)) {
asMarker.drop();
break;
}
} else {
// from X import _
String token_text = parseIdentifier(getReferenceType());
if (from_future) {
// TODO: mark all known future feature names
if (TOK_WITH_STATEMENT.equals(token_text)) {
myFutureFlags.add(FUTURE.WITH_STATEMENT);
} else if (TOK_NESTED_SCOPES.equals(token_text)) {
myFutureFlags.add(FUTURE.NESTED_SCOPES);
} else if (TOK_PRINT_FUNCTION.equals(token_text)) {
myFutureFlags.add(FUTURE.PRINT_FUNCTION);
}
}
}
// possible 'as' comes as an ident; reparse it as keyword if found
setExpectAsKeyword(true);
if (builder.getTokenType() == PyTokenTypes.AS_KEYWORD) {
builder.advanceLexer();
setExpectAsKeyword(false);
parseIdentifier(PyElementTypes.TARGET_EXPRESSION);
}
asMarker.done(elementType);
setExpectAsKeyword(false);
if (builder.getTokenType() == PyTokenTypes.COMMA) {
builder.advanceLexer();
if (in_parens && builder.getTokenType() == PyTokenTypes.RPAR) {
break;
}
} else {
break;
}
}
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class RestParser method parseMarkup.
private static void parseMarkup(PsiBuilder builder) {
PsiBuilder.Marker marker = builder.mark();
IElementType type = builder.getTokenType();
if (type == RestTokenTypes.SUBSTITUTION) {
builder.advanceLexer();
marker.done(RestElementTypes.REFERENCE_TARGET);
builder.advanceLexer();
marker = builder.mark();
type = builder.getTokenType();
}
if (type == RestTokenTypes.DIRECTIVE) {
gotoNextWhiteSpaces(builder);
if (builder.getTokenType() != RestTokenTypes.WHITESPACE) {
builder.advanceLexer();
marker.done(RestElementTypes.DIRECTIVE_BLOCK);
return;
}
skipBlankLines(builder);
if (builder.getTokenType() != RestTokenTypes.WHITESPACE || "\n".equals(builder.getTokenText())) {
marker.done(RestElementTypes.DIRECTIVE_BLOCK);
return;
}
String white = builder.getTokenText();
parseDirective(builder, white, marker);
} else if (type == RestTokenTypes.FOOTNOTE || type == RestTokenTypes.CITATION || type == RestTokenTypes.HYPERLINK || type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
builder.advanceLexer();
marker.done(RestElementTypes.REFERENCE_TARGET);
} else {
builder.advanceLexer();
marker.drop();
}
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class RestParser method parse.
@NotNull
public ASTNode parse(IElementType root, PsiBuilder builder) {
final PsiBuilder.Marker rootMarker = builder.mark();
while (!builder.eof()) {
IElementType type = builder.getTokenType();
if (type == RestTokenTypes.EXPLISIT_MARKUP_START) {
builder.advanceLexer();
parseMarkup(builder);
} else if (type == RestTokenTypes.REFERENCE_NAME || type == RestTokenTypes.SUBSTITUTION) {
PsiBuilder.Marker marker = builder.mark();
builder.advanceLexer();
marker.done(RestTokenTypes.REFERENCE_NAME);
} else if (type == RestTokenTypes.TITLE) {
PsiBuilder.Marker marker = builder.mark();
builder.advanceLexer();
marker.done(RestTokenTypes.TITLE);
} else if (type == RestTokenTypes.FIELD) {
parseFieldList(builder);
} else if (type == RestTokenTypes.INLINE_LINE) {
PsiBuilder.Marker marker = builder.mark();
builder.advanceLexer();
marker.done(RestElementTypes.INLINE_BLOCK);
} else if (type == RestTokenTypes.ANONYMOUS_HYPERLINK) {
PsiBuilder.Marker marker = builder.mark();
builder.advanceLexer();
marker.done(RestElementTypes.REFERENCE_TARGET);
} else if (type == RestTokenTypes.LINE) {
parseLineText(builder, type);
} else
builder.advanceLexer();
}
rootMarker.done(root);
return builder.getTreeBuilt();
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class XPath2Parser method parseSequenceType.
private boolean parseSequenceType(PsiBuilder builder) {
PsiBuilder.Marker mark = builder.mark();
final IElementType type = parseItemOrEmptySequenceType(builder);
if (type != null) {
if (type == XPath2TokenTypes.ITEM) {
if (XPath2TokenTypes.OCCURRENCE_OPS.contains(builder.getTokenType())) {
makeToken(builder);
}
}
mark.done(XPath2ElementTypes.SEQUENCE_TYPE);
return true;
} else if (parseNodeType(builder) || parseQName(builder)) {
if (builder.getTokenType() == XPathTokenTypes.MULT) {
builder.remapCurrentToken(XPathTokenTypes.STAR);
}
if (XPath2TokenTypes.OCCURRENCE_OPS.contains(builder.getTokenType())) {
makeToken(builder);
}
mark.done(XPath2ElementTypes.SEQUENCE_TYPE);
return true;
}
mark.drop();
return false;
}
use of com.intellij.lang.PsiBuilder in project intellij-community by JetBrains.
the class XPathParser method parseAxisSpecifier.
/**
* [5] AxisSpecifier ::= AxisName '::' | AbbreviatedAxisSpecifier
* <p/>
* [13] AbbreviatedAxisSpecifier ::= '@'?
*/
private boolean parseAxisSpecifier(PsiBuilder builder) {
final PsiBuilder.Marker marker = builder.mark();
final IElementType tokenType = builder.getTokenType();
if (XPathTokenTypes.AXIS.contains(tokenType)) {
builder.advanceLexer();
checkMatches(builder, XPathTokenTypes.COLCOL, ":: expected");
} else {
if (tokenType == XPathTokenTypes.AT) {
builder.advanceLexer();
} else if (tokenType == XPathTokenTypes.DOT || tokenType == XPathTokenTypes.DOTDOT) {
marker.drop();
return false;
} else {
final PsiBuilder.Marker m = builder.mark();
final boolean b = parseNodeTest(builder);
m.rollbackTo();
if (!b) {
marker.drop();
return false;
}
}
}
marker.done(XPathElementTypes.AXIS_SPECIFIER);
return true;
}
Aggregations