diff options
author | Georg Brandl <georg@python.org> | 2019-11-24 16:18:10 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2019-11-24 16:40:54 +0100 |
commit | f113b24f5f02bd294087fe13364f16e2bfed11f7 (patch) | |
tree | d1d44dea2372aabac622fdc07216f769d214afe9 /pygments/lexers/ruby.py | |
parent | 356aff3ac93891532ffd5f44a360ad8403a2aca0 (diff) | |
download | pygments-git-f113b24f5f02bd294087fe13364f16e2bfed11f7.tar.gz |
Ruby: support squiggly heredocs (bitbucket PR #729)
Diffstat (limited to 'pygments/lexers/ruby.py')
-rw-r--r-- | pygments/lexers/ruby.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/pygments/lexers/ruby.py b/pygments/lexers/ruby.py index 723895d1..8bcbde67 100644 --- a/pygments/lexers/ruby.py +++ b/pygments/lexers/ruby.py @@ -43,17 +43,17 @@ class RubyLexer(ExtendedRegexLexer): def heredoc_callback(self, match, ctx): # okay, this is the hardest part of parsing Ruby... - # match: 1 = <<-?, 2 = quote? 3 = name 4 = quote? 5 = rest of line + # match: 1 = <<[-~]?, 2 = quote? 3 = name 4 = quote? 5 = rest of line start = match.start(1) - yield start, Operator, match.group(1) # <<-? + yield start, Operator, match.group(1) # <<[-~]? yield match.start(2), String.Heredoc, match.group(2) # quote ", ', ` yield match.start(3), String.Delimiter, match.group(3) # heredoc name yield match.start(4), String.Heredoc, match.group(4) # quote again heredocstack = ctx.__dict__.setdefault('heredocstack', []) outermost = not bool(heredocstack) - heredocstack.append((match.group(1) == '<<-', match.group(3))) + heredocstack.append((match.group(1) in ('<<-', '<<~'), match.group(3))) ctx.pos = match.start(5) ctx.end = match.end(5) @@ -247,10 +247,10 @@ class RubyLexer(ExtendedRegexLexer): Name.Builtin), (r'__(FILE|LINE)__\b', Name.Builtin.Pseudo), # normal heredocs - (r'(?<!\w)(<<-?)(["`\']?)([a-zA-Z_]\w*)(\2)(.*?\n)', + (r'(?<!\w)(<<[-~]?)(["`\']?)([a-zA-Z_]\w*)(\2)(.*?\n)', heredoc_callback), # empty string heredocs - (r'(<<-?)("|\')()(\2)(.*?\n)', heredoc_callback), + (r'(<<[-~]?)("|\')()(\2)(.*?\n)', heredoc_callback), (r'__END__', Comment.Preproc, 'end-part'), # multiline regex (after keywords or assignments) (r'(?:^|(?<=[=<>~!:])|' |