Skip to content

Commit

Permalink
Fix #835: Haskell quasiquotations
Browse files Browse the repository at this point in the history
  • Loading branch information
enolan committed Jan 30, 2018
1 parent 367e989 commit 6089653
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/rouge/lexers/haskell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/visual/samples/haskell
Original file line number Diff line number Diff line change
Expand Up @@ -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
|]

0 comments on commit 6089653

Please sign in to comment.