Open ju1ius opened 6 years ago
Changing the grammar to:
// Tokens
%token internal_option_ \(\?(?=-?[imsxJUX]) -> opt
%token opt:internal_option -?[imsxJUX] -> opt
%token opt:semicolon : -> default
%token opt:_internal_option \) -> default
// Rules
internal_options:
::internal_option_:: options() ::_internal_option::
| ::internal_option_:: options() ::semicolon:: alternation() ::_capturing:: #noncapturing
options:
<internal_option>+ #internal_options
yields the following parse trees:
Pattern: a(?i)b
> #expression
> > #concatenation
> > > token(literal, a)
> > > #internal_options
> > > > token(opt:internal_option, i)
> > > token(literal, b)
Pattern: a(?i:b)c
> #expression
> > #concatenation
> > > token(literal, a)
> > > #noncapturing
> > > > #internal_options
> > > > > token(opt:internal_option, i)
> > > > token(literal, b)
> > > token(literal, c)
Which seem syntactically correct since, to me at least, (?i:b)
means «a non-capturing-group for which the i option is set».
What do you think ?
Thanks for the report!
About problem 2, I'm not aware of the U
, X
, and J
options. Where did you find them?
n
is missing,An empty options setting "(?)" is allowed. Needless to say, it has no effect.
And right now, this form is not supported.
Let's consider the following diff:
- %token internal_option \(\?[\-+]?[imsx]\)
+ %token internal_option \(\?(-?[imnsx]+)*\)
It should solve problems 1, 2, 3, 4, 6, 7, and 8.
Problem 5 is more tricky, and it's not related to “internal option” directly. Can you open another issue to address it please?
Hi !
What works
a(?i)b
a(?-i)b
All the above work only for the
i
,m
,s
andx
options.What doesn't work:
U
,X
, andJ
optionsa(?im)b
a(?-i-m)b
a(?i-m)b
a(?i:b)c
(?+i)
syntax, but according to the documentation and the PHP implementation this is invalid.All the above fail with:
Unexpected token "?" (zero_or_one) at line 1 and column 3
Possible fixes
Changing the grammar to:
solves n° 1, 2, 3, 4 & 6. n° 5 is a bit more complex... :wink: