-
Notifications
You must be signed in to change notification settings - Fork 14
Conversation
It replaces the `Identifier` enumerator.
The `name` rule is mostly a renaming from `identifier`; it removes the `Identifier` computation and returns a simple `&[u8]`.
f79f472
to
012b4b0
Compare
#24 has been merged, so I have rebased the commits on |
First, UTF-8 validation is not required. Second, the parser works with `&[u8]` so it eases the comparison with existing tokens.
These new variants (`Unqualified`, `Qualified`, `RelativeQualified`, and `FullyQualified`) better reflects the actual semantics of the code.
This new rule replaces the `namespace` rule.
efd5dbe
to
c36470e
Compare
`and_not!(I -> IResult<I, O>, I -> IResult<I, P>) => I -> IResult<I, 0>` returns the result of the first parser if the second fails. Both parsers run on the same input. This is handy when the first parser accepts general values and the second parser denies a particular subset of values.
The following input is valid: `namespace\Foo\Bar`, while this one is not: `Foo\namespace\Bar`. `namespace` is a valid name but the `qualified_name` rule must be stricter.
@jubianchi: Ready for a review! |
Qualified(Vec<&'a [u8]>), | ||
/// A relative qualified name, i.e. a name in a relative namespace | ||
/// restricted to the current namespace, like `namespace\Foo\Bar`. | ||
RelativeQualified(Vec<&'a [u8]>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not very confident with this name. I wonder if RestrictedQualified
would not be better.
cc @nikic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment has been closed by Github. I am reopening it.
Applies the parser 0 or more times and skips the consumed data, nothing is returned. The embedded parser may return `nom::IResult::Incomplete`. This is heavily inspired by the original nom `many0` macro.
Exact about |
This macro is applying the `skip` rule before the first argument; it allows to skip tokens.
The following qualified name is valid: ```php Foo /* baz*/ \ Bar ``` It is equivalent to: ```php Foo\Bar ``` By using the `first` macro, skip tokens can be supported.
The `first!(parser)` syntax was not tested. This patch extends existing test cases to test this particular syntax.
4b2cad4
to
b38d2bb
Compare
"The `YIELD` token.\n\nRepresent the generator operator, e.g. `yield …;`." | ||
); | ||
token!( | ||
pub YIELD_FROM: "yield from"; | ||
pub YIELD_FROM: b"yield from"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR, but the whitespace between yield
and from
isn't necessarily a single character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Thanks for this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it all whitespaces, comments etc. (skip tokens) or just regular space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spec says
Note carefully that yield from is a single token that contains whitespace. However, comments are not permitted in that whitespace.
So any whitespace is fine, but no comments.
6d0978b
to
50cd568
Compare
) | ||
} | ||
|
||
test_keyword!(case_keyword_abstract: (b"abstract", super::ABSTRACT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add some tests to make sure variations with different case work? ABSTRACT
, AbStRaCt
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
A qualified name is composed of `name` rule. However, some values must be excluded from the `name` rule. Previously, only the `namespace` token was excluded but this was wrong: All the keywords must be excluded.
Damn, the https://github.com/php/php-langspec/blob/master/spec/19-grammar.md#names Section does not cover all the constraints. Actually https://github.com/php/php-langspec/blob/master/spec/09-lexical-structure.md provides much more details. I will review my PR with this Section in mind. |
This macro declares a case-insensitive ASCII array as a suite to recognize. It is pretty similar to the nom `tag!` macro except it is case-insensitive and only accepts ASCII characters so far.
This patch uses the new `itag` macro. Associated test suite is updated by testing the given result and its uppercased version.
c5f3231
to
ab230d0
Compare
It is an alias to the `itag` macro. The goal of this alias is twofold: 1. It avoids confusion and errors (a PHP keyword is always case-insensitive), 2. It ensures a better readability of parsers.
This patch ensures that case is insensitive for tokens in qualified names.
This is just a semantic change.
`yield from` is a keyword but the specification says: > Note carefully that yield from is a single token that contains > whitespace. However, comments are not permitted in that whitespace.
Address #10.
Must be merged after #24.
Specification
https://github.com/php/php-langspec/blob/master/spec/19-grammar.md#names
Progression
keyword
parser.yield from
can (only) have whitespaces betweenyield
andfrom
(https://github.com/php/php-langspec/blob/master/spec/09-lexical-structure.md#keywords),itag
parser and macro,keyword
macro, alias toitag
,keywords
parser,keywords
test suite,qualified_name
,qualified_name
test suite.