Skip to content

Commit

Permalink
First swipe at 3.0 grammar.
Browse files Browse the repository at this point in the history
Most 3.0 stuff currently does not work but this still passes 2.6 specs
without crashing.  Next phase will be filling out the AST fully so parsing
new features will not die during parse itself but during IR building.  Things
like endless methods no doubt are fully working already as they are just
syntactical sugar.
  • Loading branch information
enebo committed Apr 7, 2021
1 parent 57a52b9 commit 2d4e192
Show file tree
Hide file tree
Showing 17 changed files with 9,633 additions and 7,005 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -6,7 +6,7 @@ DO NOT MODIFIY - GENERATED CODE
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand Down
24 changes: 24 additions & 0 deletions core/src/main/java/org/jruby/ast/DefHolder.java
@@ -0,0 +1,24 @@
package org.jruby.ast;

import org.jruby.RubySymbol;
import org.jruby.lexer.yacc.LexContext;
import org.jruby.util.ByteList;

public class DefHolder {
public final RubySymbol name;
public final ByteList current_arg;
public final LexContext ctxt;

public int line;
public Node singleton = null;

public DefHolder(RubySymbol name, ByteList currentArg, LexContext ctxt) {
this.name = name;
this.current_arg = currentArg;
this.ctxt = ctxt;
}

public void setSingleton(Node singleton) {
this.singleton = singleton;
}
}
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/ext/ripper/RipperLexer.java
Expand Up @@ -226,6 +226,8 @@ public static Keyword getKeyword(String str) {
// field since all ident logic should hit sequentially.
String identValue;

boolean inKwarg;

// Used for tiny smidgen of grammar in lexer (see setParserSupport())
private RipperParserBase parser = null;

Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/lexer/LexingCommon.java
Expand Up @@ -11,6 +11,7 @@
import org.jruby.RubyEncoding;
import org.jruby.RubyRegexp;
import org.jruby.exceptions.RaiseException;
import org.jruby.lexer.yacc.LexContext;
import org.jruby.lexer.yacc.StackState;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
Expand Down Expand Up @@ -47,6 +48,7 @@ public LexingCommon(LexerSource src) {
this.src = src;
}

private LexContext lexContext = new LexContext();
protected int braceNest = 0;
public boolean commandStart;
protected StackState conditionState = new StackState();
Expand All @@ -59,7 +61,6 @@ public LexingCommon(LexerSource src) {
protected int heredoc_end = 0;
protected int heredoc_indent = 0;
protected int heredoc_line_indent = 0;
public boolean inKwarg = false;
protected int last_cr_line;
protected int last_state;
private int leftParenBegin = 0;
Expand Down Expand Up @@ -219,6 +220,10 @@ protected void flush() {
tokp = lex_p;
}

public LexContext getLexContext() {
return lexContext;
}

public int getBraceNest() {
return braceNest;
}
Expand Down
36 changes: 36 additions & 0 deletions core/src/main/java/org/jruby/lexer/yacc/LexContext.java
@@ -0,0 +1,36 @@
package org.jruby.lexer.yacc;

import org.jruby.ast.DefHolder;

public class LexContext {
// Is the parser currently within a class body.
public boolean in_class;

// Is the parser currently within a method definition
public boolean in_def;

public boolean in_defined;

public boolean in_kwarg;

public ShareableConstantValue shareable_constant_value;

public void reset() {
in_def = false;
}

public Object clone() {
LexContext context = new LexContext();
context.in_class = in_class;
context.in_def = in_def;
context.in_defined = in_defined;
context.shareable_constant_value = shareable_constant_value;

return context;
}

public void restore(DefHolder holder) {
this.in_def = holder.ctxt.in_def;
this.shareable_constant_value = holder.ctxt.shareable_constant_value;
}
}

0 comments on commit 2d4e192

Please sign in to comment.