Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 2.20 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. git diff src/org/jruby/lexer/yacc/RubyYaccLexer.java
  2. diff --git a/src/org/jruby/lexer/yacc/RubyYaccLexer.java b/src/org/jruby/lexer/yacc/RubyYaccLexer.java
  3. index b7268b1..826ca8e 100644
  4. --- a/src/org/jruby/lexer/yacc/RubyYaccLexer.java
  5. +++ b/src/org/jruby/lexer/yacc/RubyYaccLexer.java
  6. @@ -39,6 +39,8 @@ import java.io.IOException;
  7.  
  8.  import java.math.BigInteger;
  9.  import java.util.HashMap;
  10. +import java.util.Stack;
  11. +import java.util.regex.Pattern;
  12.  
  13.  import org.jcodings.Encoding;
  14.  import org.jcodings.specific.ASCIIEncoding;
  15. @@ -121,6 +123,8 @@ public class RubyYaccLexer {
  16.      }
  17.  
  18.      private Encoding encoding;
  19. +    
  20. +    private Stack<Keyword> backlog = new Stack<Keyword>();
  21.  
  22.      public Encoding getEncoding() {
  23.          return encoding;
  24. @@ -309,6 +313,25 @@ public class RubyYaccLexer {
  25.      }
  26.  
  27.      public int nextToken() throws IOException {
  28. +        if (!backlog.isEmpty()) {
  29. +            Keyword keyword = backlog.pop();
  30. +            LexState state = lex_state; // Save state at time keyword is encountered
  31. +
  32. +            setState(keyword.state);
  33. +            if (state == LexState.EXPR_FNAME) {
  34. +                yaccValue = new Token(keyword.name, getPosition());
  35. +            } else {
  36. +                yaccValue = new Token("end", getPosition());
  37. +            }
  38. +
  39. +            if (state == LexState.EXPR_BEG || (!isOneEight && state == LexState.EXPR_VALUE)) return keyword.id0;
  40. +
  41. +            if (keyword.id0 != keyword.id1) setState(LexState.EXPR_BEG);
  42. +
  43. +            return keyword.id1;        
  44. +        }
  45. +        
  46. +            
  47.          token = yylex();
  48.  
  49.          return token == EOF ? 0 : token;
  50. @@ -1662,6 +1685,15 @@ public class RubyYaccLexer {
  51.          }
  52.  
  53.          if (lex_state != LexState.EXPR_DOT) {
  54. +            Pattern pat = Pattern.compile("en+d");
  55. +            
  56. +            if (pat.matcher(tempVal).matches()) {
  57. +                int numberOfEnds = tempVal.length() - 2;
  58. +                for (int i = 0; i < numberOfEnds - 1; i++) {
  59. +                    backlog.add(getKeyword("end"));
  60. +                }
  61. +                tempVal = "end";
  62. +            }
  63.              Keyword keyword = getKeyword(tempVal); // Is it is a keyword?
  64.  
  65.              if (keyword != null && (keyword != Keyword.__ENCODING__ || !isOneEight)) {