public
Created

ennnnnd support for JRuby

  • Download Gist
gistfile1.txt
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
git diff src/org/jruby/lexer/yacc/RubyYaccLexer.java
diff --git a/src/org/jruby/lexer/yacc/RubyYaccLexer.java b/src/org/jruby/lexer/yacc/RubyYaccLexer.java
index b7268b1..826ca8e 100644
--- a/src/org/jruby/lexer/yacc/RubyYaccLexer.java
+++ b/src/org/jruby/lexer/yacc/RubyYaccLexer.java
@@ -39,6 +39,8 @@ import java.io.IOException;
import java.math.BigInteger;
import java.util.HashMap;
+import java.util.Stack;
+import java.util.regex.Pattern;
import org.jcodings.Encoding;
import org.jcodings.specific.ASCIIEncoding;
@@ -121,6 +123,8 @@ public class RubyYaccLexer {
}
private Encoding encoding;
+
+ private Stack<Keyword> backlog = new Stack<Keyword>();
public Encoding getEncoding() {
return encoding;
@@ -309,6 +313,25 @@ public class RubyYaccLexer {
}
public int nextToken() throws IOException {
+ if (!backlog.isEmpty()) {
+ Keyword keyword = backlog.pop();
+ LexState state = lex_state; // Save state at time keyword is encountered
+
+ setState(keyword.state);
+ if (state == LexState.EXPR_FNAME) {
+ yaccValue = new Token(keyword.name, getPosition());
+ } else {
+ yaccValue = new Token("end", getPosition());
+ }
+
+ if (state == LexState.EXPR_BEG || (!isOneEight && state == LexState.EXPR_VALUE)) return keyword.id0;
+
+ if (keyword.id0 != keyword.id1) setState(LexState.EXPR_BEG);
+
+ return keyword.id1;
+ }
+
+
token = yylex();
return token == EOF ? 0 : token;
@@ -1662,6 +1685,15 @@ public class RubyYaccLexer {
}
if (lex_state != LexState.EXPR_DOT) {
+ Pattern pat = Pattern.compile("en+d");
+
+ if (pat.matcher(tempVal).matches()) {
+ int numberOfEnds = tempVal.length() - 2;
+ for (int i = 0; i < numberOfEnds - 1; i++) {
+ backlog.add(getKeyword("end"));
+ }
+ tempVal = "end";
+ }
Keyword keyword = getKeyword(tempVal); // Is it is a keyword?
if (keyword != null && (keyword != Keyword.__ENCODING__ || !isOneEight)) {

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.