Created
July 18, 2011 01:43
-
-
Save enebo/1088363 to your computer and use it in GitHub Desktop.
ennnnnd support for JRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment