Skip to content

Commit

Permalink
Different fix for #161
Browse files Browse the repository at this point in the history
  • Loading branch information
sheaf committed May 15, 2020
1 parent 22f713b commit 7dcb241
Show file tree
Hide file tree
Showing 5 changed files with 327 additions and 5 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## 3.2.1. - 14.05.2020
## x.x.x - Unreleased

- Fix excessive backtracking in regular expression for data declarations
- Different approach to fixing slow highlighting of data declarations
([#161](https://github.com/JustusAdam/language-haskell/issues/161)).


## 3.2.1 - 14.05.2020

- Attempt to limit backtracking in regular expression for data declarations
([#161](https://github.com/JustusAdam/language-haskell/issues/161)).
- Improved highlighting for multi-line standalone kind signatures.
- Improved type highlighting in multiline deriving declarations.
Expand Down
11 changes: 9 additions & 2 deletions syntaxes/haskell.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,6 @@ repository:
'2': {name: keyword.operator.pipe.haskell}
end: >-
(?x)
(?:\G|^)\s* # Enforce starting condition to avoid catastrophic backtracking (https://github.com/JustusAdam/language-haskell/issues/161)
(?: # Infix data constructor
# First argument
(?:
Expand Down Expand Up @@ -994,12 +993,20 @@ repository:
# - an alphabetic infix constructor
| (`)([\p{Lu}\p{Lt}][\p{Ll}_\p{Lu}\p{Lt}\p{Nd}']*)(`)
)
) # Otherwise, prefix data constructor, either:
| # - an alphabetic data constructor e.g. "Cons_123"
(?:(?<!')\b([\p{Lu}\p{Lt}][\p{Ll}_\p{Lu}\p{Lt}\p{Nd}']*))
| # - a symbolic (prefix) data constructor
(\()\s*(:[\p{S}\p{P}&&[^(),;\[\]`{}_"']]*)\s*(\))
| # Otherwise, try to fail early to avoid excessive backtracking (https://github.com/JustusAdam/language-haskell/issues/161)
# Fail when detecting a lowercase identifier and then something not starting with a tick or colon
(?=\b(?<!')(?!(?:forall|deriving)\s)[\p{Ll}_]\S+\s+[^`:])
# Fail when seeing another equal signs or pipe symbol
|(?=
(?<![\p{S}\p{P}&&[^(),;\[\]`{}_"']]) # non-symbol
(?:=|\|)
(?![\p{S}\p{P}&&[^(),;\[\]`{}_"']]) # non-symbol
)
endCaptures:
'1':
patterns:
Expand Down
2 changes: 1 addition & 1 deletion test/tests/ADTs.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- SYNTAX TEST "source.haskell" "ADTs"

data T = C T
data T = C
-- ^^^^ keyword.other.data.haskell
-- ^ storage.type.haskell
-- ^ constant.other.haskell
Expand Down
275 changes: 275 additions & 0 deletions test/tests/SlowHighlighting.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
-- SYNTAX TEST "source.haskell" "Test slow highlighting of data constructor definitions"


data A =

type X = Y
-- <---- keyword.other.type.haskell

data A =

xxxxxxxxxxxxxxxxx Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
( Dddddddddddddddddddddddddd ( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Dddddddddddddddddddddddddd
( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Hhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiii )
)
)
)
)
)
)
)
)
xxxxxxxxxxxxxxxxx Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
( Dddddddddddddddddddddddddd ( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Dddddddddddddddddddddddddd
( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Hhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiii )
)
)
)
)
)
)
)
)
xxxxxxxxxxxxxxxxx Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
( Dddddddddddddddddddddddddd ( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Dddddddddddddddddddddddddd
( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Hhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiii )
)
)
)
)
)
)
)
)
xxxxxxxxxxxxxxxxx Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
( Dddddddddddddddddddddddddd ( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Dddddddddddddddddddddddddd
( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Hhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiii )
)
)
)
)
)
)
)
)
xxxxxxxxxxxxxxxxx Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
( Dddddddddddddddddddddddddd ( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Dddddddddddddddddddddddddd
( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Hhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiii )
)
)
)
)
)
)
)
)
xxxxxxxxxxxxxxxxx Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
( Dddddddddddddddddddddddddd ( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Dddddddddddddddddddddddddd
( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Hhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiii )
)
)
)
)
)
)
)
)
xxxxxxxxxxxxxxxxx Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
( Dddddddddddddddddddddddddd ( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Dddddddddddddddddddddddddd
( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Hhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiii )
)
)
)
)
)
)
)
)
xxxxxxxxxxxxxxxxx Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
( Dddddddddddddddddddddddddd ( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Dddddddddddddddddddddddddd
( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Hhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiii )
)
)
)
)
)
)
)
)
xxxxxxxxxxxxxxxxx Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb |
( Dddddddddddddddddddddddddd ( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Dddddddddddddddddddddddddd
( Eeeeeeeeeeeeeeeeeeeeeeeee fffffffffffffffffffffffff )
( Eeeeeeeeeeeeeeeeeeeeeeeee Fffffffffffffffffffffffff |
( Gggggggggggggggggggggg ( Aaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccc )
( Dddddddddddddddddddddddddddd eeeeeeeeeeeeeeeeeeeeeeeeee |
( Hhhhhhhhhhhhhhhh iiiiiiiiiiiiiiiii )
)
)
)
)
)
)
)
)

data BenchResult =

instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
instance ( Aaaaaaaaaa x ) where
-- <-------- keyword.other.instance.haskell
34 changes: 34 additions & 0 deletions test/tickets/T0153.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,40 @@
-- ^ ^ ^ variable.other.generic-type.haskell
-- ^ ^ ^ storage.type.haskell

data E x =
-- ^^^^ keyword.other.data.haskell
-- ^ storage.type.haskell
-- ^ variable.other.generic-type.haskell
-- ^ keyword.operator.eq.haskell
C x => Bar x A
-- ^^ keyword.operator.big-arrow.haskell
-- ^^^ constant.other.haskell
-- ^ ^ variable.other.generic-type.haskell
-- ^ ^ storage.type.haskell
data E x =
-- ^^^^ keyword.other.data.haskell
-- ^ storage.type.haskell
-- ^ variable.other.generic-type.haskell
-- ^ keyword.operator.eq.haskell
forall x. Bar x A
-- ^^^^^^ keyword.other.forall.haskell
-- ^ keyword.operator.period.haskell
-- ^^^ constant.other.haskell
-- ^ ^ variable.other.generic-type.haskell
-- ^ storage.type.haskell
data E x =
-- ^^^^ keyword.other.data.haskell
-- ^ storage.type.haskell
-- ^ variable.other.generic-type.haskell
-- ^ keyword.operator.eq.haskell
forall x . C x => Bar x A
-- ^^^^^^ keyword.other.forall.haskell
-- ^ keyword.operator.period.haskell
-- ^^ keyword.operator.big-arrow.haskell
-- ^^^ constant.other.haskell
-- ^ ^ variable.other.generic-type.haskell
-- ^ ^ storage.type.haskell

f :: forall x. C x => Bar x A
-- ^ entity.name.function.haskell
-- ^^ keyword.operator.double-colon.haskell
Expand Down

0 comments on commit 7dcb241

Please sign in to comment.