public void setID(beaver.Symbol symbol) {
   if (symbol.value != null && !(symbol.value instanceof String))
     throw new UnsupportedOperationException("setID is only valid for String lexemes");
   tokenString_ID = (String) symbol.value;
   IDstart = symbol.getStart();
   IDend = symbol.getEnd();
 }
示例#2
0
  private void processPHPBlock(IParseNode root, int sourceLength)
      throws IOException, Exception // $codepro.audit.disable
      {
    Symbol startTag = getCurrentSymbol();
    advance();

    // finds the entire php block
    int start = getCurrentSymbol().getStart();
    int end = start;
    short id = getCurrentSymbol().getId();
    while (id != PHTMLTokens.PHP_END && id != PHTMLTokens.EOF) {
      end = getCurrentSymbol().getEnd();
      advance();
      id = getCurrentSymbol().getId();
    }

    IParseNode result = getParseResult(IPHPConstants.CONTENT_TYPE_PHP, start, end);
    if (result != null) {
      Symbol endTag = getCurrentSymbol();
      ParseNode phpNode = new ParseNode(IPHPConstants.CONTENT_TYPE_PHP);
      int endOffset;
      if ("?>".equals(endTag.value)) // $NON-NLS-1$
      {
        endOffset = endTag.getEnd() + 1;
      } else {
        endOffset = endTag.getEnd();
      }
      phpNode.setLocation(startTag.getStart(), Math.min(endOffset, sourceLength - 1));
      root.addChild(phpNode);
    }
  }
示例#3
0
  /**
   * assertTokenType
   *
   * @param source
   * @param type
   * @throws Exception
   */
  protected void assertTokenType(String source, JSTokenType type) {
    _scanner.setSource(source);

    try {
      Symbol token = _scanner.nextToken();
      int id = token.getId();
      int length = token.getEnd() - token.getStart() + 1;

      assertEquals("unexpected token type", type.getIndex(), id);
      assertEquals("token length does not match source length: " + source, source.length(), length);
    } catch (Throwable e) {
      fail(e.getMessage());
    }
  }
    /* (non-Javadoc)
     * @see com.aptana.editor.json.parsing.ast.JSONTreeWalker#visit(com.aptana.editor.json.parsing.ast.JSONEntryNode)
     */
    @Override
    public void visit(JSONEntryNode node) {
      JSONEntryFormatNode entry = new JSONEntryFormatNode(_document);
      IParseNode name = node.getFirstChild();
      Symbol colon = node.getColon();
      IParseNode value = node.getLastChild();
      IFormatterTextNode nameText =
          createTextNode(_document, name.getStartingOffset(), name.getEndingOffset() + 1);
      IFormatterTextNode colonText =
          createTextNode(_document, colon.getStart(), colon.getEnd() + 1);

      // add children
      entry.addChild(nameText);
      entry.addChild(colonText);

      // push node, visit children, then remove from stack
      push(entry);
      this.visit(value);
      checkedPop(entry, node.getEndingOffset() + 1);
    }
示例#5
0
 /* Checks deep equality of two Symbols (complexity comes from giving nice error messages). */
 public static void assertEquals(String msg, Symbol actual, Symbol expected) {
   final short expectedId = expected.getId();
   final short actualId = actual.getId();
   if (actualId != expectedId) {
     fail(
         msg
             + ": incorrect token type - "
             + "expected: "
             + expectedId
             + " ("
             + AspectsParser.Terminals.NAMES[expectedId]
             + ") "
             + "but was: "
             + actualId
             + " ("
             + AspectsParser.Terminals.NAMES[actualId]
             + ")");
   }
   final String expectedValue = (String) expected.value;
   final String actualValue = ScannerTestTool.stringifyValue(actual.value);
   if (((actualValue == null || expectedValue == null) && (actualValue != expectedValue))
       || (actualValue != null && !actualValue.equals(expectedValue))) {
     fail(
         msg
             + " - "
             + AspectsParser.Terminals.NAMES[actualId]
             + ": incorrect token value - "
             + "expected: "
             + expectedValue
             + " "
             + "but was: "
             + actualValue);
   }
   final int expectedStart = expected.getStart();
   final int actualStart = actual.getStart();
   if (actualStart != expectedStart) {
     fail(
         msg
             + " - "
             + getSymbolString(actual)
             + ": incorrect start position - "
             + "expected: line "
             + Symbol.getLine(expectedStart)
             + " col "
             + Symbol.getColumn(expectedStart)
             + " "
             + "but was: line "
             + Symbol.getLine(actualStart)
             + " col "
             + Symbol.getColumn(actualStart));
   }
   final int expectedEnd = expected.getEnd();
   final int actualEnd = actual.getEnd();
   if (actualEnd != expectedEnd) {
     fail(
         msg
             + " - "
             + getSymbolString(actual)
             + ": incorrect end position - "
             + "expected: line "
             + Symbol.getLine(expectedEnd)
             + " col "
             + Symbol.getColumn(expectedEnd)
             + " "
             + "but was: line "
             + Symbol.getLine(actualEnd)
             + " col "
             + Symbol.getColumn(actualEnd));
   }
 }