@Override
  public boolean consume(CodeReader code, Lexer lexer) {
    if (!Character.isJavaIdentifierStart(code.peek())) {
      return false;
    }

    int line = code.getCursor().getLine();
    int column = code.getCursor().getColumn();
    while (Character.isJavaIdentifierPart(code.peek())) {
      tmpBuilder.append((char) code.pop());
    }

    String word = tmpBuilder.toString();

    TokenType keywordType = keywordsMap.get(word);
    Token token =
        tokenBuilder
            .setType(keywordType == null ? GenericTokenType.IDENTIFIER : keywordType)
            .setValueAndOriginalValue(word, word)
            .setURI(lexer.getURI())
            .setLine(line)
            .setColumn(column)
            .build();

    lexer.addToken(token);

    tmpBuilder.delete(0, tmpBuilder.length());

    return true;
  }
Exemplo n.º 2
0
 public boolean hasNextToken(CodeReader code, HtmlCodeBuilder codeBuilder) {
   return code.peek() != '\n'
       && code.peek() != '\r'
       && (isCommentStartedOnPreviousLine(codeBuilder)
           || (code.peek() == startToken[0]
               && Arrays.equals(code.peek(startToken.length), startToken)));
 }
Exemplo n.º 3
0
 @Override
 public boolean consume(CodeReader code, HtmlCodeBuilder codeBuilder) {
   if (code.peek() == '\'' || code.peek() == '\"') {
     codeBuilder.appendWithoutTransforming(tagBefore);
     int firstChar = code.peek();
     code.popTo(new EndCommentMatcher(firstChar, code), codeBuilder);
     codeBuilder.appendWithoutTransforming(tagAfter);
     return true;
   } else {
     return false;
   }
 }
Exemplo n.º 4
0
 @Override
 public boolean consume(CodeReader code, HtmlCodeBuilder codeBuilder) {
   if (code.peek() == '@') {
     codeBuilder.appendWithoutTransforming(tagBefore);
     code.popTo(END_TOKEN_MATCHER, codeBuilder);
     codeBuilder.appendWithoutTransforming(tagAfter);
     return true;
   } else {
     return false;
   }
 }