Java Code Examples for com.intellij.lang.PsiBuilder.Marker

The following are Jave code examples for showing how to use Marker 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: TS-IJ   File: TSParserUtil.java   Source Code and License Vote up 6 votes
public static boolean parseExpressionStmtGroup(PsiBuilder b, int l) {
    if (!recursion_guard_(b, l, "expr_stmt_group")) return false;
    boolean r;
    PsiBuilder.Marker m = enter_section_(b);
    r = object_expr(b, l + 1);

    //Need to do these first since they match with expr
    if (!r) r = assign_ref_expr(b, l + 1);
    if (!r) r = assign_ref_index_expr(b, l + 1);
    if (!r) r = call_method_expr(b, l + 1);

    //If none of those wonky rules succeed, do the decent ones
    if (!r) r = assign_var_expr(b, l + 1);
    if (!r) r = assign_index_expr(b, l + 1);
    if (!r) r = call_global_expr(b, l + 1);
    if (!r) r = call_global_ns_expr(b, l + 1);
    exit_section_(b, m, null, r);
    return r;
}
 
Example 2
Project: TS-IJ   File: TSParserUtil.java   Source Code and License Vote up 6 votes
private static boolean assign_ref_expr(PsiBuilder b, int l) {
    //So this is rather wonky. What we do here is try to parse the incoming nodes as an expression,
    // as assign_ref_expr (and the below rules) need an expression as the first argument, but
    // you can chain them together. And calling expr will eat the assign_ref_expr when it parses.
    //So to get to the point here:
    // We run expr() and then see what it comes up with. If the last node (basically the expression
    // that it parsed from the call) is of our type, then we successfully parsed it.
    boolean r;
    PsiBuilder.Marker m = enter_section_(b);
    //Group -1 so we parse whatever expression is next
    r = expr(b, l + 1, -1);
    if (r) {
        //If we parsed an expression, check if we parsed the type we'ere looking for
        PsiBuilderImpl.ProductionMarker last = (PsiBuilderImpl.ProductionMarker) b.getLatestDoneMarker();
        r = last != null && last.getTokenType().equals(ASSIGN_REF_EXPR);
    }
    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
public static boolean parseApplicationHandlerDefinitionSignature(PsiBuilder b, int l) {
  if (!recursion_guard_(b, l, "parseApplicationHandlerDefinitionSignature")) return false;
  boolean r;
  //application handled definition in script only makes sense inside <using terms of> statement
  if (b.getUserData(IS_PARSING_USING_TERMS_FROM_STATEMENT) != Boolean.TRUE || b.getUserData(PARSING_TELL_COMPOUND_STATEMENT) == Boolean.TRUE) return false;

  StringHolder parsedCommandName = new StringHolder();
  String toldApplicationName = getTargetApplicationName(b);
  PsiBuilder.Marker m2 = enter_section_(b, l, _COLLAPSE_, "<parse Application Handler Definition");
  r = parseDictionaryCommandNameInner(b, l + 1, parsedCommandName, toldApplicationName, true, null);
  exit_section_(b, l, m2, DICTIONARY_COMMAND_NAME, r, false, null);

  if (!r) return false;
  // TODO: 06/12/15 may be try to avoid creating PSI here!..
  List<AppleScriptCommand> allCommandsWithName = getAllCommandsWithName(b, parsedCommandName.value, toldApplicationName, false, null);

  for (AppleScriptCommand command : allCommandsWithName) {
    r = parseParametersForCommand(b, l + 1, command);//custom parsing here
    if (r) {
      break;
    }
  }
  boolean incompleteHandlerCall = !r && allCommandsWithName.size() > 0 && (b.getTokenType() == NLS || b.eof());
  return r || incompleteHandlerCall;

}
 
Example 5
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 6 votes
/**
   * If inside tell (only in a tell?) compound statement - first check it's terms
   */
  public static boolean parseExpression(PsiBuilder b, int l, String dictionaryTermToken, Parser expression) {
    if (!recursion_guard_(b, l, "parseExpression")) return false;
    if (!nextTokenIsFast(b, dictionaryTermToken)) return false;
    boolean r;

    //check application terms first
    if (b.getUserData(PARSING_TELL_COMPOUND_STATEMENT) == Boolean.TRUE) {
      String toldAppName = peekTargetApplicationName(b);
      if (!StringUtil.isEmpty(toldAppName)) {
        StringHolder parsedName = new StringHolder();
        PsiBuilder.Marker mComName = enter_section_(b, l, _AND_, "<parse Expression>");
        r = parseCommandNameForApplication(b, l + 1, parsedName, toldAppName, true);
        exit_section_(b, l, mComName, null, r, false, null);
        if (r) return false;
        if (ParsableScriptSuiteRegistryHelper.isPropertyWithPrefixExist(toldAppName, dictionaryTermToken)) {
          return false;
//          PsiBuilder.Marker m = enter_section_(b, l, _AND_, null, "<dictionary constant>");
//          r = parseDictionaryConstant(b, l + 1);
//          exit_section_(b, l, m, r, false, null);
//          if (r) return false;
        }
      }
    }
    return expression.parse(b, l + 1);
  }
 
Example 6
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 7
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 8
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 6 votes
public static boolean parseDictionaryCommandName(PsiBuilder b, int l) {
  boolean r;
  if (nextTokenIs(b, NLS)) {
    return false;
  }
  StringHolder parsedCommandName = new StringHolder();
  String toldApplicationName = getTargetApplicationName(b);
  boolean areThereUseStatements = b.getUserData(WAS_USE_STATEMENT_USED) == Boolean.TRUE;
  Set<String> applicationsToImport = null;
  if (areThereUseStatements) {
    applicationsToImport = b.getUserData(USED_APPLICATION_NAMES);
  }
  PsiBuilder.Marker m = enter_section_(b, l, _COLLAPSE_, "<parse ApplicationDictionary Command Name>");
  r = parseDictionaryCommandNameInner(b, l + 1, parsedCommandName, toldApplicationName, areThereUseStatements, applicationsToImport);
  exit_section_(b, l, m, DICTIONARY_COMMAND_NAME, r, false, null);
  return r;
}
 
Example 9
Project: TS-IJ   File: TSParserUtil.java   Source Code and License Vote up 5 votes
private static boolean call_method_expr(PsiBuilder b, int l) {
    //See assign_ref_expr for explanation
    boolean r;
    PsiBuilder.Marker m = enter_section_(b);
    r = expr(b, l + 1, -1);
    if (r) {
        PsiBuilderImpl.ProductionMarker last = (PsiBuilderImpl.ProductionMarker)b.getLatestDoneMarker();
        r = last != null && last.getTokenType().equals(CALL_METHOD_EXPR);
    }
    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: 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 12
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 5 votes
/**
 * @param b                           {@link PsiBuilder}
 * @param l                           Level deep
 * @param tellStatementStartCondition If this is the application reference of a &lt;tell&gt; or &lt;using terms
 *                                    from&gt; statements
 * @return true if parsed
 */
public static boolean parseApplicationName(PsiBuilder b, int l, Parser tellStatementStartCondition) {
  if (!recursion_guard_(b, l, "parseApplicationName")) return false;
  boolean r;
  consumeToken(b, THE_KW);
  if (!nextTokenIs(b, "", APPLICATION, APP)) return false;

  PsiBuilder.Marker mCls = enter_section_(b, l, _NONE_, "<parse application name>");
  r = consumeToken(b, APPLICATION);
  if (!r) r = consumeToken(b, APP);
  exit_section_(b, l, mCls, DICTIONARY_CLASS_NAME, r, false, null);

  if (!nextTokenIs(b, "", STRING_LITERAL, ID)) return false;
  PsiBuilder.Marker mProp = enter_section_(b, l, _NONE_, "<parse application name>");
  boolean idReference = consumeToken(b, ID);
  exit_section_(b, l, mProp, DICTIONARY_PROPERTY_NAME, idReference, false, null);
  PsiBuilder.Marker m = enter_section_(b);
  String applicationNameString = b.getTokenText();
  r = consumeToken(b, STRING_LITERAL);

  // if this is start of <tell compound> or <tell simple> or <using terms from> statements, push the application name
  // which dictionary will be consulted for terms parsing (only the last pushed application is queried)
  if (r && applicationNameString != null) {
    applicationNameString = applicationNameString.replace("\"", "");
    if (!StringUtil.isEmptyOrSpaces(applicationNameString) && tellStatementStartCondition.parse(b, l + 1)) {
      pushTargetApplicationName(b, applicationNameString);
    }
  }
  exit_section_(b, m, null, r);
  return r;
}
 
Example 13
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 5 votes
private static boolean parseParameterForCommand(PsiBuilder b, int l, AppleScriptCommand command,
                                                StringHolder parsedParameterSelector, boolean givenForm, boolean
                                                        first) {
  if (!recursion_guard_(b, l, "parseParameterForCommand")) return false;
  boolean r;
  PsiBuilder.Marker m = enter_section_(b, l, _NONE_, "<parse Parameter For Command>");//todo check here if it works
  r = parseGivenParameter(b, l + 1, command, parsedParameterSelector, givenForm, first);
  //todo and here exit and enter once again if it is true??
  if (!r) r = parseBooleanParameter(b, l + 1, command, parsedParameterSelector);

  exit_section_(b, l, m, COMMAND_PARAMETER, r, false, null);
  return r;
}
 
Example 14
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 5 votes
private static boolean parseBooleanParameter(PsiBuilder b, int l, AppleScriptCommand command, StringHolder
        parsedParameterSelector) {
  if (!recursion_guard_(b, l, "parseBooleanParameter")) return false;
  boolean r;
  //need to rollback with/without if there is no match
  PsiBuilder.Marker m = enter_section_(b, l, _NONE_, "<parse Boolean Parameter>");
  b.putUserData(PARSING_COMMAND_HANDLER_BOOLEAN_PARAMETER, true);
  r = consumeToken(b, WITH);
  if (!r) r = consumeToken(b, WITHOUT);
  if (!r) r = consumeToken(b, LAND); //for cases like: '...with regexp and all occurrences without case sensitive'
  r = r && parseCommandParameterSelector(b, l + 1, command, parsedParameterSelector);
  exit_section_(b, l, m, null, r, false, null);
  b.putUserData(PARSING_COMMAND_HANDLER_BOOLEAN_PARAMETER, false);
  return r;
}
 
Example 15
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 5 votes
private static boolean parseGivenParameter(PsiBuilder b, int l, AppleScriptCommand command,
                                           StringHolder parsedParameterSelector, boolean givenForm, boolean first) {
  if (!recursion_guard_(b, l, "parseGivenParameter")) return false;
  PsiBuilder.Marker m = enter_section_(b, l, _NONE_, "<parse Given Parameter>");
  boolean r = !givenForm || first || consumeToken(b, COMMA);//if it is a given form and not the first parameter ->
  // should be comma
  r = r && parseCommandParameterSelector(b, l + 1, command, parsedParameterSelector);
  final CommandParameter parameterDefinition = command.getParameterByName(parsedParameterSelector.value);
  //todo: parameter value expression could be incorrectly parsed and needed to be rolled backed (__AND__ modifier?)
  //as in example: mount volume "" in AppleTalk zone ""  (in - parsed as range ref form)
  if (givenForm) r = consumeToken(b, COLON);
  r = r && parseCommandParameterValue(b, l + 1, parameterDefinition);
  exit_section_(b, l, m, null, r, false, null);
  return r;
}
 
Example 16
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 5 votes
private static boolean parseCommandDirectParameterValue(PsiBuilder b, int l,
                                                          @NotNull CommandDirectParameter parameter) {
    if (!recursion_guard_(b, l, "parseCommandDirectParameterValue")) return false;
    boolean r = false;
//    String parameterTypeSpecifier = parameter.getTypeSpecifier();
    // if we are inside tell compound statement=> direct parameter is optional
    // so it may be wrongly detected instead of parameter selector. So, checking if it is a parameter selector first
    boolean isTellCompound = b.getUserData(PARSING_TELL_COMPOUND_STATEMENT) == Boolean.TRUE;
    if (isTellCompound || parameter.isOptional()) {
      AppleScriptCommand myCmd = parameter.getCommand();
      for (String paramName : myCmd.getParameterNames()) {
        if (nextTokenIs(b, paramName)) return true;
      }
    }
    PsiBuilder.Marker m = enter_section_(b, l, _NONE_, "<parse Command Direct Parameter Value >");
    String parameterTypeSpecifier = parameter.getTypeSpecifier();
    if ("type".equals(parameterTypeSpecifier)) {
      r = typeSpecifier(b, l + 1);
    }
    // see https://bitbucket.org/adernov/applescript-internal/issues/23/coercion-expression-priority
//    else if ("text".equals(parameterTypeSpecifier)) {
//      r = AppleScriptParser.coercionExpressionWrapper(b, l + 1);
//      if (!r) r = AppleScriptParser.concatenationExpressionWrapper(b, l + 1);
//      if (!r) r = AppleScriptParser.stringLiteralExpression(b, l + 1);
//    }
    if (!r)
      r = com.intellij.plugin.applescript.lang.parser.AppleScriptParser.expression(b, l + 1);
    exit_section_(b, l, m, DIRECT_PARAMETER_VAL, r, false, null);
    // A tell statement specifies a default target for all commands contained
    // within it, so the direct parameter is optional.
    return r || parameter.isOptional() || isTellCompound;
  }
 
Example 17
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 5 votes
static boolean typeSpecifier(PsiBuilder b, int l) {
  if (!recursion_guard_(b, l, "typeSpecifier")) return false;
  boolean r;
  PsiBuilder.Marker m = enter_section_(b);
  r = singularClassName(b, l + 1);
  if (!r) r = AppleScriptParser.builtInClassIdentifierPlural(b, l + 1);
  if (!r) r = AppleScriptParser.dictionaryClassIdentifierPlural(b, l + 1);
  exit_section_(b, m, null, r);
  return r;
}
 
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: ParserScope.java   Source Code and License Vote up 4 votes
ParserScope(ParserScopeEnum resolution, IElementType tokenType, PsiBuilder.Marker mark) {
    this.resolution = resolution;
    this.tokenType = tokenType;
    this.mark = mark;
}
 
Example 20
Project: AppleScript-IDEA   File: AppleScriptGeneratedParserUtil.java   Source Code and License Vote up 4 votes
/**
 * @param b                        {@link PsiBuilder}
 * @param l                        Level deep
 * @param currentTokenText         Text string of the token being parsed
 * @param isPluralForm             Whether we are parsing class name in plural form
 * @param toldApplicationName      The name of the application (which is the target of all messages in current block)
 *                                 dictionary of which will be queried first of all when searching for class names
 * @param areThereUseStatements    Whether there are use statements used in the script, in which case standard library
 *                                 Should be specified explicitly
 * @param applicationsToImportFrom Set list of the applications (if specified) attached to script from use statements
 * @return true if class name parsed
 */
private static boolean parseDictionaryClassName(PsiBuilder b, int l, StringHolder currentTokenText,
                                                final boolean isPluralForm,
                                                @NotNull String toldApplicationName,
                                                final boolean areThereUseStatements,
                                                final @Nullable Set<String> applicationsToImportFrom) {
  boolean r, propertyExists = false;
  PsiBuilder.Marker m = enter_section_(b);
  r = parseApplicationClassName(b, l + 1, currentTokenText, isPluralForm, toldApplicationName);
  if (r) {
    // grammar allows className and propertyName as primaryExpression, so we should match the longest token between
    // className or propertyName tokens. Here we check and return false if the property with the longer name exists,
    // as it will be parsed later
    currentTokenText.value += " " + b.getTokenText();
    propertyExists = ParsableScriptSuiteRegistryHelper
            .isPropertyWithPrefixExist(toldApplicationName, currentTokenText.value);
  }
  exit_section_(b, m, null, r && !propertyExists);
  if (propertyExists) return false;
  if (r) return true;
  if (areThereUseStatements) {
    // if there are <use> statements in script (with importing dictionary terms condition), checking dictionary for
    // each application
    if (applicationsToImportFrom != null && !applicationsToImportFrom.isEmpty()) {
      for (String appName : applicationsToImportFrom) {
        m = enter_section_(b);
        r = parseApplicationClassName(b, l + 1, currentTokenText, isPluralForm, appName);
        if (r) {
          // check here as well for the property with longer name
          currentTokenText.value += " " + b.getTokenText();
          propertyExists = ParsableScriptSuiteRegistryHelper
                  .isPropertyWithPrefixExist(appName, currentTokenText.value);
        }
        exit_section_(b, m, null, r && !propertyExists);
        if (propertyExists) return false;
        if (r) return true;
      }
    }
  } else {
    m = enter_section_(b);
    r = parseStdClassName(b, l + 1, currentTokenText, isPluralForm);
    exit_section_(b, m, null, r);
    if (r) return true;
  }
  // It looks like not always CocoaStandard classes(and other terms) could be presented in applications terminology,
  // so in this case we check CocoaStandard here
  m = enter_section_(b);
  r = parseApplicationClassName(b, l + 1, currentTokenText, isPluralForm,
          ApplicationDictionary.COCOA_STANDARD_LIBRARY);
  if (r) {
    // grammar allows className and propertyName as primaryExpression, so we should match the longest token between
    // className or propertyName tokens. Here we check and return false if the property with the longer name exists,
    // as it will be parsed later
    currentTokenText.value += " " + b.getTokenText();
    propertyExists = ParsableScriptSuiteRegistryHelper
            .isPropertyWithPrefixExist(toldApplicationName, currentTokenText.value);
  }
  exit_section_(b, m, null, r && !propertyExists);
  return !propertyExists && r;
}