Skip to content

Commit 1e96e67

Browse files
author
jneen
committed
style and don't re-scan triple quotes
1 parent d44e3f2 commit 1e96e67

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/rouge/lexers/gherkin.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,28 @@ def self.detect?(text)
2929
end
3030

3131
state :annotated_string do
32-
rule %r(("""(\S+)\n)(.*?)("""))m do |m|
33-
first_line, lang, content, last_line = m.captures
34-
token Str, first_line
32+
rule %r((""")(\S*)(.*?)("""))m do |m|
33+
open, lang, content, close = m.captures
34+
35+
token Str, open
36+
token Str::Escape, lang
37+
3538
sublexer = Rouge::Lexer.find(lang.strip)
39+
3640
if sublexer
3741
delegate sublexer, content
3842
else
3943
token Str, content
4044
end
41-
token Str, last_line
45+
46+
token Str, close
4247
end
4348
end
4449

4550
state :root do
4651
mixin :basic
4752
rule %r(\n), Text
4853
mixin :annotated_string
49-
rule %r(""".*?""")m, Str
5054
rule %r(@[^\s@]+), Name::Tag
5155
mixin :has_table
5256
mixin :has_examples

spec/lexers/gherkin_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ class Calculator
5353
end
5454
"""
5555
GHERKIN
56-
56+
5757
find_calls = []
5858
original_find = Rouge::Lexer.method(:find)
5959
Rouge::Lexer.define_singleton_method(:find) do |lang|
6060
find_calls << lang
6161
original_find.call(lang)
6262
end
63-
63+
6464
tokens = subject.lex(source).to_a
65-
65+
6666
assert { tokens.size == 11 }
6767
assert { tokens[0][0] == Token['Name.Function'] }
6868
assert { tokens[2][0] == Token['Literal.String'] }

0 commit comments

Comments
 (0)