Skip to main content

TokenKind

Enum TokenKind 

Source
pub enum TokenKind {
Show 131 variants My, Our, Local, State, Sub, If, Elsif, Else, Unless, While, Until, For, Foreach, Return, Package, Use, No, Begin, End, Check, Init, Unitcheck, Eval, Do, Given, When, Default, Try, Catch, Finally, Continue, Next, Last, Redo, Goto, Class, Method, Field, Format, Undef, Assign, Plus, Minus, Star, Slash, Percent, Power, LeftShift, RightShift, BitwiseAnd, BitwiseOr, BitwiseXor, BitwiseNot, PlusAssign, MinusAssign, StarAssign, SlashAssign, PercentAssign, DotAssign, AndAssign, OrAssign, XorAssign, PowerAssign, LeftShiftAssign, RightShiftAssign, LogicalAndAssign, LogicalOrAssign, DefinedOrAssign, Equal, NotEqual, Match, NotMatch, SmartMatch, Less, Greater, LessEqual, GreaterEqual, Spaceship, StringCompare, And, Or, Not, DefinedOr, WordAnd, WordOr, WordNot, WordXor, Arrow, FatArrow, Dot, Range, Ellipsis, Increment, Decrement, DoubleColon, Question, Colon, Backslash, LeftParen, RightParen, LeftBrace, RightBrace, LeftBracket, RightBracket, Semicolon, Comma, Number, String, Regex, Substitution, Transliteration, QuoteSingle, QuoteDouble, QuoteWords, QuoteCommand, HeredocStart, HeredocBody, FormatBody, DataMarker, DataBody, VString, UnknownRest, HeredocDepthLimit, Identifier, ScalarSigil, ArraySigil, HashSigil, SubSigil, GlobSigil, Eof, Unknown,
}
Expand description

Token classification for Perl parsing.

The set is intentionally simplified for fast parser matching while covering keywords, operators, delimiters, literals, identifiers, and special tokens.

Use TokenKind::display_name to get a human-readable string suitable for error messages shown to the user.

§Categories

GroupExamples
KeywordsMy, Sub, If, …
OperatorsPlus, Arrow, And, …
DelimitersLeftParen, LeftBrace, …
LiteralsNumber, String, Regex, …
IdentifiersIdentifier, ScalarSigil, …
SpecialEof, Unknown

Variants§

§

My

Lexical variable declaration: my $x

§

Our

Package variable declaration: our $x

§

Local

Dynamic scoping: local $x

§

State

Persistent variable: state $x

§

Sub

Subroutine declaration: sub foo

§

If

Conditional: if (cond)

§

Elsif

Else-if conditional: elsif (cond)

§

Else

Else branch: else { }

§

Unless

Negated conditional: unless (cond)

§

While

While loop: while (cond)

§

Until

Until loop: until (cond)

§

For

C-style for loop: for (init; cond; update)

§

Foreach

Iterator loop: foreach $x (@list)

§

Return

Return statement: return $value

§

Package

Package declaration: package Foo

§

Use

Module import: use Module

§

No

Disable pragma/module: no strict

§

Begin

Compile-time block: BEGIN { }

§

End

Exit-time block: END { }

§

Check

Check phase block: CHECK { }

§

Init

Init phase block: INIT { }

§

Unitcheck

Unit check block: UNITCHECK { }

§

Eval

Exception handling: eval { }

§

Do

Block execution: do { } or do "file"

§

Given

Switch expression: given ($x)

§

When

Case clause: when ($pattern)

§

Default

Default case: default { }

§

Try

Try block: try { }

§

Catch

Catch block: catch ($e) { }

§

Finally

Finally block: finally { }

§

Continue

Continue block: continue { }

§

Next

Loop control: next

§

Last

Loop control: last

§

Redo

Loop control: redo

§

Goto

Goto statement: goto LABEL, goto &sub, goto EXPR

§

Class

Class declaration (5.38+): class Foo

§

Method

Method declaration (5.38+): method foo

§

Field

Class field declaration (5.38+): field $name

§

Format

Format declaration: format STDOUT =

§

Undef

Undefined value: undef

§

Assign

Assignment: =

§

Plus

Addition: +

§

Minus

Subtraction: -

§

Star

Multiplication: *

§

Slash

Division: /

§

Percent

Modulo: %

§

Power

Exponentiation: **

§

LeftShift

Left bit shift: <<

§

RightShift

Right bit shift: >>

§

BitwiseAnd

Bitwise AND: &

§

BitwiseOr

Bitwise OR: |

§

BitwiseXor

Bitwise XOR: ^

§

BitwiseNot

Bitwise NOT: ~

§

PlusAssign

Add and assign: +=

§

MinusAssign

Subtract and assign: -=

§

StarAssign

Multiply and assign: *=

§

SlashAssign

Divide and assign: /=

§

PercentAssign

Modulo and assign: %=

§

DotAssign

Concatenate and assign: .=

§

AndAssign

Bitwise AND and assign: &=

§

OrAssign

Bitwise OR and assign: |=

§

XorAssign

Bitwise XOR and assign: ^=

§

PowerAssign

Power and assign: **=

§

LeftShiftAssign

Left shift and assign: <<=

§

RightShiftAssign

Right shift and assign: >>=

§

LogicalAndAssign

Logical AND and assign: &&=

§

LogicalOrAssign

Logical OR and assign: ||=

§

DefinedOrAssign

Defined-or and assign: //=

§

Equal

Numeric equality: ==

§

NotEqual

Numeric inequality: !=

§

Match

Pattern match binding: =~

§

NotMatch

Negated pattern match: !~

§

SmartMatch

Smart match: ~~

§

Less

Less than: <

§

Greater

Greater than: >

§

LessEqual

Less than or equal: <=

§

GreaterEqual

Greater than or equal: >=

§

Spaceship

Numeric comparison (spaceship): <=>

§

StringCompare

String comparison: cmp

§

And

Logical AND: &&

§

Or

Logical OR: ||

§

Not

Logical NOT: !

§

DefinedOr

Defined-or: //

§

WordAnd

Word AND operator: and

§

WordOr

Word OR operator: or

§

WordNot

Word NOT operator: not

§

WordXor

Word XOR operator: xor

§

Arrow

Method/dereference arrow: ->

§

FatArrow

Hash key separator: =>

§

Dot

String concatenation: .

§

Range

Range operator: ..

§

Ellipsis

Yada-yada (unimplemented): ...

§

Increment

Increment: ++

§

Decrement

Decrement: --

§

DoubleColon

Package separator: ::

§

Question

Ternary condition: ?

§

Colon

Ternary/label separator: :

§

Backslash

Reference operator: \

§

LeftParen

Left parenthesis: (

§

RightParen

Right parenthesis: )

§

LeftBrace

Left brace: {

§

RightBrace

Right brace: }

§

LeftBracket

Left bracket: [

§

RightBracket

Right bracket: ]

§

Semicolon

Statement terminator: ;

§

Comma

List separator: ,

§

Number

Numeric literal: 42, 3.14, 0xFF

§

String

String literal: "hello" or 'world'

§

Regex

Regular expression: /pattern/flags

§

Substitution

Substitution: s/pattern/replacement/flags

§

Transliteration

Transliteration: tr/abc/xyz/ or y///

§

QuoteSingle

Single-quoted string: q/text/

§

QuoteDouble

Double-quoted string: qq/text/

§

QuoteWords

Quote words: qw(list of words)

§

QuoteCommand

Backtick command: `cmd` or qx/cmd/

§

HeredocStart

Heredoc start marker: <<EOF

§

HeredocBody

Heredoc content body

§

FormatBody

Format specification body

§

DataMarker

Data section marker: __DATA__ or __END__

§

DataBody

Data section content

§

VString

Version string literal: v5.26.0, v5.10

§

UnknownRest

Unparsed remainder (budget exceeded)

§

HeredocDepthLimit

Heredoc depth limit exceeded (special error token)

§

Identifier

Bareword identifier or function name

§

ScalarSigil

Scalar sigil: $

§

ArraySigil

Array sigil: @

§

HashSigil

Hash sigil: %

§

SubSigil

Subroutine sigil: &

§

GlobSigil

Glob/typeglob sigil: *

§

Eof

End of file/input

§

Unknown

Unknown/unrecognized token

Implementations§

Source§

impl TokenKind

Source

pub fn display_name(self) -> &'static str

Return a user-friendly display name for this token kind.

These names appear in parser error messages shown in the editor. They use the actual Perl syntax (e.g. } instead of RightBrace) so users can immediately understand what the parser expected.

§Examples
use perl_token::TokenKind;

assert_eq!(TokenKind::Semicolon.display_name(), "';'");
assert_eq!(TokenKind::Sub.display_name(), "'sub'");
assert_eq!(TokenKind::Number.display_name(), "number");

Trait Implementations§

Source§

impl Clone for TokenKind

Source§

fn clone(&self) -> TokenKind

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TokenKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TokenKind

Source§

fn eq(&self, other: &TokenKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for TokenKind

Source§

impl Eq for TokenKind

Source§

impl StructuralPartialEq for TokenKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more