regexp-tree icon indicating copy to clipboard operation
regexp-tree copied to clipboard

grammar expects regex to not end after a #comment with /x

Open dannybrian opened this issue 5 years ago • 1 comments

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 avatar Apr 10 '19 01:04 dannybrian

@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,

DmitrySoshnikov avatar Apr 12 '19 05:04 DmitrySoshnikov