diff options
| author | Colomban Wendling <ban@herbesfolles.org> | 2016-02-17 15:49:22 +0100 | 
|---|---|---|
| committer | Colomban Wendling <ban@herbesfolles.org> | 2016-02-17 15:49:22 +0100 | 
| commit | b7a58f9c9c4067714b2118c2ee96e0867d0c0190 (patch) | |
| tree | 067d37932987705d47b3612bea93c0443f79e2c1 /lexers/LexRuby.cxx | |
| parent | 8cb3d9c412f1d09f0f4c94df84ff980f3e83c949 (diff) | |
| download | scintilla-mirror-b7a58f9c9c4067714b2118c2ee96e0867d0c0190.tar.gz | |
Ruby: Fix some HereDoc recognition with several expressions on a line
Part of bug [#1810].
Diffstat (limited to 'lexers/LexRuby.cxx')
| -rw-r--r-- | lexers/LexRuby.cxx | 31 | 
1 files changed, 30 insertions, 1 deletions
| diff --git a/lexers/LexRuby.cxx b/lexers/LexRuby.cxx index 092f71dd0..42f30fd2a 100644 --- a/lexers/LexRuby.cxx +++ b/lexers/LexRuby.cxx @@ -433,6 +433,32 @@ static bool haveTargetMatch(Sci_Position currPos,      return true;  } +// Finds the start position of the expression containing @p pos +// @p min_pos should be a known expression start, e.g. the start of the line +static Sci_Position findExpressionStart(Sci_Position pos, +                                        Sci_Position min_pos, +                                        Accessor &styler) { +    int depth = 0; +    for (; pos > min_pos; pos -= 1) { +        int style = styler.StyleAt(pos - 1); +        if (style == SCE_RB_OPERATOR) { +            int ch = styler[pos - 1]; +            if (ch == '}' || ch == ')' || ch == ']') { +                depth += 1; +            } else if (ch == '{' || ch == '(' || ch == '[') { +                if (depth == 0) { +                    break; +                } else { +                    depth -= 1; +                } +            } else if (ch == ';' && depth == 0) { +                break; +            } +        } +    } +    return pos; +} +  // We need a check because the form  // [identifier] <<[target]  // is ambiguous.  The Ruby lexer/parser resolves it by @@ -458,8 +484,11 @@ static bool sureThisIsNotHeredoc(Sci_Position lt2StartPos,      const bool definitely_not_a_here_doc = true;      const bool looks_like_a_here_doc = false; +    // find the expression start rather than the line start +    Sci_Position exprStartPosn = findExpressionStart(lt2StartPos, lineStartPosn, styler); +      // Find the first word after some whitespace -    Sci_Position firstWordPosn = skipWhitespace(lineStartPosn, lt2StartPos, styler); +    Sci_Position firstWordPosn = skipWhitespace(exprStartPosn, lt2StartPos, styler);      if (firstWordPosn >= lt2StartPos) {          return definitely_not_a_here_doc;      } | 
