regexp-tree
regexp-tree copied to clipboard
grammar expects regex to not end after a #comment with /x
The current comment grammar eats up the slash and flags after a comment when using the x
flag:
const re = `/
# A regular expression for date.
(?<year>\d{4})- # year part of a date
(?<month>\d{2})- # month part of a date
(?<day>\d{2}) # day part of a date /x`; // \/\w* shouldn't get eaten
This yields "SyntaxError: Unexpected end of input". See pull request for fix and changed test to match. Thanks!
@dannybrian, thanks, this might be a good addition. Though we need to consider whether it reflects semantics of a line-comment in existing systems. Usually a line-comment goes until the end of of a string, whatever symbols it contains.
const re `/
...
# should this /x`; still be a comment?
# another comment /x;`
/x`; // and an actual close of regexp
In the first comment,