pub struct Ident<'src> {
pub span: Span,
/* private fields */
}Expand description
A bare identifier — the kind that names a function, class, parameter,
enum case, etc. Distinct from Name, which represents possibly-qualified
names.
The “error” state — produced during error recovery when no identifier was found in the source — is represented by an empty name, which cannot occur for a real PHP identifier (the lexer rejects empty matches).
Use Ident::new / Ident::error to construct, Ident::as_str to
extract a real name, Ident::is_error to test for the error state.
Serialises as {"name": .., "span": ..} for real names and null for the
error state.
Fields§
§span: SpanSource range of the identifier token; includes the $ of a variable name.
Implementations§
Source§impl<'src> Ident<'src>
impl<'src> Ident<'src>
Sourcepub fn new(name: &'src str, span: Span) -> Self
pub fn new(name: &'src str, span: Span) -> Self
Construct an identifier from a non-empty name.
Empty input is rejected in debug builds — use Ident::error instead.
Sourcepub fn as_str(&self) -> Option<&'src str>
pub fn as_str(&self) -> Option<&'src str>
Returns Some(s) for a real identifier, None for the error state.