Skip to content

Commit

Permalink
Merge pull request #868 from signalvine/haskell-quasiquotes
Browse files Browse the repository at this point in the history
  • Loading branch information
dblessing committed Apr 3, 2018
2 parents 984d20e + 6089653 commit c230251
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
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
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 c230251

Please sign in to comment.