Nashornの字句解析のソースを見るとnashorn.lexer.xmlliteralsというのがあります。
XMLリテラル?…XML?…!?
E4X!E4Xじゃないか!
試してみました。
https://gist.github.com/tuchida/9796167
nashorn.lexer.xmlliteralsなし
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
$ jdk1.8.0/bin/javac E4X.java && jdk1.8.0/bin/java E4X E4X: null javax.script.ScriptException: <eval>:1:0 Expected an operand but found < <xml>xml</xml> ^ in <eval> at line number 1 at column number 0 at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:564) at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:610) at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:597) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:524) at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:194) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) at E4X.main(E4X.java:11) Caused by: jdk.nashorn.internal.runtime.ParserException: <eval>:1:0 Expected an operand but found < <xml>xml</xml> ^ at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:258) at jdk.nashorn.internal.parser.AbstractParser.error(AbstractParser.java:243) at jdk.nashorn.internal.parser.Parser.unaryExpression(Parser.java:2788) at jdk.nashorn.internal.parser.Parser.expression(Parser.java:2888) at jdk.nashorn.internal.parser.Parser.expressionStatement(Parser.java:1017) at jdk.nashorn.internal.parser.Parser.statement(Parser.java:852) at jdk.nashorn.internal.parser.Parser.sourceElements(Parser.java:693) at jdk.nashorn.internal.parser.Parser.program(Parser.java:631) at jdk.nashorn.internal.parser.Parser.parse(Parser.java:213) at jdk.nashorn.internal.parser.Parser.parse(Parser.java:188) at jdk.nashorn.internal.runtime.Context.compile(Context.java:936) at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:917) at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:406) at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:608) ... 5 more |
nashorn.lexer.xmlliteralsあり
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
$ jdk1.8.0/bin/javac E4X.java && jdk1.8.0/bin/java -Dnashorn.lexer.xmlliterals=true E4X E4X: true java.lang.NullPointerException at jdk.nashorn.internal.codegen.MethodEmitter.convert(MethodEmitter.java:1560) at jdk.nashorn.internal.codegen.CodeGenerator.enterLiteralNode(CodeGenerator.java:1432) at jdk.nashorn.internal.codegen.CodeGenerator.access$300(CodeGenerator.java:154) at jdk.nashorn.internal.codegen.CodeGenerator$1.enterLiteralNode(CodeGenerator.java:473) at jdk.nashorn.internal.ir.LiteralNode.accept(LiteralNode.java:210) at jdk.nashorn.internal.codegen.CodeGenerator.load(CodeGenerator.java:424) at jdk.nashorn.internal.codegen.CodeGenerator.load(CodeGenerator.java:403) at jdk.nashorn.internal.codegen.CodeGenerator$8.evaluate(CodeGenerator.java:2471) at jdk.nashorn.internal.codegen.CodeGenerator$Store.store(CodeGenerator.java:3206) at jdk.nashorn.internal.codegen.CodeGenerator.enterASSIGN(CodeGenerator.java:2476) at jdk.nashorn.internal.ir.visitor.NodeOperatorVisitor.enterBinaryNode(NodeOperatorVisitor.java:117) at jdk.nashorn.internal.ir.BinaryNode.accept(BinaryNode.java:168) at jdk.nashorn.internal.codegen.CodeGenerator$1.enterDefault(CodeGenerator.java:479) at jdk.nashorn.internal.ir.visitor.NodeVisitor.enterBinaryNode(NodeVisitor.java:178) at jdk.nashorn.internal.ir.BinaryNode.accept(BinaryNode.java:168) at jdk.nashorn.internal.codegen.CodeGenerator.load(CodeGenerator.java:424) at jdk.nashorn.internal.codegen.CodeGenerator.load(CodeGenerator.java:359) at jdk.nashorn.internal.codegen.CodeGenerator.enterDISCARD(CodeGenerator.java:2345) at jdk.nashorn.internal.ir.visitor.NodeOperatorVisitor.enterUnaryNode(NodeOperatorVisitor.java:57) at jdk.nashorn.internal.ir.UnaryNode.accept(UnaryNode.java:124) at jdk.nashorn.internal.codegen.CodeGenerator.enterExpressionStatement(CodeGenerator.java:857) at jdk.nashorn.internal.ir.ExpressionStatement.accept(ExpressionStatement.java:66) at jdk.nashorn.internal.ir.Node.accept(Node.java:291) at jdk.nashorn.internal.ir.Block.accept(Block.java:143) at jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57) at jdk.nashorn.internal.ir.Block.accept(Block.java:361) at jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:297) at jdk.nashorn.internal.ir.LexicalContextNode$Acceptor.accept(LexicalContextNode.java:57) at jdk.nashorn.internal.ir.LexicalContextExpression.accept(LexicalContextExpression.java:46) at jdk.nashorn.internal.ir.FunctionNode.accept(FunctionNode.java:49) at jdk.nashorn.internal.codegen.CompilationPhase$8.transform(CompilationPhase.java:379) at jdk.nashorn.internal.codegen.CompilationPhase.apply(CompilationPhase.java:513) at jdk.nashorn.internal.codegen.Compiler.compile(Compiler.java:358) at jdk.nashorn.internal.runtime.Context.compile(Context.java:960) at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:917) at jdk.nashorn.internal.runtime.Context.compileScript(Context.java:406) at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:608) at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:597) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:524) at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:194) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) at E4X.main(E4X.java:11) |
nashorn.lexer.xmlliteralsありだとシンタックスエラーにならずコード生成部分でヌルポになりました。ソースを追ってみるとトークンの生成はするのですが(valueOfXMLのコメントが「Convert a regex token to a token object.」なのが微笑ましいですね)、コード生成時にXMLTokenを見てる箇所がありません。
はー、RhinoかわいいよRhino。
最近のコメント