Skip to main content

Lexer

Struct 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 = 0

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

Source

pub const YYerror: i32 = 256

Token error, to be returned by the scanner.

Source

pub const YYUNDEF: i32 = 257

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

Source

pub const kCLASS: i32 = 258

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

Source

pub const kMODULE: i32 = 259

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

Source

pub const kDEF: i32 = 260

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

Source

pub const kUNDEF: i32 = 261

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

Source

pub const kBEGIN: i32 = 262

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

Source

pub const kRESCUE: i32 = 263

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

Source

pub const kENSURE: i32 = 264

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

Source

pub const kEND: i32 = 265

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

Source

pub const kIF: i32 = 266

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

Source

pub const kUNLESS: i32 = 267

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

Source

pub const kTHEN: i32 = 268

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

Source

pub const kELSIF: i32 = 269

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

Source

pub const kELSE: i32 = 270

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

Source

pub const kCASE: i32 = 271

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

Source

pub const kWHEN: i32 = 272

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

Source

pub const kWHILE: i32 = 273

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

Source

pub const kUNTIL: i32 = 274

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

Source

pub const kFOR: i32 = 275

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

Source

pub const kBREAK: i32 = 276

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

Source

pub const kNEXT: i32 = 277

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

Source

pub const kREDO: i32 = 278

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

Source

pub const kRETRY: i32 = 279

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

Source

pub const kIN: i32 = 280

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

Source

pub const kDO: i32 = 281

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

Source

pub const kDO_COND: i32 = 282

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

Source

pub const kDO_BLOCK: i32 = 283

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

Source

pub const kDO_LAMBDA: i32 = 284

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

Source

pub const kRETURN: i32 = 285

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

Source

pub const kYIELD: i32 = 286

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

Source

pub const kSUPER: i32 = 287

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

Source

pub const kSELF: i32 = 288

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

Source

pub const kNIL: i32 = 289

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

Source

pub const kTRUE: i32 = 290

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

Source

pub const kFALSE: i32 = 291

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

Source

pub const kAND: i32 = 292

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

Source

pub const kOR: i32 = 293

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

Source

pub const kNOT: i32 = 294

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

Source

pub const kIF_MOD: i32 = 295

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

Source

pub const kUNLESS_MOD: i32 = 296

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

Source

pub const kWHILE_MOD: i32 = 297

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

Source

pub const kUNTIL_MOD: i32 = 298

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

Source

pub const kRESCUE_MOD: i32 = 299

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

Source

pub const kALIAS: i32 = 300

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

Source

pub const kDEFINED: i32 = 301

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

Source

pub const klBEGIN: i32 = 302

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

Source

pub const klEND: i32 = 303

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

Source

pub const k__LINE__: i32 = 304

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

Source

pub const k__FILE__: i32 = 305

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

Source

pub const k__ENCODING__: i32 = 306

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

Source

pub const tIDENTIFIER: i32 = 307

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

Source

pub const tFID: i32 = 308

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

Source

pub const tGVAR: i32 = 309

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

Source

pub const tIVAR: i32 = 310

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

Source

pub const tCONSTANT: i32 = 311

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

Source

pub const tCVAR: i32 = 312

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

Source

pub const tLABEL: i32 = 313

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

Source

pub const tINTEGER: i32 = 314

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

Source

pub const tFLOAT: i32 = 315

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

Source

pub const tRATIONAL: i32 = 316

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

Source

pub const tIMAGINARY: i32 = 317

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

Source

pub const tCHAR: i32 = 318

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

Source

pub const tNTH_REF: i32 = 319

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

Source

pub const tBACK_REF: i32 = 320

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

Source

pub const tSTRING_CONTENT: i32 = 321

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

Source

pub const tREGEXP_END: i32 = 322

Token tREGEXP_END, to be returned by the scanner.

Source

pub const tDOT: i32 = 323

Token tDOT, to be returned by the scanner.

Source

pub const tBACKSLASH: i32 = 324

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

Source

pub const tSP: i32 = 325

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

Source

pub const tSLASH_T: i32 = 326

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

Source

pub const tSLASH_F: i32 = 327

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

Source

pub const tSLASH_R: i32 = 328

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

Source

pub const tVTAB: i32 = 329

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

Source

pub const tUPLUS: i32 = 330

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

Source

pub const tUMINUS: i32 = 331

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

Source

pub const tPOW: i32 = 332

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

Source

pub const tCMP: i32 = 333

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

Source

pub const tEQ: i32 = 334

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

Source

pub const tEQQ: i32 = 335

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

Source

pub const tNEQ: i32 = 336

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

Source

pub const tGEQ: i32 = 337

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

Source

pub const tLEQ: i32 = 338

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

Source

pub const tANDOP: i32 = 339

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

Source

pub const tOROP: i32 = 340

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

Source

pub const tMATCH: i32 = 341

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

Source

pub const tNMATCH: i32 = 342

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

Source

pub const tDOT2: i32 = 343

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

Source

pub const tDOT3: i32 = 344

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

Source

pub const tBDOT2: i32 = 345

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

Source

pub const tBDOT3: i32 = 346

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

Source

pub const tAREF: i32 = 347

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

Source

pub const tASET: i32 = 348

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

Source

pub const tLSHFT: i32 = 349

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

Source

pub const tRSHFT: i32 = 350

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

Source

pub const tANDDOT: i32 = 351

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

Source

pub const tCOLON2: i32 = 352

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

Source

pub const tCOLON3: i32 = 353

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

Source

pub const tOP_ASGN: i32 = 354

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

Source

pub const tASSOC: i32 = 355

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

Source

pub const tLPAREN: i32 = 356

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

Source

pub const tLPAREN_ARG: i32 = 357

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

Source

pub const tRPAREN: i32 = 358

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

Source

pub const tLBRACK: i32 = 359

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

Source

pub const tLBRACE: i32 = 360

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

Source

pub const tLBRACE_ARG: i32 = 361

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

Source

pub const tSTAR: i32 = 362

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

Source

pub const tDSTAR: i32 = 363

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

Source

pub const tAMPER: i32 = 364

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

Source

pub const tLAMBDA: i32 = 365

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

Source

pub const tSYMBEG: i32 = 366

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

Source

pub const tSTRING_BEG: i32 = 367

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

Source

pub const tXSTRING_BEG: i32 = 368

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

Source

pub const tREGEXP_BEG: i32 = 369

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

Source

pub const tWORDS_BEG: i32 = 370

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

Source

pub const tQWORDS_BEG: i32 = 371

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

Source

pub const tSYMBOLS_BEG: i32 = 372

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

Source

pub const tQSYMBOLS_BEG: i32 = 373

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

Source

pub const tSTRING_END: i32 = 374

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

Source

pub const tSTRING_DEND: i32 = 375

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

Source

pub const tSTRING_DBEG: i32 = 376

Token tSTRING_DBEG, to be returned by the scanner.

Source

pub const tSTRING_DVAR: i32 = 377

Token tSTRING_DVAR, to be returned by the scanner.

Source

pub const tLAMBEG: i32 = 378

Token tLAMBEG, to be returned by the scanner.

Source

pub const tLABEL_END: i32 = 379

Token tLABEL_END, to be returned by the scanner.

Source

pub const tCOMMA: i32 = 380

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

Source

pub const tLCURLY: i32 = 381

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

Source

pub const tRCURLY: i32 = 382

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

Source

pub const tLBRACK2: i32 = 383

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

Source

pub const tEQL: i32 = 384

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

Source

pub const tPIPE: i32 = 385

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

Source

pub const tAMPER2: i32 = 386

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

Source

pub const tGT: i32 = 387

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

Source

pub const tLT: i32 = 388

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

Source

pub const tBACK_REF2: i32 = 389

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

Source

pub const tCARET: i32 = 390

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

Source

pub const tLPAREN2: i32 = 391

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

Source

pub const tRBRACK: i32 = 392

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

Source

pub const tSEMI: i32 = 393

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

Source

pub const tSPACE: i32 = 394

Token " ", to be returned by the scanner.

Source

pub const tNL: i32 = 395

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

Source

pub const tPLUS: i32 = 396

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

Source

pub const tMINUS: i32 = 397

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

Source

pub const tSTAR2: i32 = 398

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

Source

pub const tDIVIDE: i32 = 399

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

Source

pub const tPERCENT: i32 = 400

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

Source

pub const tTILDE: i32 = 401

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

Source

pub const tBANG: i32 = 402

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

Source

pub const tLOWEST: i32 = 403

Token tLOWEST, to be returned by the scanner.

Source

pub const tEH: i32 = 404

Token tEH, to be returned by the scanner.

Source

pub const tCOLON: i32 = 405

Token tCOLON, to be returned by the scanner.

Source

pub const tUMINUS_NUM: i32 = 406

Token tUMINUS_NUM, to be returned by the scanner.

Source

pub const tLAST_TOKEN: i32 = 407

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 !RefUnwindSafe for Lexer

§

impl !Send for Lexer

§

impl !Sync for Lexer

§

impl !UnwindSafe for Lexer

§

impl Freeze for Lexer

§

impl Unpin for Lexer

§

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

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.