Java Code Examples for com.intellij.lang.PsiBuilder.advanceLexer()

The following are Jave code examples for showing how to use advanceLexer() of the com.intellij.lang.PsiBuilder class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 6 votes
private static boolean parseCommandParameterSelector(PsiBuilder b, int l, AppleScriptCommand command,
                                                     StringHolder parsedParameterSelector) {
  if (!recursion_guard_(b, l, "parseCommandParameterSelector")) return false;
  boolean r = false;
  PsiBuilder.Marker m = enter_section_(b, l, _NONE_, "<parse Command Parameter Selector>");//todo check this _AND_
  parsedParameterSelector.value = b.getTokenText() == null ? "" : b.getTokenText();
  while (!b.eof() && b.getTokenType() != NLS && b.getTokenType() != COMMENT) {
    b.advanceLexer();
    if (command.getParameterByName(parsedParameterSelector.value) != null) {
      r = true;
      break;
    }
    parsedParameterSelector.value += " " + b.getTokenText();
  }
  exit_section_(b, l, m, COMMAND_PARAMETER_SELECTOR, r, false, null);
  return r;
}
 
Example 2
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 6 votes
private static boolean parseStdLibCommandName(PsiBuilder b, int l, StringHolder parsedName) {
  if (!recursion_guard_(b, l, "parseStdLibCommandName")) return false;
  boolean r = false;
  parsedName.value = "";
  parsedName.value = b.getTokenText() == null ? "" : b.getTokenText();
  PsiBuilder.Marker m = enter_section_(b);
  boolean commandWithPrefixExists = ParsableScriptSuiteRegistryHelper.isStdCommandWithPrefixExist(parsedName.value);
  String nextTokenText = parsedName.value;
  while (b.getTokenText() != null && commandWithPrefixExists) {
    b.advanceLexer(); //advance lexer in any case
    nextTokenText += " " + b.getTokenText();
    commandWithPrefixExists = ParsableScriptSuiteRegistryHelper.isStdCommandWithPrefixExist(nextTokenText);
    if (commandWithPrefixExists) {
      parsedName.value = nextTokenText;
    } else if (ParsableScriptSuiteRegistryHelper.isStdCommand(parsedName.value)) {
      r = true;
      break;
    }
  }
  exit_section_(b, m, null, r);
  return r;
}
 
Example 3
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 6 votes
/**
 * @param b {@link PsiBuilder}
 * @param l level deep
 * @return true if parsed token(s) is the property of the scripting additions library
 */
private static boolean tryToParseStdProperty(PsiBuilder b, int l) {
  if (!recursion_guard_(b, l, "tryToParseStdProperty")) return false;
  boolean r = false;
  PsiBuilder.Marker m = enter_section_(b);
  StringHolder currentTokenText = new StringHolder();
  currentTokenText.value = b.getTokenText() == null ? "" : b.getTokenText();
  boolean propertyWithPrefixExists = ParsableScriptSuiteRegistryHelper
          .isStdPropertyWithPrefixExist(currentTokenText.value);
  String nextTokenText = currentTokenText.value;
  while (b.getTokenText() != null && propertyWithPrefixExists) {
    b.advanceLexer(); //advance lexer in any case
    nextTokenText += " " + b.getTokenText();
    propertyWithPrefixExists = ParsableScriptSuiteRegistryHelper.isStdPropertyWithPrefixExist(nextTokenText);
    if (propertyWithPrefixExists) {
      currentTokenText.value = nextTokenText;
    } else if (ParsableScriptSuiteRegistryHelper.isStdProperty(currentTokenText.value)) {
      r = true;
      break;
    }
  }
  exit_section_(b, m, null, r);
  return r;
}
 
Example 4
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 6 votes
/**
 * @param b               {@link PsiBuilder}
 * @param l               level deep
 * @param applicationName name of the application
 * @return true if parsed token(s) is the property of the specified application
 */
private static boolean tryToParseApplicationProperty(PsiBuilder b, int l, @NotNull String applicationName) {
  if (!recursion_guard_(b, l, "tryToParseApplicationProperty")) return false;
  boolean r = false;
  PsiBuilder.Marker m = enter_section_(b);
  StringHolder currentTokenText = new StringHolder();
  currentTokenText.value = b.getTokenText() == null ? "" : b.getTokenText();
  boolean propertyWithPrefixExist = ParsableScriptSuiteRegistryHelper.isPropertyWithPrefixExist(applicationName,
          currentTokenText.value);
  //find the longest lexeme
  String nextTokenText = currentTokenText.value;
  while (b.getTokenText() != null && propertyWithPrefixExist) {
    b.advanceLexer(); //advance lexer in any case
    nextTokenText += " " + b.getTokenText();
    propertyWithPrefixExist = ParsableScriptSuiteRegistryHelper.isPropertyWithPrefixExist(applicationName,
            nextTokenText);
    if (propertyWithPrefixExist) {
      currentTokenText.value = nextTokenText;
    } else if (ParsableScriptSuiteRegistryHelper.isApplicationProperty(applicationName, currentTokenText.value)) {
      r = true;
      break;
    }
  }
  exit_section_(b, m, null, r);
  return r;
}
 
Example 5
Project: reasonml-idea-plugin   File: RmlParser.java   Source Code and License Vote up 6 votes
private void parseGtAutoClose(PsiBuilder builder, ParserState parserState) {
    if (parserState.currentScope.tokenType == m_types.TAG_PROPERTY) {
        parserState.currentScope.end();
        parserState.scopes.pop();
        parserState.currentScope = parserState.scopes.empty() ? parserState.fileScope : parserState.scopes.peek();
    }

    if (parserState.currentScope.resolution == startTag || parserState.currentScope.resolution == closeTag) {
        builder.remapCurrentToken(m_types.TAG_GT);
        builder.advanceLexer();
        parserState.dontMove = true;

        parserState.currentScope.end();
        parserState.scopes.pop();

        parserState.currentScope = parserState.scopes.empty() ? parserState.fileScope : parserState.scopes.peek();
    }
}
 
Example 6
Project: reasonml-idea-plugin   File: RmlParser.java   Source Code and License Vote up 6 votes
private void parseLt(PsiBuilder builder, ParserState parserState) {
    // Can be a symbol or a JSX tag
    IElementType nextTokenType = builder.rawLookup(1);
    if (nextTokenType == m_types.LIDENT || nextTokenType == m_types.UIDENT) {
        // Surely a tag
        builder.remapCurrentToken(m_types.TAG_LT);
        parserState.currentScope = markScope(builder, parserState.scopes, startTag, m_types.TAG_START, groupExpression, m_types.TAG_LT);
        parserState.currentScope.complete = true;

        builder.advanceLexer();
        parserState.dontMove = true;
        builder.remapCurrentToken(m_types.TAG_NAME);
    } else if (nextTokenType == m_types.SLASH) {
        builder.remapCurrentToken(m_types.TAG_LT);
        parserState.currentScope = markScope(builder, parserState.scopes, closeTag, m_types.TAG_CLOSE, any, m_types.TAG_LT);
        parserState.currentScope.complete = true;
    }
}
 
Example 7
Project: reasonml-idea-plugin   File: RmlParser.java   Source Code and License Vote up 6 votes
private void parseRParen(PsiBuilder builder, ParserState parserState) {
    ParserScope scope = parserState.endUntilScopeExpression(m_types.LPAREN);

    builder.advanceLexer();
    parserState.dontMove = true;

    if (scope != null) {
        scope.complete = true;
        parserState.scopes.pop().end();
        scope = parserState.getLatestScope();
        if (scope != null && scope.resolution == letNamedEq) {
            scope.resolution = letNamedEqParameters;
        }
    }

    parserState.updateCurrentScope();
}
 
Example 8
Project: reasonml-idea-plugin   File: OclParser.java   Source Code and License Vote up 6 votes
private void parseEq(PsiBuilder builder, ParserState parserState) {
    if (parserState.isCurrentResolution(typeNamed)) {
        parserState.currentScope.resolution = typeNamedEq;
    } else if (parserState.isCurrentResolution(letNamed)) {
        parserState.currentScope.resolution = letNamedEq;
        builder.advanceLexer();
        parserState.dontMove = true;
        parserState.currentScope = markScope(builder, parserState.scopes, letNamedEq, m_types.LET_BINDING, groupExpression, m_types.EQ);
        parserState.currentScope.complete = true;
    } else if (parserState.isCurrentResolution(tagProperty)) {
        parserState.currentScope.resolution = tagPropertyEq;
    } else if (parserState.isCurrentResolution(moduleNamed)) {
        parserState.currentScope.resolution = moduleNamedEq;
        parserState.currentScope.complete = true;
    }
}
 
Example 9
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 5 votes
private static boolean tryToParseStdConstant(PsiBuilder b, int l) {
  if (!recursion_guard_(b, l, "tryToParseStdConstant")) return false;
  StringHolder currentTokenText = new StringHolder();
  currentTokenText.value = b.getTokenText() == null ? "" : b.getTokenText();
  boolean r = false, propertyOrClassExists = false, constantWithPrefixExists = ParsableScriptSuiteRegistryHelper
          .isStdConstantWithPrefixExist(currentTokenText.value);
  String nextTokenText = currentTokenText.value;
  PsiBuilder.Marker m = enter_section_(b);
  while (b.getTokenText() != null && constantWithPrefixExists) {
    b.advanceLexer();
    nextTokenText += " " + b.getTokenText();
    constantWithPrefixExists = ParsableScriptSuiteRegistryHelper.isStdConstantWithPrefixExist(nextTokenText);
    if (constantWithPrefixExists) {
      currentTokenText.value = nextTokenText;
    } else if (ParsableScriptSuiteRegistryHelper.isStdConstant(currentTokenText.value)) {
      r = true;
      break;
    }
  }
  if (r) {
    // grammar allows className and propertyName as primaryExpression, so we should match the longest token between
    // className or propertyName tokens. We check and return false if the property or class with the longer name
    // exists, as it will be parsed later
    currentTokenText.value += " " + b.getTokenText();
    propertyOrClassExists = ParsableScriptSuiteRegistryHelper
            .isStdPropertyWithPrefixExist(currentTokenText.value) ||
            ParsableScriptSuiteRegistryHelper
                    .isStdClassWithPrefixExist(currentTokenText.value);
  }
  r = r && !propertyOrClassExists;
  exit_section_(b, m, null, r);
  return r;
}
 
Example 10
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 5 votes
private static boolean tryToParseApplicationConstant(PsiBuilder b, int l, @NotNull String applicationName) {
  if (!recursion_guard_(b, l, "tryToParseApplicationConstant")) return false;
  StringHolder currentTokenText = new StringHolder();
  currentTokenText.value = b.getTokenText() == null ? "" : b.getTokenText();
  boolean r = false, propertyOrClassExists = false, constantWithPrefixExists = ParsableScriptSuiteRegistryHelper
          .isConstantWithPrefixExist(applicationName, currentTokenText.value);
  String nextTokenText = currentTokenText.value;
  PsiBuilder.Marker m = enter_section_(b);
  while (b.getTokenText() != null && constantWithPrefixExists) {
    b.advanceLexer();
    nextTokenText += " " + b.getTokenText();
    constantWithPrefixExists = ParsableScriptSuiteRegistryHelper
            .isConstantWithPrefixExist(applicationName, nextTokenText);
    if (constantWithPrefixExists) {
      currentTokenText.value = nextTokenText;
    } else if (ParsableScriptSuiteRegistryHelper.isApplicationConstant(applicationName, currentTokenText.value)) {
      r = true;
      break;
    }
  }
  if (r) {
    // grammar allows className and propertyName as primaryExpression, so we should match the longest token between
    // className or propertyName tokens. We check and return false if the property or class with the longer name
    // exists, as it will be parsed later
    propertyOrClassExists = ParsableScriptSuiteRegistryHelper
            .isPropertyWithPrefixExist(applicationName, currentTokenText.value) ||
            ParsableScriptSuiteRegistryHelper
                    .isClassWithPrefixExist(applicationName, currentTokenText.value);
    if (propertyOrClassExists) {
      currentTokenText.value += " " + b.getTokenText();
      propertyOrClassExists = ParsableScriptSuiteRegistryHelper
              .isPropertyWithPrefixExist(applicationName, currentTokenText.value) ||
              ParsableScriptSuiteRegistryHelper
                      .isClassWithPrefixExist(applicationName, currentTokenText.value);
    }
  }
  r = r && !propertyOrClassExists;
  exit_section_(b, m, null, r);
  return r;
}
 
Example 11
Project: reasonml-idea-plugin   File: RmlParser.java   Source Code and License Vote up 5 votes
private void parseRBracket(PsiBuilder builder, ParserState parserState) {
    ParserScope scope = parserState.endUntilScopeExpression(m_types.LBRACKET);

    builder.advanceLexer();
    parserState.dontMove = true;

    if (scope != null) {
        if (scope.resolution != annotation) {
            scope.complete = true;
        }
        parserState.scopes.pop().end();
    }

    parserState.updateCurrentScope();
}
 
Example 12
Project: reasonml-idea-plugin   File: RmlParser.java   Source Code and License Vote up 5 votes
private void parseRBrace(PsiBuilder builder, ParserState parserState) {
    ParserScope scope = parserState.endUntilScopeExpression(m_types.LBRACE);

    builder.advanceLexer();
    parserState.dontMove = true;

    if (scope != null) {
        scope.complete = true;
        parserState.scopes.pop().end();
    }

    parserState.updateCurrentScope();
}
 
Example 13
Project: reasonml-idea-plugin   File: RmlParser.java   Source Code and License Vote up 5 votes
private void parseSemi(PsiBuilder builder, ParserState parserState) {
    // End current start-expression scope
    ParserScope scope = parserState.endUntilStart();
    if (scope != null && scope.scopeType == startExpression) {
        builder.advanceLexer();
        parserState.dontMove = true;
        parserState.scopes.pop();
        scope.end();
    }

    parserState.updateCurrentScope();
}
 
Example 14
Project: reasonml-idea-plugin   File: OclParser.java   Source Code and License Vote up 5 votes
private void parseEnd(PsiBuilder builder, ParserState parserState) {
    ParserScope scope = parserState.endUntilScopeExpression(null);

    builder.advanceLexer();
    parserState.dontMove = true;

    if (scope != null) {
        scope.complete = true;
        parserState.scopes.pop().end();
    }

    parserState.updateCurrentScope();
}
 
Example 15
Project: reasonml-idea-plugin   File: OclParser.java   Source Code and License Vote up 5 votes
private void parseRParen(PsiBuilder builder, ParserState parserState) {
    ParserScope scope = parserState.endUntilScopeExpression(m_types.LPAREN);

    builder.advanceLexer();
    parserState.dontMove = true;

    if (scope != null) {
        scope.complete = true;
        parserState.scopes.pop().end();
        parserState.getLatestScope();
    }

    parserState.updateCurrentScope();
}
 
Example 16
Project: reasonml-idea-plugin   File: OclParser.java   Source Code and License Vote up 5 votes
private void parseRBrace(PsiBuilder builder, ParserState parserState) {
    ParserScope scope = parserState.endUntilScopeExpression(m_types.LBRACE);

    builder.advanceLexer();
    parserState.dontMove = true;

    if (scope != null) {
        scope.complete = true;
        parserState.scopes.pop().end();
    }

    parserState.updateCurrentScope();
}
 
Example 17
Project: reasonml-idea-plugin   File: OclParser.java   Source Code and License Vote up 5 votes
private void parseRBracket(PsiBuilder builder, ParserState parserState) {
    ParserScope scope = parserState.endUntilScopeExpression(m_types.LBRACKET);

    builder.advanceLexer();
    parserState.dontMove = true;

    if (scope != null) {
        if (scope.resolution != annotation) {
            scope.complete = true;
        }
        parserState.scopes.pop().end();
    }

    parserState.currentScope = parserState.scopes.empty() ? parserState.fileScope : parserState.scopes.peek();
}
 
Example 18
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 4 votes
/**
   * @param b               {@link PsiBuilder}
   * @param l               level deep
   * @param parsedName      holder for parsed term string
   * @param applicationName name of the application, which dictionary terms will be queried
   * @param checkStdLib     whether to check in scripting additions library if no terms were found in this application
   * @return true if command name was parsed
   */
  private static boolean parseCommandNameForApplication(PsiBuilder b, int l,
                                                        StringHolder parsedName,
                                                        @NotNull String applicationName,
                                                        boolean checkStdLib) {
    if (!recursion_guard_(b, l, "parseCommandNameForApplication")) return false;
    boolean r = false;
    parsedName.value = "";
    PsiBuilder.Marker m = enter_section_(b);
    parsedName.value = b.getTokenText() == null ? "" : b.getTokenText();

    boolean commandWithPrefixExists = ParsableScriptSuiteRegistryHelper.isCommandWithPrefixExist(applicationName,
            parsedName.value);
    String nextTokenText = parsedName.value;
    while (b.getTokenText() != null && commandWithPrefixExists) {
      b.advanceLexer(); //advance lexer to the next token
      nextTokenText += " " + b.getTokenText();
      commandWithPrefixExists = ParsableScriptSuiteRegistryHelper
              .isCommandWithPrefixExist(applicationName, nextTokenText);
      if (commandWithPrefixExists) {
        //if command with prefix exists, append token text
        parsedName.value = nextTokenText;
      } else if (ParsableScriptSuiteRegistryHelper.isApplicationCommand(applicationName, parsedName.value)) {
        //if there is std command with longer prefix exists do not parse it here
        r = !checkStdLib || !ParsableScriptSuiteRegistryHelper.isStdCommandWithPrefixExist(nextTokenText);
        // if there is class name with longer prefix exists !! AND !! next is NLS token => do not this as command name
//        boolean longerClassNameExists = ParsableScriptSuiteRegistryHelper
//                .isClassWithPrefixExist(applicationName, nextTokenText);
//        if (r && longerClassNameExists) {
//          while (b.getTokenType() != NLS) {
//            b.advanceLexer();
//            nextTokenText += " " + b.getTokenText();
//          }
//          r = ParsableScriptSuiteRegistryHelper.isApplicationClass(applicationName, nextTokenText);
//        }
        r = r && !ParsableScriptSuiteRegistryHelper.isClassWithPrefixExist(applicationName, nextTokenText);
        break;
      }
    }
    exit_section_(b, m, null, r);
    return r;
  }
 
Example 19
Project: reasonml-idea-plugin   File: CommonParser.java   Source Code and License Vote up 4 votes
protected boolean advance(PsiBuilder builder) {
    builder.advanceLexer();
    return true;
}
 
Example 20
Project: reasonml-idea-plugin   File: RmlParser.java   Source Code and License Vote up 4 votes
@Override
protected void parseFile(PsiBuilder builder, ParserState parserState) {
    IElementType tokenType = null;

    int c = current_position_(builder);
    while (true) {
        parserState.previousTokenType = tokenType;
        tokenType = builder.getTokenType();
        if (tokenType == null) {
            break;
        }

        if (tokenType == m_types.SEMI) {
            parseSemi(builder, parserState);
        } else if (tokenType == m_types.EQ) {
            parseEq(parserState);
        } else if (tokenType == m_types.ARROW) {
            parseArrow(builder, parserState);
        } else if (tokenType == m_types.TRY) {
            parseTry(builder, parserState);
        } else if (tokenType == m_types.SWITCH) {
            parseSwitch(builder, parserState);
        } else if (tokenType == m_types.LIDENT) {
            parseLIdent(builder, parserState);
        } else if (tokenType == m_types.UIDENT) {
            parseUIdent(builder, parserState);
        } else if (tokenType == m_types.ARROBASE) {
            parseArrobase(builder, parserState);
        } else if (tokenType == m_types.PERCENT) {
            parsePercent(builder, parserState);
        }
        // ( ... )
        else if (tokenType == m_types.LPAREN) {
            parseLParen(builder, parserState);
        } else if (tokenType == m_types.RPAREN) {
            parseRParen(builder, parserState);
        }
        // { ... }
        else if (tokenType == m_types.LBRACE) {
            parseLBrace(builder, parserState);
        } else if (tokenType == m_types.RBRACE) {
            parseRBrace(builder, parserState);
        }
        // [ ... ]
        else if (tokenType == m_types.LBRACKET) {
            parseLBracket(builder, parserState);
        } else if (tokenType == m_types.RBRACKET) {
            parseRBracket(builder, parserState);
        }
        // < ... >
        else if (tokenType == m_types.LT) {
            parseLt(builder, parserState);
        } else if (tokenType == m_types.GT || tokenType == m_types.TAG_AUTO_CLOSE) {
            parseGtAutoClose(builder, parserState);
        }
        // Starts an expression
        else if (tokenType == m_types.OPEN) {
            parseOpen(builder, parserState);
        } else if (tokenType == m_types.EXTERNAL) {
            parseExternal(builder, parserState);
        } else if (tokenType == m_types.TYPE) {
            parseType(builder, parserState);
        } else if (tokenType == m_types.MODULE) {
            parseModule(builder, parserState);
        } else if (tokenType == m_types.LET) {
            parseLet(builder, parserState);
        }

        if (parserState.dontMove) {
            parserState.dontMove = false;
        } else {
            builder.advanceLexer();
        }

        if (!empty_element_parsed_guard_(builder, "reasonFile", c)) {
            break;
        }

        c = builder.rawTokenIndex();
    }
}