Skip to content

Commit

Permalink
Support promoted data constructors in Haskell lexer (#1027)
Browse files Browse the repository at this point in the history
This commit adds support for promoted data constructors to the Haskell
lexer. Unfortunately there is a bit of ambiguity with char literals.
This commit errs on the side of char literks. The data constructor `A'`
would be `'A'` in promoted form but the lexer will highlight this as a
char literal.
  • Loading branch information
bgamari authored and pyrmont committed Jun 20, 2019
1 parent 00e472f commit 2edea1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rouge/lexers/haskell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def self.detect?(text)
# rule %r/^[_a-z][\w']*/, Name::Function
rule %r/[_a-z][\w']*/, Name
rule %r/[A-Z][\w']*/, Keyword::Type
rule %r/'[A-Z]\w+'?/, Keyword::Type # promoted data constructor

# lambda operator
rule %r(\\(?![:!#\$\%&*+.\\/<=>?@^\|~-]+)), Name::Function
Expand Down
7 changes: 7 additions & 0 deletions spec/visual/samples/haskell
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

-- Initial tests

_a'
Ab'
'Cd'

---------------------------------------------------------------------
-- SmallCheck: another lightweight testing library.
-- Colin Runciman, August 2006
Expand Down

0 comments on commit 2edea1f

Please sign in to comment.