Skip to content

Possible parsing problem with Regexp in extended mode #4097

@gettalong

Description

@gettalong

When parsing a Regexp in extended mode, the documentation states:

Modifier x enables extended mode, which means that:

  • Literal white space in the pattern is to be ignored.
  • Character # marks the remainder of its containing line as a comment,
    which is also to be ignored for matching purposes.

The following Regexp in extended mode doesn't not exactly do what I imagined:

/
test # the following slash / should be ignored
/x

My interpretation of the documentation is that anything after # is ignored. However, the / is not ignored, leading to the following error message:

-: -:2: syntax errors found (SyntaxError)
  1 | /
> 2 | test # the following slash / should be ignored
    |                              ^~~~~~ unexpected local variable or method, expecting end-of-input
> 3 | /x
    | ^ unterminated regexp meets end of file; expected a closing delimiter

Note that using the old parse.y implementation also leads to an error:

-:2: syntax error, unexpected local variable or method, expecting end-of-input
... # the following slash / should be ignored
-: compile error (SyntaxError)

So is this a parsing error or a documentation error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions