diff --git a/lib/rouge/lexers/haskell.rb b/lib/rouge/lexers/haskell.rb index aa3fe00612..bd84517963 100644 --- a/lib/rouge/lexers/haskell.rb +++ b/lib/rouge/lexers/haskell.rb @@ -81,6 +81,15 @@ def self.detect?(text) rule /\[\s*\]/, Keyword::Type rule /\(\s*\)/, Name::Builtin + + # Quasiquotations + rule /(\[)([_a-z][\w']*)(\|)/ do |m| + token Operator, m[1] + token Name, m[2] + token Operator, m[3] + push :quasiquotation + end + rule /[\[\](),;`{}]/, Punctuation end @@ -162,6 +171,12 @@ def self.detect?(text) rule /./, Error, :pop! end + state :quasiquotation do + rule /\|\]/, Operator, :pop! + rule /[^\|]+/m, Text + rule /\|/, Text + end + state :string do rule /"/, Str, :pop! rule /\\/, Str::Escape, :escape diff --git a/spec/visual/samples/haskell b/spec/visual/samples/haskell index 77c7f9df12..d30280d448 100644 --- a/spec/visual/samples/haskell +++ b/spec/visual/samples/haskell @@ -383,3 +383,12 @@ foo = replicate n '\x1f363' bar :: String bar = "\x1f389\x1f363\x1f389" + +quasi1 = [quoter|Some quoted text|] + +quasi2 = [quoter'|Some text with a | in it|] + +quasi3 = [here|Newlines +are part of +the quotation +|]