package net.zero918nobita.Xemime.ast;

import net.zero918nobita.Xemime.parser.ParserConstants;
import net.zero918nobita.Xemime.parser.Token;

public class XToken {
    protected Token token;
    protected boolean isSpecial;

    public XToken(Token token, boolean isSpecial) {
        this.token = token;
        this.isSpecial = isSpecial;
    }

    public XToken(Token token) {
        this(token, false);
    }

    @Override
    public String toString() {
        return token.image;
    }

    public boolean isSpecial() {
        return this.isSpecial;
    }

    public int kindID() {
        return token.kind;
    }

    public String kindName() {
        return ParserConstants.tokenImage[token.kind];
    }

    public int lineno() {
        return token.beginLine;
    }

    public int column() {
        return token.beginColumn;
    }

    public String image() {
        return token.image;
    }
}

@@ -135,16 +135,68 @@
 Token;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 public c
@@ -958,11 +958,1248 @@
 e;%0A    %7D
+%0A%0A    protected Token specialTokenHead(Token firstSpecial) %7B%0A        Token s = firstSpecial;%0A        while (s.specialToken != null) s = s.specialToken;%0A        return s;%0A    %7D%0A%0A    protected List%3CXToken%3E buildTokenList(Token first, boolean rejectFirstSpecials) %7B%0A        List%3CXToken%3E result = new ArrayList%3C%3E();%0A        boolean rejectSpecials = rejectFirstSpecials;%0A        for (Token t = first; t != null; t = t.next) %7B%0A            if (t.specialToken != null && !rejectSpecials) %7B%0A                Token s = specialTokenHead(t.specialToken);%0A                for (; s != null; s = s.next) result.add(new XToken(s));%0A            %7D%0A            result.add(new XToken(t));%0A            rejectSpecials = false;%0A        %7D%0A        return result;%0A    %7D%0A%0A    public List%3CXToken%3E tokensWithoutFirstSpecials() %7B%0A        return buildTokenList(token, true);%0A    %7D%0A%0A    public String includedLine() %7B%0A        StringBuffer buf = new StringBuffer();%0A        for (XToken t : tokensWithoutFirstSpecials()) %7B%0A            int idx = t.image().indexOf('%5Cn');%0A            if (idx %3E 0) %7B%0A                buf.append(t.image().substring(0, idx));%0A                break;%0A            %7D%0A            buf.append(t.image());%0A        %7D%0A        return buf.toString();%0A    %7D
 %0A%7D%0A

Update XToken