use of php.runtime.env.Context in project jphp by jphp-compiler.
the class SimpleExprTest method testSimpleCall.
@Test
public void testSimpleCall() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("myCall(1 * 2, func(3, 2), 4);"));
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
List<Token> tokens = analyzer.getTree();
Assert.assertTrue(tokens.size() == 1);
Assert.assertTrue(tokens.get(0) instanceof ExprStmtToken);
ExprStmtToken expr = (ExprStmtToken) tokens.get(0);
tokens = expr.getTokens();
Assert.assertTrue(tokens.size() == 1);
Assert.assertTrue(tokens.get(0) instanceof CallExprToken);
CallExprToken call = (CallExprToken) expr.getTokens().get(0);
Assert.assertTrue(call.getName() instanceof NameToken);
Assert.assertEquals("myCall", ((NameToken) call.getName()).getName());
Assert.assertTrue(call.getParameters().size() == 3);
Assert.assertTrue(call.getParameters().get(0).getTokens().size() == 3);
Assert.assertTrue(call.getParameters().get(2).getTokens().size() == 1);
ExprStmtToken param = call.getParameters().get(1);
Assert.assertTrue(param.getTokens().size() == 1);
Assert.assertTrue(param.getTokens().get(0) instanceof CallExprToken);
CallExprToken subCall = (CallExprToken) param.getTokens().get(0);
Assert.assertTrue(subCall.getParameters().size() == 2);
}
use of php.runtime.env.Context in project jphp by jphp-compiler.
the class SyntaxAnalyzerTest method testSimple.
@Test
public void testSimple() throws IOException {
Tokenizer tokenizer = new Tokenizer(new Context("foobar;"));
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, tokenizer);
Assert.assertTrue(analyzer.getTree().size() == 1);
Assert.assertTrue(analyzer.getTree().listIterator().next() instanceof ExprStmtToken);
}
use of php.runtime.env.Context in project jphp by jphp-compiler.
the class CLI method checkSyntax.
protected void checkSyntax(String filename) throws Throwable {
Launcher launcher = new Launcher("jphp.conf", args);
launcher.run(false, true);
File file = new File(filename);
Environment environment = new Environment(launcher.getCompileScope(), output);
Context context = new Context(file);
try {
SyntaxAnalyzer analyzer = new SyntaxAnalyzer(environment, new Tokenizer(context));
analyzer.getTree();
output.println(String.format("No syntax errors detected in %s", filename));
} catch (Exception e) {
environment.catchUncaught(e);
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
} finally {
try {
environment.doFinal();
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
}
}
use of php.runtime.env.Context in project jphp by jphp-compiler.
the class CLI method executeFile.
protected void executeFile(String filename) throws Throwable {
Launcher launcher = new Launcher("jphp.conf", args);
launcher.run(false);
File file = new File(filename);
Environment environment = new Environment(launcher.getCompileScope(), output);
environment.getDefaultBuffer().setImplicitFlush(true);
try {
Context context = new Context(file);
ModuleEntity module = environment.importModule(context);
module.include(environment);
} catch (Exception e) {
environment.catchUncaught(e);
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
} finally {
try {
environment.doFinal();
} catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
}
}
use of php.runtime.env.Context in project jphp by jphp-compiler.
the class TokenizerTest method testStringSlashes.
@Test
public void testStringSlashes() throws IOException {
Token token;
Tokenizer tokenizer = new Tokenizer(new Context(" 'foo\\'bar' \"foo\\\"bar\""));
token = tokenizer.nextToken();
assertTrue(token instanceof StringExprToken);
assertEquals("foo'bar", ((StringExprToken) token).getValue());
token = tokenizer.nextToken();
assertTrue(token instanceof StringExprToken);
assertEquals("foo\"bar", ((StringExprToken) token).getValue());
}
Aggregations