pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/jruby/jruby/commit/a8a6a7938b577d0aa9f3264f9894fd9c7f8a0bac

/> front-end parser overhaul · jruby/jruby@a8a6a79 · GitHub
Skip to content

Commit a8a6a79

Browse files
committed
front-end parser overhaul
Beginning of working towards using traditional and YARP parsing through the same interface. YARP is not really hooked up but it will happen soon. There is a much smaller footprint of APIs to support now. The YARP code itself has already significantly changed but it is closer than it was so this was committed.
1 parent acd9346 commit a8a6a79

32 files changed

Lines changed: 3689 additions & 4012 deletions

core/src/main/java/org/jruby/ParseResult.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ public interface ParseResult {
99
int getLine();
1010
String getFile();
1111
int getCoverageMode();
12+
Object getAST();
1213
}

core/src/main/java/org/jruby/Ruby.java

Lines changed: 82 additions & 157 deletions
Large diffs are not rendered by default.

core/src/main/java/org/jruby/ast/RootNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,8 @@ public List<Node> childNodes() {
126126
public boolean executesOnce() {
127127
return true;
128128
}
129+
130+
public Object getAST() {
131+
return this;
132+
}
129133
}

core/src/main/java/org/jruby/embed/internal/EmbedRubyRuntimeAdapterImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.net.URL;
4040
import java.util.Objects;
4141

42+
import org.jcodings.specific.UTF8Encoding;
4243
import org.jruby.Ruby;
4344
import org.jruby.RubyInstanceConfig.CompileMode;
4445
import org.jruby.RubyRuntimeAdapter;
@@ -184,9 +185,9 @@ private EmbedEvalUnit runParser(Object input, String filename, int... lines) {
184185
try {
185186
final Node node;
186187
if (input instanceof String) {
187-
node = runtime.parseEval((String) input, filename, scope, line);
188+
node = (Node) runtime.getParserManager().parseEval(filename, line, (String) input, scope).getAST();
188189
} else {
189-
node = runtime.parseFile((InputStream) input, filename, scope, line);
190+
node = (Node) runtime.getParserManager().parseFile(filename, line, (InputStream) input, runtime.setupSourceEncoding(UTF8Encoding.INSTANCE), scope, 0).getAST();
190191
}
191192
CompileMode compileMode = runtime.getInstanceConfig().getCompileMode();
192193
if (compileMode == CompileMode.FORCE) {

core/src/main/java/org/jruby/ext/jruby/JRubyLibrary.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
package org.jruby.ext.jruby;
3333

34+
import org.jcodings.Encoding;
3435
import org.jcodings.specific.ASCIIEncoding;
36+
import org.jcodings.specific.UTF8Encoding;
3537
import org.jruby.*;
3638
import org.jruby.anno.JRubyMethod;
3739
import org.jruby.anno.JRubyModule;
@@ -52,6 +54,8 @@
5254

5355
import java.io.ByteArrayInputStream;
5456

57+
import static org.jruby.parser.ParserManager.INLINE;
58+
5559
/**
5660
* Native part of require 'jruby', e.g. provides methods for swapping between the normal Ruby reference to an
5761
* object and the Java-integration-wrapped reference.
@@ -207,7 +211,7 @@ private static Node parseImpl(ThreadContext context, IRubyObject[] args, Block b
207211

208212
final RubyString content = args[0].convertToString();
209213
final String filename;
210-
boolean extra_position_info = false; int lineno = 0;
214+
boolean inlineSource = false; int lineno = 0;
211215

212216
switch (args.length) {
213217
case 1 :
@@ -218,31 +222,22 @@ private static Node parseImpl(ThreadContext context, IRubyObject[] args, Block b
218222
break;
219223
case 3 :
220224
filename = args[1].convertToString().toString();
221-
extra_position_info = args[2].isTrue();
225+
inlineSource = args[2].isTrue();
222226
break;
223227
case 4 :
224228
filename = args[1].convertToString().toString();
225-
extra_position_info = args[2].isTrue();
229+
inlineSource = args[2].isTrue();
226230
lineno = args[3].convertToInteger().getIntValue();
227231
break;
228232
default :
229233
throw new AssertionError("unexpected arguments: " + java.util.Arrays.toString(args));
230234
}
231235

232236
final ByteList bytes = content.getByteList();
233-
final DynamicScope scope = null;
234-
235-
final Node parseResult;
236-
if (content.getEncoding() == ASCIIEncoding.INSTANCE) {
237-
// binary content, parse as though from a stream
238-
ByteArrayInputStream stream = new ByteArrayInputStream(bytes.getUnsafeBytes(), bytes.getBegin(), bytes.getRealSize());
239-
parseResult = context.runtime.parseFile(stream, filename, scope, lineno);
240-
}
241-
else {
242-
parseResult = context.runtime.parse(bytes, filename, scope, lineno, extra_position_info);
243-
}
237+
ByteArrayInputStream stream = new ByteArrayInputStream(bytes.getUnsafeBytes(), bytes.getBegin(), bytes.getRealSize());
238+
Encoding encoding = content.getEncoding() == ASCIIEncoding.INSTANCE ? context.runtime.setupSourceEncoding(UTF8Encoding.INSTANCE) : bytes.getEncoding();
244239

245-
return parseResult;
240+
return (Node) context.runtime.getParserManager().parseFile(filename, lineno, stream, encoding, null, inlineSource ? INLINE : 0).getAST();
246241
}
247242

248243
@JRubyMethod(module = true, name = "compile_ir", required = 1, optional = 3, checkArity = false)

core/src/main/java/org/jruby/ext/ripper/RipperParser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@
3636
import java.io.IOException;
3737
import java.util.Set;
3838

39+
import org.jruby.Ruby;
3940
import org.jruby.RubySymbol;
4041
import org.jruby.ast.*;
4142
import org.jruby.common.IRubyWarnings;
4243
import org.jruby.common.IRubyWarnings.ID;
4344
import org.jruby.lexer.LexerSource;
4445
import org.jruby.lexer.LexingCommon;
46+
import org.jruby.runtime.DynamicScope;
4547
import org.jruby.ext.ripper.StrTerm;
4648
import org.jruby.util.KeyValuePair; import org.jruby.RubyArray;
4749
import org.jruby.util.ByteList;
@@ -97,12 +99,13 @@
9799
import static org.jruby.util.CommonByteLists.ANON_BLOCK;
98100
import static org.jruby.util.CommonByteLists.FWD_BLOCK;
99101
import static org.jruby.util.CommonByteLists.FWD_KWREST;
102+
import static org.jruby.parser.ParserManager.isEval;
100103

101104
public class RipperParser extends RipperParserBase {
102105
public RipperParser(ThreadContext context, IRubyObject ripper, LexerSource source) {
103106
super(context, ripper, source);
104107
}
105-
// line 106 "-"
108+
// line 109 "-"
106109
// %token constants
107110
public static final int keyword_class = 257;
108111
public static final int keyword_module = 258;
@@ -6635,7 +6638,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
66356638
return yyVal;
66366639
};
66376640
}
6638-
// line 4605 "ripper_RubyParser.out"
6641+
// line 4608 "ripper_RubyParser.out"
66396642

66406643
}
6641-
// line 14421 "-"
6644+
// line 14424 "-"

core/src/main/java/org/jruby/ir/IRManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.InputStream;
55
import java.util.EnumSet;
66

7+
import org.jcodings.specific.UTF8Encoding;
78
import org.jruby.Ruby;
89
import org.jruby.RubyInstanceConfig;
910
import org.jruby.RubyModule;
@@ -404,7 +405,7 @@ public IRMethod loadInternalMethod(ThreadContext context, IRubyObject self, Stri
404405

405406
private Node parse(ThreadContext context, FileResource file, String fileName) throws IOException {
406407
try (InputStream stream = file.openInputStream()) {
407-
return context.runtime.parseFile(stream, fileName, null, 0);
408+
return (Node) context.runtime.getParserManager().parseFile(fileName, 0, stream, UTF8Encoding.INSTANCE, null, 0).getAST();
408409
}
409410
}
410411
}

core/src/main/java/org/jruby/ir/IRScope.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,4 +1010,8 @@ public static EnumSet<IRFlags> allocateInitialFlags(IRScope scope) {
10101010
return EnumSet.noneOf(IRFlags.class);
10111011
}
10121012
}
1013+
1014+
public Object getAST() {
1015+
throw new RuntimeException("IRScopes and their descendants should never be asked for a syntax tree");
1016+
}
10131017
}

core/src/main/java/org/jruby/ir/builder/IRBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,11 @@ Nil nil() {
907907
return manager.getNil();
908908
}
909909

910+
RubySymbol symbol(byte[] bytes) {
911+
// FIXME: should be iso8859_1 and not charset java string.
912+
return symbol(new String(bytes));
913+
}
914+
910915
RubySymbol symbol(String id) {
911916
return manager.runtime.newSymbol(id);
912917
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy