Search in sources :

Example 1 with Directive

use of php.runtime.common.Directive in project jphp by jphp-compiler.

the class Tokenizer method readComment.

protected Token readComment(CommentToken.Kind kind, int startPosition, int startLine) {
    int i, pos = relativePosition, k = 0;
    boolean isOldComment = code.charAt(currentPosition) == '#';
    for (i = currentPosition + 1; i < codeLength; i++, k++) {
        char ch = code.charAt(i);
        pos++;
        if (checkNewLine(ch))
            pos = 0;
        char prev_ch = i > 0 ? code.charAt(i - 1) : '\0';
        boolean closed = false;
        switch(kind) {
            case SIMPLE:
                closed = (GrammarUtils.isNewline(ch));
                if (GrammarUtils.isCloseTag(String.valueOf(new char[] { prev_ch, ch }))) {
                    i -= 2;
                    closed = true;
                }
                break;
            case DOCTYPE:
            case BLOCK:
                closed = k != 0 && (GrammarUtils.isCloseComment(String.valueOf(new char[] { prev_ch, ch })));
                break;
        }
        closed = closed || i == codeLength - 1;
        if (closed) {
            String text = code.substring(startPosition, kind == CommentToken.Kind.SIMPLE ? i : i - 1);
            TokenMeta meta = new TokenMeta(text, startLine, currentLine, startRelativePosition, relativePosition);
            meta.setStartIndex(currentPosition - 1);
            if (isOldComment || kind == CommentToken.Kind.DOCTYPE) {
                meta.setStartIndex(currentPosition);
            }
            if (kind == CommentToken.Kind.BLOCK || kind == CommentToken.Kind.DOCTYPE) {
                meta.setEndIndex(i + 1);
            } else {
                meta.setEndIndex(i);
            }
            currentPosition = i;
            relativePosition = pos;
            Token result = buildToken(CommentToken.class, meta);
            if (kind == CommentToken.Kind.SIMPLE && text.startsWith("//")) {
                String directive = text.substring(2).trim();
                if (directive.startsWith("@@")) {
                    int p = directive.indexOf(' ');
                    if (p != -1) {
                        String name = directive.substring(2, p);
                        String value = p + 1 < directive.length() ? directive.substring(p + 1) : "";
                        if (!directives.containsKey(name.toLowerCase()))
                            directives.put(name.toLowerCase(), new Directive(value, result.toTraceInfo(context)));
                    }
                }
            }
            return result;
        }
    }
    assert false;
    return null;
}
Also used : ValueExprToken(org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken) EchoRawToken(org.develnext.jphp.core.tokenizer.token.stmt.EchoRawToken) StringExprToken(org.develnext.jphp.core.tokenizer.token.expr.value.StringExprToken) Directive(php.runtime.common.Directive)

Aggregations

ValueExprToken (org.develnext.jphp.core.tokenizer.token.expr.ValueExprToken)1 StringExprToken (org.develnext.jphp.core.tokenizer.token.expr.value.StringExprToken)1 EchoRawToken (org.develnext.jphp.core.tokenizer.token.stmt.EchoRawToken)1 Directive (php.runtime.common.Directive)1