@Test public void compilesExecutableJava() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Program program = new Program( new InputOf( new JoinedText( "\n", "object car as Serializable:", " Integer @vin", " String name():", " \"Mercedes-Benz\"" ).asString() ), s -> new OutputTo(baos) ); program.compile(); try (final GroovyClassLoader loader = new GroovyClassLoader()) { final Class<?> type = loader.parseClass( new GroovyCodeSource( new TextOf(baos.toByteArray()).asString(), "car", GroovyShell.DEFAULT_CODE_BASE ) ); MatcherAssert.assertThat( type.getMethod("name").invoke( type.getConstructor(Integer.class).newInstance(0) ), Matchers.equalTo("Mercedes-Benz") ); } }
public void compile() throws IOException { final String[] lines = new TextOf(this.input).asString().split("\n"); final ANTLRErrorListener errors = new BaseErrorListener() { @Override public void syntaxError(final Recognizer<?, ?> recognizer, final Object symbol, final int line, final int position, final String msg, final RecognitionException error) { throw new CompileException( String.format( "[%d:%d] %s: \"%s\"", line, position, msg, lines[line - 1] ), error ); } }; final org.eolang.compiler.ProgramLexer lexer = new org.eolang.compiler.ProgramLexer( CharStreams.fromStream(this.input.stream()) ); lexer.removeErrorListeners(); lexer.addErrorListener(errors); final org.eolang.compiler.ProgramParser parser = new org.eolang.compiler.ProgramParser( new CommonTokenStream(lexer) ); parser.removeErrorListeners(); parser.addErrorListener(errors); final Tree tree = parser.program().ret; new IoCheckedScalar<>( new And( path -> { new LengthOf( new TeeInput( path.getValue(), this.target.apply(path.getKey()) ) ).value(); }, tree.java().entrySet() ) ).value(); }
Program { public void compile() throws IOException { final String[] lines = new TextOf(this.input).asString().split("\n"); final ANTLRErrorListener errors = new BaseErrorListener() { @Override public void syntaxError(final Recognizer<?, ?> recognizer, final Object symbol, final int line, final int position, final String msg, final RecognitionException error) { throw new CompileException( String.format( "[%d:%d] %s: \"%s\"", line, position, msg, lines[line - 1] ), error ); } }; final org.eolang.compiler.ProgramLexer lexer = new org.eolang.compiler.ProgramLexer( CharStreams.fromStream(this.input.stream()) ); lexer.removeErrorListeners(); lexer.addErrorListener(errors); final org.eolang.compiler.ProgramParser parser = new org.eolang.compiler.ProgramParser( new CommonTokenStream(lexer) ); parser.removeErrorListeners(); parser.addErrorListener(errors); final Tree tree = parser.program().ret; new IoCheckedScalar<>( new And( path -> { new LengthOf( new TeeInput( path.getValue(), this.target.apply(path.getKey()) ) ).value(); }, tree.java().entrySet() ) ).value(); } }
Program { public void compile() throws IOException { final String[] lines = new TextOf(this.input).asString().split("\n"); final ANTLRErrorListener errors = new BaseErrorListener() { @Override public void syntaxError(final Recognizer<?, ?> recognizer, final Object symbol, final int line, final int position, final String msg, final RecognitionException error) { throw new CompileException( String.format( "[%d:%d] %s: \"%s\"", line, position, msg, lines[line - 1] ), error ); } }; final org.eolang.compiler.ProgramLexer lexer = new org.eolang.compiler.ProgramLexer( CharStreams.fromStream(this.input.stream()) ); lexer.removeErrorListeners(); lexer.addErrorListener(errors); final org.eolang.compiler.ProgramParser parser = new org.eolang.compiler.ProgramParser( new CommonTokenStream(lexer) ); parser.removeErrorListeners(); parser.addErrorListener(errors); final Tree tree = parser.program().ret; new IoCheckedScalar<>( new And( path -> { new LengthOf( new TeeInput( path.getValue(), this.target.apply(path.getKey()) ) ).value(); }, tree.java().entrySet() ) ).value(); } Program(final Input ipt, final Path dir);  Program(final Input ipt, final Func<String, Output> tgt); }
Program { public void compile() throws IOException { final String[] lines = new TextOf(this.input).asString().split("\n"); final ANTLRErrorListener errors = new BaseErrorListener() { @Override public void syntaxError(final Recognizer<?, ?> recognizer, final Object symbol, final int line, final int position, final String msg, final RecognitionException error) { throw new CompileException( String.format( "[%d:%d] %s: \"%s\"", line, position, msg, lines[line - 1] ), error ); } }; final org.eolang.compiler.ProgramLexer lexer = new org.eolang.compiler.ProgramLexer( CharStreams.fromStream(this.input.stream()) ); lexer.removeErrorListeners(); lexer.addErrorListener(errors); final org.eolang.compiler.ProgramParser parser = new org.eolang.compiler.ProgramParser( new CommonTokenStream(lexer) ); parser.removeErrorListeners(); parser.addErrorListener(errors); final Tree tree = parser.program().ret; new IoCheckedScalar<>( new And( path -> { new LengthOf( new TeeInput( path.getValue(), this.target.apply(path.getKey()) ) ).value(); }, tree.java().entrySet() ) ).value(); } Program(final Input ipt, final Path dir);  Program(final Input ipt, final Func<String, Output> tgt); void compile(); }
Program { public void compile() throws IOException { final String[] lines = new TextOf(this.input).asString().split("\n"); final ANTLRErrorListener errors = new BaseErrorListener() { @Override public void syntaxError(final Recognizer<?, ?> recognizer, final Object symbol, final int line, final int position, final String msg, final RecognitionException error) { throw new CompileException( String.format( "[%d:%d] %s: \"%s\"", line, position, msg, lines[line - 1] ), error ); } }; final org.eolang.compiler.ProgramLexer lexer = new org.eolang.compiler.ProgramLexer( CharStreams.fromStream(this.input.stream()) ); lexer.removeErrorListeners(); lexer.addErrorListener(errors); final org.eolang.compiler.ProgramParser parser = new org.eolang.compiler.ProgramParser( new CommonTokenStream(lexer) ); parser.removeErrorListeners(); parser.addErrorListener(errors); final Tree tree = parser.program().ret; new IoCheckedScalar<>( new And( path -> { new LengthOf( new TeeInput( path.getValue(), this.target.apply(path.getKey()) ) ).value(); }, tree.java().entrySet() ) ).value(); } Program(final Input ipt, final Path dir);  Program(final Input ipt, final Func<String, Output> tgt); void compile();  }