use of org.develnext.jphp.core.tokenizer.token.Token in project jphp by jphp-compiler.
the class FunctionGenerator method processUses.
protected void processUses(FunctionStmtToken result, ListIterator<Token> iterator) {
Token next = nextToken(iterator);
if (next instanceof NamespaceUseStmtToken) {
next = nextToken(iterator);
if (!isOpenedBrace(next, BraceExprToken.Kind.SIMPLE))
unexpectedToken(next, "(");
List<ArgumentStmtToken> arguments = new ArrayList<ArgumentStmtToken>();
while (iterator.hasNext()) {
ArgumentStmtToken argument = processArgument(iterator);
if (argument == null)
break;
if (argument.getValue() != null)
unexpectedToken(argument.getValue().getSingle());
arguments.add(argument);
FunctionStmtToken parent = analyzer.getFunction(true);
if (parent != null) {
parent.variable(argument.getName()).setUsed(true);
if (argument.isReference()) {
parent.variable(argument.getName()).setPassed(true).setUnstable(true);
}
parent = analyzer.peekClosure();
if (parent != null) {
parent.variable(argument.getName()).setUnstable(true);
}
}
}
result.setUses(arguments);
processReturnHint(result, iterator);
} else {
result.setUses(new ArrayList<ArgumentStmtToken>());
iterator.previous();
}
}
use of org.develnext.jphp.core.tokenizer.token.Token in project jphp by jphp-compiler.
the class NamespaceGenerator method processBody.
protected void processBody(NamespaceStmtToken namespace, ListIterator<Token> iterator) {
Token next = nextToken(iterator);
if (next instanceof SemicolonToken) {
List<Token> tree = analyzer.process(iterator);
namespace.setTree(tree);
namespace.setTokenRegistered(true);
} else if (isOpenedBrace(next, BraceExprToken.Kind.BLOCK)) {
boolean done = false;
List<Token> tree = new ArrayList<Token>();
while (iterator.hasNext()) {
Token item = analyzer.processNext(iterator);
if (isClosedBrace(item, BraceExprToken.Kind.BLOCK)) {
done = true;
break;
}
tree.add(item);
}
if (!done)
nextToken(iterator);
namespace.setTree(tree);
} else
unexpectedToken(next);
}
use of org.develnext.jphp.core.tokenizer.token.Token in project jphp by jphp-compiler.
the class TryCatchGenerator method processCatch.
public void processCatch(CatchStmtToken result, ListIterator<Token> iterator) {
Token next = nextToken(iterator);
if (!isOpenedBrace(next, BraceExprToken.Kind.SIMPLE))
unexpectedToken(next, "(");
List<FulledNameToken> exceptions = new ArrayList<>();
do {
next = nextToken(iterator);
if (!(next instanceof NameToken)) {
if (exceptions.isEmpty()) {
unexpectedToken(next, TokenType.T_STRING);
} else {
iterator.previous();
break;
}
}
FulledNameToken exception = analyzer.getRealName((NameToken) next);
exceptions.add(exception);
next = nextToken(iterator);
if (!(next instanceof OrExprToken)) {
iterator.previous();
break;
}
} while (true);
result.setExceptions(exceptions);
next = nextToken(iterator);
if (!(next instanceof VariableExprToken))
unexpectedToken(next, TokenType.T_VARIABLE);
VariableExprToken variable = (VariableExprToken) next;
result.setVariable(variable);
if (analyzer.getFunction() != null) {
analyzer.getFunction().variable(variable).setUnstable(true);
}
analyzer.getScope().addVariable(variable);
next = nextToken(iterator);
if (!isClosedBrace(next, BraceExprToken.Kind.SIMPLE))
unexpectedToken(next, ")");
BodyStmtToken body = analyzer.generator(BodyGenerator.class).getToken(nextToken(iterator), iterator);
result.setBody(body);
}
use of org.develnext.jphp.core.tokenizer.token.Token in project jphp by jphp-compiler.
the class TryCatchGenerator method getToken.
@Override
public TryStmtToken getToken(Token current, ListIterator<Token> iterator) {
if (current instanceof TryStmtToken) {
TryStmtToken result = (TryStmtToken) current;
analyzer.addScope(false);
BodyStmtToken body = analyzer.generator(BodyGenerator.class).getToken(nextToken(iterator), iterator);
result.setBody(body);
Token next = nextToken(iterator);
result.setCatches(new ArrayList<CatchStmtToken>());
if (next instanceof CatchStmtToken) {
processCatches(result, next, iterator);
} else if (next instanceof FinallyStmtToken) {
analyzer.getScope().setLevelForGoto(true);
processFinally(result, next, iterator);
analyzer.getScope().setLevelForGoto(false);
} else
unexpectedToken(next, TokenType.T_CATCH);
result.setLocal(analyzer.removeScope().getVariables());
return result;
}
return null;
}
use of org.develnext.jphp.core.tokenizer.token.Token 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 = (TokenizeGrammarUtils.isNewline(ch));
if (TokenizeGrammarUtils.isCloseTag(prev_ch, ch)) {
i -= 2;
closed = true;
}
break;
case DOCTYPE:
case BLOCK:
closed = k != 0 && (TokenizeGrammarUtils.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;
}
Aggregations