use of org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken in project jphp by jphp-compiler.
the class TokenizerTest method testVarVar.
@Test
public void testVarVar() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("$$foo $ $bar $$$foobar"));
assertTrue(tokenizer.nextToken() instanceof DollarExprToken);
assertTrue(tokenizer.nextToken() instanceof VariableExprToken);
assertTrue(tokenizer.nextToken() instanceof DollarExprToken);
assertTrue(tokenizer.nextToken() instanceof VariableExprToken);
assertTrue(tokenizer.nextToken() instanceof DollarExprToken);
assertTrue(tokenizer.nextToken() instanceof DollarExprToken);
assertTrue(tokenizer.nextToken() instanceof VariableExprToken);
tokenizer = new Tokenizer(new Context("${'foo;6bar'}"));
assertTrue(tokenizer.nextToken() instanceof DollarExprToken);
assertTrue(tokenizer.nextToken() instanceof BraceExprToken);
assertTrue(tokenizer.nextToken() instanceof StringExprToken);
assertTrue(tokenizer.nextToken() instanceof BraceExprToken);
}
use of org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken in project jphp by jphp-compiler.
the class TokenizerTest method testHeredoc.
@Test
public void testHeredoc() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("<<<DOC\n <foobar> \nDOC;\n"));
Token token = tokenizer.nextToken();
assertTrue(token instanceof StringExprToken);
assertEquals(StringExprToken.Quote.DOC, ((StringExprToken) token).getQuote());
assertEquals(" <foobar> ", ((StringExprToken) token).getValue());
tokenizer = new Tokenizer(new Context("<<<\"DOC\"\n \\n<foobar> \nDOC;\n"));
token = tokenizer.nextToken();
assertTrue(token instanceof StringExprToken);
assertEquals(StringExprToken.Quote.DOC, ((StringExprToken) token).getQuote());
assertEquals(" \n<foobar> ", ((StringExprToken) token).getValue());
tokenizer = new Tokenizer(new Context("<<<'DOC'\n \\n<foobar> \nDOC;\n"));
token = tokenizer.nextToken();
assertTrue(token instanceof StringExprToken);
assertEquals(StringExprToken.Quote.DOC, ((StringExprToken) token).getQuote());
assertEquals(" \\n<foobar> ", ((StringExprToken) token).getValue());
tokenizer = new Tokenizer(new Context("a(<<<DOC\n<foobar>\nDOC\n)\n"));
token = tokenizer.nextToken();
assertTrue(token instanceof NameToken);
token = tokenizer.nextToken();
assertTrue(token instanceof BraceExprToken);
token = tokenizer.nextToken();
assertTrue(token instanceof StringExprToken);
assertEquals(StringExprToken.Quote.DOC, ((StringExprToken) token).getQuote());
assertEquals("<foobar>", ((StringExprToken) token).getValue());
}
use of org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken in project jphp by jphp-compiler.
the class DeclareGenerator method getToken.
@Override
public DeclareStmtToken getToken(Token current, ListIterator<Token> iterator) {
if (current instanceof DeclareStmtToken) {
BraceExprToken token = nextAndExpected(iterator, BraceExprToken.class);
if (!isOpenedBrace(token, BraceExprToken.Kind.SIMPLE)) {
unexpectedToken(token, "(");
}
NameToken nameToken = nextAndExpected(iterator, NameToken.class);
nextAndExpected(iterator, AssignExprToken.class);
ExprStmtToken value = analyzer.generator(ExprGenerator.class).getInBraces(BraceExprToken.Kind.SIMPLE, iterator, true);
if (!value.isConstantly()) {
unexpectedToken(value, "constant value");
}
DeclareStmtToken result = (DeclareStmtToken) current;
result.setName(nameToken);
result.setValue(value);
return result;
}
return null;
}
use of org.develnext.jphp.core.tokenizer.token.expr.BraceExprToken in project jphp by jphp-compiler.
the class ASMExpression method processOperator.
protected void processOperator(Stack<Token> stack, List<Token> result, OperatorExprToken current) {
List<Token> list = new ArrayList<Token>();
boolean isRightOperator = current != null && current.isRightSide();
int prior = current == null ? -1 : current.getPriority();
while (!stack.empty()) {
Token el = stack.peek();
int elPrior = getPriority(el);
if (el instanceof BraceExprToken)
break;
if (current != null && current.getAssociation() == Association.RIGHT && !current.isBinary() && prev instanceof OperatorExprToken)
break;
boolean flush = current == null || elPrior == 1 || (isRightOperator ? elPrior > prior : elPrior <= prior);
if (flush) {
stack.pop();
list.add(el);
} else {
break;
}
}
result.addAll(list);
}
Aggregations