|
1 | 1 | import * as CharSet from './char-set' |
2 | 2 | import * as RE from './regex' |
| 3 | +import { UnsupportedSyntaxError } from './regex-parser' |
3 | 4 | import { assert, checkedAllCases, isOneOf } from './utils' |
4 | 5 |
|
5 | 6 | /** |
@@ -243,16 +244,22 @@ function pullUpStartAnchor(ast: RegExpAST): RegExpAST { |
243 | 244 | } |
244 | 245 | } |
245 | 246 | case "positive-lookahead": { |
| 247 | + const inner = pullUpStartAnchor(ast.inner) |
246 | 248 | const right = pullUpStartAnchor(ast.right) |
247 | | - if (right.type === 'start-anchor') { |
| 249 | + if (inner.type === 'start-anchor') { |
| 250 | + throw new UnsupportedSyntaxError('start anchors (^) inside lookaheads are not supported') |
| 251 | + } else if (right.type === 'start-anchor') { |
248 | 252 | return startAnchor(undefined, positiveLookahead(ast.inner, right.right)) |
249 | 253 | } else { |
250 | 254 | return positiveLookahead(ast.inner, right) |
251 | 255 | } |
252 | 256 | } |
253 | 257 | case "negative-lookahead": { |
| 258 | + const inner = pullUpStartAnchor(ast.inner) |
254 | 259 | const right = pullUpStartAnchor(ast.right) |
255 | | - if (right.type === 'start-anchor') { |
| 260 | + if (inner.type === 'start-anchor') { |
| 261 | + throw new UnsupportedSyntaxError('start anchors (^) inside lookaheads are not supported') |
| 262 | + } else if (right.type === 'start-anchor') { |
256 | 263 | return startAnchor(undefined, negativeLookahead(ast.inner, right.right)) |
257 | 264 | } else { |
258 | 265 | return negativeLookahead(ast.inner, right) |
@@ -386,16 +393,22 @@ function pullUpEndAnchor(ast: RegExpAST): RegExpAST { |
386 | 393 | } |
387 | 394 | } |
388 | 395 | case "positive-lookahead": { |
| 396 | + const inner = pullUpEndAnchor(ast.inner) |
389 | 397 | const right = pullUpEndAnchor(ast.right) |
390 | | - if (right.type === 'end-anchor') { |
| 398 | + if (inner.type === 'end-anchor') { |
| 399 | + throw new UnsupportedSyntaxError('end anchors ($) inside lookaheads are not supported') |
| 400 | + } else if (right.type === 'end-anchor') { |
391 | 401 | return endAnchor(positiveLookahead(ast.inner, right.left), undefined) |
392 | 402 | } else { |
393 | 403 | return positiveLookahead(ast.inner, right) |
394 | 404 | } |
395 | 405 | } |
396 | 406 | case "negative-lookahead": { |
| 407 | + const inner = pullUpEndAnchor(ast.inner) |
397 | 408 | const right = pullUpEndAnchor(ast.right) |
398 | | - if (right.type === 'end-anchor') { |
| 409 | + if (inner.type === 'end-anchor') { |
| 410 | + throw new UnsupportedSyntaxError('end anchors ($) inside lookaheads are not supported') |
| 411 | + } else if (right.type === 'end-anchor') { |
399 | 412 | return endAnchor(negativeLookahead(ast.inner, right.right), undefined) |
400 | 413 | } else { |
401 | 414 | return negativeLookahead(ast.inner, right) |
|
0 commit comments