Struct lib_ruby_parser::Lexer

source ·
pub struct Lexer {
    pub lex_state: LexState,
    pub cond: StackState,
    pub cmdarg: StackState,
    pub static_env: StaticEnvironment,
    /* private fields */
}
Expand description

A struct responsible for converting a given input into a sequence of tokens

Fields§

§lex_state: LexState

Current state of the lexer, used internally for testing

§cond: StackState

Internal field, used to differentiate kDO_COND vs kDO, exposed for internal testing

§cmdarg: StackState

Internal field, used to differentiate kDO_BLOCK vs kDO, exposed for internal testing

§static_env: StaticEnvironment

Stack of sets of variables in current scopes. Each stack item represents locals in the scope.

You can use it to pre-define some locals and parse your input as if these locals exist.

For example, you can parse the following code

a = b + c

as

Send(LocalVar(a), "+", LocalVar(b))

by declaring a and b as locals using

parser.lexer.static_env.declare("a")
parser.lexer.static_env.declare("b")
parser.parse()

Implementations§

source§

impl Lexer

source

pub fn new<Bytes, Name>( bytes: Bytes, name: Name, decoder: Option<Decoder> ) -> Self
where Bytes: Into<Vec<u8>>, Name: Into<String>,

Constructs an instance of Lexer

source

pub fn tokenize_until_eof(&mut self) -> Vec<Token>

Tokenizes given input until EOF

Keep in mind that Lexer in Ruby is driven by Parser, and so this method on its own can return a wrong sequence of tokens. It’s used internally to test simple inputs.

If you need to get tokens better use ParserResult::tokens field

source§

impl Lexer

source

pub const END_OF_INPUT: i32 = 0i32

Token "end-of-input", to be returned by the scanner.

source

pub const YYerror: i32 = 256i32

Token error, to be returned by the scanner.

source

pub const YYUNDEF: i32 = 257i32

Token "invalid token", to be returned by the scanner.

source

pub const kCLASS: i32 = 258i32

Token "`class'", to be returned by the scanner.

source

pub const kMODULE: i32 = 259i32

Token "`module'", to be returned by the scanner.

source

pub const kDEF: i32 = 260i32

Token "`def'", to be returned by the scanner.

source

pub const kUNDEF: i32 = 261i32

Token "`undef'", to be returned by the scanner.

source

pub const kBEGIN: i32 = 262i32

Token "`begin'", to be returned by the scanner.

source

pub const kRESCUE: i32 = 263i32

Token "`rescue'", to be returned by the scanner.

source

pub const kENSURE: i32 = 264i32

Token "`ensure'", to be returned by the scanner.

source

pub const kEND: i32 = 265i32

Token "`end'", to be returned by the scanner.

source

pub const kIF: i32 = 266i32

Token "`if'", to be returned by the scanner.

source

pub const kUNLESS: i32 = 267i32

Token "`unless'", to be returned by the scanner.

source

pub const kTHEN: i32 = 268i32

Token "`then'", to be returned by the scanner.

source

pub const kELSIF: i32 = 269i32

Token "`elsif'", to be returned by the scanner.

source

pub const kELSE: i32 = 270i32

Token "`else'", to be returned by the scanner.

source

pub const kCASE: i32 = 271i32

Token "`case'", to be returned by the scanner.

source

pub const kWHEN: i32 = 272i32

Token "`when'", to be returned by the scanner.

source

pub const kWHILE: i32 = 273i32

Token "`while'", to be returned by the scanner.

source

pub const kUNTIL: i32 = 274i32

Token "`until'", to be returned by the scanner.

source

pub const kFOR: i32 = 275i32

Token "`for'", to be returned by the scanner.

source

pub const kBREAK: i32 = 276i32

Token "`break'", to be returned by the scanner.

source

pub const kNEXT: i32 = 277i32

Token "`next'", to be returned by the scanner.

source

pub const kREDO: i32 = 278i32

Token "`redo'", to be returned by the scanner.

source

pub const kRETRY: i32 = 279i32

Token "`retry'", to be returned by the scanner.

source

pub const kIN: i32 = 280i32

Token "`in'", to be returned by the scanner.

source

pub const kDO: i32 = 281i32

Token "`do'", to be returned by the scanner.

source

pub const kDO_COND: i32 = 282i32

Token "`do' for condition", to be returned by the scanner.

source

pub const kDO_BLOCK: i32 = 283i32

Token "`do' for block", to be returned by the scanner.

source

pub const kDO_LAMBDA: i32 = 284i32

Token "`do' for lambda", to be returned by the scanner.

source

pub const kRETURN: i32 = 285i32

Token "`return'", to be returned by the scanner.

source

pub const kYIELD: i32 = 286i32

Token "`yield'", to be returned by the scanner.

source

pub const kSUPER: i32 = 287i32

Token "`super'", to be returned by the scanner.

source

pub const kSELF: i32 = 288i32

Token "`self'", to be returned by the scanner.

source

pub const kNIL: i32 = 289i32

Token "`nil'", to be returned by the scanner.

source

pub const kTRUE: i32 = 290i32

Token "`true'", to be returned by the scanner.

source

pub const kFALSE: i32 = 291i32

Token "`false'", to be returned by the scanner.

source

pub const kAND: i32 = 292i32

Token "`and'", to be returned by the scanner.

source

pub const kOR: i32 = 293i32

Token "`or'", to be returned by the scanner.

source

pub const kNOT: i32 = 294i32

Token "`not'", to be returned by the scanner.

source

pub const kIF_MOD: i32 = 295i32

Token "`if' modifier", to be returned by the scanner.

source

pub const kUNLESS_MOD: i32 = 296i32

Token "`unless' modifier", to be returned by the scanner.

source

pub const kWHILE_MOD: i32 = 297i32

Token "`while' modifier", to be returned by the scanner.

source

pub const kUNTIL_MOD: i32 = 298i32

Token "`until' modifier", to be returned by the scanner.

source

pub const kRESCUE_MOD: i32 = 299i32

Token "`rescue' modifier", to be returned by the scanner.

source

pub const kALIAS: i32 = 300i32

Token "`alias'", to be returned by the scanner.

source

pub const kDEFINED: i32 = 301i32

Token "`defined?'", to be returned by the scanner.

source

pub const klBEGIN: i32 = 302i32

Token "`BEGIN'", to be returned by the scanner.

source

pub const klEND: i32 = 303i32

Token "`END'", to be returned by the scanner.

source

pub const k__LINE__: i32 = 304i32

Token "`__LINE__'", to be returned by the scanner.

source

pub const k__FILE__: i32 = 305i32

Token "`__FILE__'", to be returned by the scanner.

source

pub const k__ENCODING__: i32 = 306i32

Token "`__ENCODING__'", to be returned by the scanner.

source

pub const tIDENTIFIER: i32 = 307i32

Token "local variable or method", to be returned by the scanner.

source

pub const tFID: i32 = 308i32

Token "method", to be returned by the scanner.

source

pub const tGVAR: i32 = 309i32

Token "global variable", to be returned by the scanner.

source

pub const tIVAR: i32 = 310i32

Token "instance variable", to be returned by the scanner.

source

pub const tCONSTANT: i32 = 311i32

Token "constant", to be returned by the scanner.

source

pub const tCVAR: i32 = 312i32

Token "class variable", to be returned by the scanner.

source

pub const tLABEL: i32 = 313i32

Token "label", to be returned by the scanner.

source

pub const tINTEGER: i32 = 314i32

Token "integer literal", to be returned by the scanner.

source

pub const tFLOAT: i32 = 315i32

Token "float literal", to be returned by the scanner.

source

pub const tRATIONAL: i32 = 316i32

Token "rational literal", to be returned by the scanner.

source

pub const tIMAGINARY: i32 = 317i32

Token "imaginary literal", to be returned by the scanner.

source

pub const tCHAR: i32 = 318i32

Token "char literal", to be returned by the scanner.

source

pub const tNTH_REF: i32 = 319i32

Token "numbered reference", to be returned by the scanner.

source

pub const tBACK_REF: i32 = 320i32

Token "back reference", to be returned by the scanner.

source

pub const tSTRING_CONTENT: i32 = 321i32

Token "literal content", to be returned by the scanner.

source

pub const tREGEXP_END: i32 = 322i32

Token tREGEXP_END, to be returned by the scanner.

source

pub const tDOT: i32 = 323i32

Token tDOT, to be returned by the scanner.

source

pub const tBACKSLASH: i32 = 324i32

Token "backslash", to be returned by the scanner.

source

pub const tSP: i32 = 325i32

Token "escaped space", to be returned by the scanner.

source

pub const tSLASH_T: i32 = 326i32

Token "escaped horizontal tab", to be returned by the scanner.

source

pub const tSLASH_F: i32 = 327i32

Token "escaped form feed", to be returned by the scanner.

source

pub const tSLASH_R: i32 = 328i32

Token "escaped carriage return", to be returned by the scanner.

source

pub const tVTAB: i32 = 329i32

Token "escaped vertical tab", to be returned by the scanner.

source

pub const tUPLUS: i32 = 330i32

Token "unary+", to be returned by the scanner.

source

pub const tUMINUS: i32 = 331i32

Token "unary-", to be returned by the scanner.

source

pub const tPOW: i32 = 332i32

Token "**", to be returned by the scanner.

source

pub const tCMP: i32 = 333i32

Token "<=>", to be returned by the scanner.

source

pub const tEQ: i32 = 334i32

Token "==", to be returned by the scanner.

source

pub const tEQQ: i32 = 335i32

Token "===", to be returned by the scanner.

source

pub const tNEQ: i32 = 336i32

Token "!=", to be returned by the scanner.

source

pub const tGEQ: i32 = 337i32

Token ">=", to be returned by the scanner.

source

pub const tLEQ: i32 = 338i32

Token "<=", to be returned by the scanner.

source

pub const tANDOP: i32 = 339i32

Token "&&", to be returned by the scanner.

source

pub const tOROP: i32 = 340i32

Token "||", to be returned by the scanner.

source

pub const tMATCH: i32 = 341i32

Token "=~", to be returned by the scanner.

source

pub const tNMATCH: i32 = 342i32

Token "!~", to be returned by the scanner.

source

pub const tDOT2: i32 = 343i32

Token "..", to be returned by the scanner.

source

pub const tDOT3: i32 = 344i32

Token "...", to be returned by the scanner.

source

pub const tBDOT2: i32 = 345i32

Token "(..", to be returned by the scanner.

source

pub const tBDOT3: i32 = 346i32

Token "(...", to be returned by the scanner.

source

pub const tAREF: i32 = 347i32

Token "[]", to be returned by the scanner.

source

pub const tASET: i32 = 348i32

Token "[]=", to be returned by the scanner.

source

pub const tLSHFT: i32 = 349i32

Token "<<", to be returned by the scanner.

source

pub const tRSHFT: i32 = 350i32

Token ">>", to be returned by the scanner.

source

pub const tANDDOT: i32 = 351i32

Token "&.", to be returned by the scanner.

source

pub const tCOLON2: i32 = 352i32

Token "::", to be returned by the scanner.

source

pub const tCOLON3: i32 = 353i32

Token ":: at EXPR_BEG", to be returned by the scanner.

source

pub const tOP_ASGN: i32 = 354i32

Token "operator-assignment", to be returned by the scanner.

source

pub const tASSOC: i32 = 355i32

Token "=>", to be returned by the scanner.

source

pub const tLPAREN: i32 = 356i32

Token "(", to be returned by the scanner.

source

pub const tLPAREN_ARG: i32 = 357i32

Token "( arg", to be returned by the scanner.

source

pub const tRPAREN: i32 = 358i32

Token ")", to be returned by the scanner.

source

pub const tLBRACK: i32 = 359i32

Token "[", to be returned by the scanner.

source

pub const tLBRACE: i32 = 360i32

Token "{", to be returned by the scanner.

source

pub const tLBRACE_ARG: i32 = 361i32

Token "{ arg", to be returned by the scanner.

source

pub const tSTAR: i32 = 362i32

Token "*", to be returned by the scanner.

source

pub const tDSTAR: i32 = 363i32

Token "**arg", to be returned by the scanner.

source

pub const tAMPER: i32 = 364i32

Token "&", to be returned by the scanner.

source

pub const tLAMBDA: i32 = 365i32

Token "->", to be returned by the scanner.

source

pub const tSYMBEG: i32 = 366i32

Token "symbol literal", to be returned by the scanner.

source

pub const tSTRING_BEG: i32 = 367i32

Token "string begin", to be returned by the scanner.

source

pub const tXSTRING_BEG: i32 = 368i32

Token "backtick literal", to be returned by the scanner.

source

pub const tREGEXP_BEG: i32 = 369i32

Token "regexp literal", to be returned by the scanner.

source

pub const tWORDS_BEG: i32 = 370i32

Token "word list", to be returned by the scanner.

source

pub const tQWORDS_BEG: i32 = 371i32

Token "verbatim word list", to be returned by the scanner.

source

pub const tSYMBOLS_BEG: i32 = 372i32

Token "symbol list", to be returned by the scanner.

source

pub const tQSYMBOLS_BEG: i32 = 373i32

Token "verbatim symbol list", to be returned by the scanner.

source

pub const tSTRING_END: i32 = 374i32

Token "string end", to be returned by the scanner.

source

pub const tSTRING_DEND: i32 = 375i32

Token "tRCURLY", to be returned by the scanner.

source

pub const tSTRING_DBEG: i32 = 376i32

Token tSTRING_DBEG, to be returned by the scanner.

source

pub const tSTRING_DVAR: i32 = 377i32

Token tSTRING_DVAR, to be returned by the scanner.

source

pub const tLAMBEG: i32 = 378i32

Token tLAMBEG, to be returned by the scanner.

source

pub const tLABEL_END: i32 = 379i32

Token tLABEL_END, to be returned by the scanner.

source

pub const tCOMMA: i32 = 380i32

Token ",", to be returned by the scanner.

source

pub const tLCURLY: i32 = 381i32

Token "{ (tLCURLY)", to be returned by the scanner.

source

pub const tRCURLY: i32 = 382i32

Token "}", to be returned by the scanner.

source

pub const tLBRACK2: i32 = 383i32

Token "[ (tLBRACK2)", to be returned by the scanner.

source

pub const tEQL: i32 = 384i32

Token "=", to be returned by the scanner.

source

pub const tPIPE: i32 = 385i32

Token "|", to be returned by the scanner.

source

pub const tAMPER2: i32 = 386i32

Token "& (tAMPER2)", to be returned by the scanner.

source

pub const tGT: i32 = 387i32

Token ">", to be returned by the scanner.

source

pub const tLT: i32 = 388i32

Token "<", to be returned by the scanner.

source

pub const tBACK_REF2: i32 = 389i32

Token "`", to be returned by the scanner.

source

pub const tCARET: i32 = 390i32

Token "^", to be returned by the scanner.

source

pub const tLPAREN2: i32 = 391i32

Token "( (tLPAREN2)", to be returned by the scanner.

source

pub const tRBRACK: i32 = 392i32

Token "]", to be returned by the scanner.

source

pub const tSEMI: i32 = 393i32

Token ";", to be returned by the scanner.

source

pub const tSPACE: i32 = 394i32

Token " ", to be returned by the scanner.

source

pub const tNL: i32 = 395i32

Token "\n", to be returned by the scanner.

source

pub const tPLUS: i32 = 396i32

Token "+", to be returned by the scanner.

source

pub const tMINUS: i32 = 397i32

Token "-", to be returned by the scanner.

source

pub const tSTAR2: i32 = 398i32

Token "* (tSTAR2)", to be returned by the scanner.

source

pub const tDIVIDE: i32 = 399i32

Token "/", to be returned by the scanner.

source

pub const tPERCENT: i32 = 400i32

Token "%", to be returned by the scanner.

source

pub const tTILDE: i32 = 401i32

Token "~", to be returned by the scanner.

source

pub const tBANG: i32 = 402i32

Token "!", to be returned by the scanner.

source

pub const tLOWEST: i32 = 403i32

Token tLOWEST, to be returned by the scanner.

source

pub const tEH: i32 = 404i32

Token tEH, to be returned by the scanner.

source

pub const tCOLON: i32 = 405i32

Token tCOLON, to be returned by the scanner.

source

pub const tUMINUS_NUM: i32 = 406i32

Token tUMINUS_NUM, to be returned by the scanner.

source

pub const tLAST_TOKEN: i32 = 407i32

Token tLAST_TOKEN, to be returned by the scanner.

Trait Implementations§

source§

impl Debug for Lexer

source§

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

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

impl Default for Lexer

source§

fn default() -> Lexer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Lexer

§

impl !RefUnwindSafe for Lexer

§

impl !Send for Lexer

§

impl !Sync for Lexer

§

impl Unpin for Lexer

§

impl !UnwindSafe for Lexer

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.