Skip to content

Commit dfe300f

Browse files
committed
Disjoin the string-gap and escape regex alternatives
1 parent 6c2b7a0 commit dfe300f

6 files changed

Lines changed: 8737 additions & 8758 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
branches: [main]
55
pull_request:
66

7+
permissions:
8+
contents: read
9+
710
jobs:
811
test:
912
runs-on: ubuntu-22.04

common/grammar/haskell.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ export function makeLiteralRules() {
4545
// (`'\NUL'`). `\\.` takes the backslash + first escape char (covers `'\''`,
4646
// `'\n'`, `'\\'`), then `[^']*` absorbs the rest up to the closing quote.
4747
_char_lit: ($) => token(/'(\\.[^']*|[^'\\])'#*/),
48-
// A backslash escapes any char, including a newline. GHC also prints long
49-
// strings with a string gap `\ <whitespace> \` (`..\n\` <newline> ` \..`),
50-
// which the regex must not misread:
48+
// Backslash escapes any non-space char. GHC also emits long strings with a
49+
// gap `\ <whitespace> \`, matched as its own alternative `\\\s+\\` for two
50+
// reasons:
5151
//
52-
// - The resume `\` must not pair with the following escape. `\\"` is a
53-
// gap-resume then an escaped quote, not an escaped backslash then a
54-
// terminating quote that would end the string early.
52+
// - The gap's trailing `\` is consumed here, so it cannot pair with a
53+
// following `"` and end the string early.
5554
//
56-
// - So the gap `\\\s+\\` is its own longest-match alternative, ahead of
57-
// the `\\[\s\S]` escape and the `[^"\\]` char.
58-
_string_lit: ($) => token(/"(\\\s+\\|\\[\s\S]|[^"\\])*"#*/),
55+
// - The escape stays `\\\S`, disjoint from the gap. An overlapping
56+
// `\\[\s\S]` lets a `\ \ \ ..` run split many ways inside the `*`
57+
// (quadratic).
58+
_string_lit: ($) => token(/"(\\\s+\\|\\\S|[^"\\])*"#*/),
5959
};
6060
}
6161

tree-sitter-ghc-core/src/grammar.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)