Skip to main content

Lexer

Struct Lexer 

Source
pub struct Lexer<'a> { /* private fields */ }
Expand description

Lexer for tokenizing schema source code.

Implementations§

Source§

impl<'a> Lexer<'a>

Source

pub fn new(source: &'a str) -> Self

Create a new lexer for the given source.

Examples found in repository?
examples/visitor_demo.rs (line 342)
339fn main() -> Result<()> {
340    println!("=== Nautilus Schema Visitor Pattern Demo ===\n");
341
342    let mut lexer = Lexer::new(SCHEMA);
343    let mut tokens = Vec::new();
344    loop {
345        let token = lexer.next_token()?;
346        if matches!(token.kind, nautilus_schema::TokenKind::Eof) {
347            tokens.push(token);
348            break;
349        }
350        tokens.push(token);
351    }
352    let schema = Parser::new(&tokens, SCHEMA).parse_schema()?;
353
354    println!(
355        "Parsed schema with {} declarations\n",
356        schema.declarations.len()
357    );
358    let separator = "=".repeat(60);
359    println!("{}", separator);
360
361    println!("\n1️⃣  Schema Statistics\n");
362    let mut stats = SchemaStats::default();
363    stats.visit_schema(&schema)?;
364    println!("{:#?}", stats);
365
366    println!("\n{}", separator);
367
368    println!("\n2️⃣  Relationship Analysis\n");
369    let mut graph = RelationshipGraph::default();
370    graph.visit_schema(&schema)?;
371    graph.print();
372
373    println!("\n{}", separator);
374
375    println!("\n3️⃣  Default Values\n");
376    let mut defaults = DefaultValueCollector::default();
377    defaults.visit_schema(&schema)?;
378    for (field, default) in &defaults.defaults {
379        println!("  {} = {}", field, default);
380    }
381
382    println!("\n{}", separator);
383
384    println!("\n4️⃣  Naming Convention Validation\n");
385    let mut validator = NamingValidator::new();
386    validator.visit_schema(&schema)?;
387    if validator.errors.is_empty() {
388        println!("  ✅ All names follow conventions!");
389    } else {
390        println!("  ⚠️  Found {} naming issues:", validator.errors.len());
391        for error in &validator.errors {
392            println!("    - {}", error);
393        }
394    }
395
396    println!("\n{}", separator);
397
398    println!("\n5️⃣  Migration Planning\n");
399    let mut orderer = MigrationOrderer::default();
400    orderer.visit_schema(&schema)?;
401    orderer.print();
402
403    println!("\n{}", separator);
404    println!("\n✅ Visitor demo completed successfully!");
405
406    Ok(())
407}
Source

pub fn next_token(&mut self) -> Result<Token>

Get the next token.

Examples found in repository?
examples/visitor_demo.rs (line 345)
339fn main() -> Result<()> {
340    println!("=== Nautilus Schema Visitor Pattern Demo ===\n");
341
342    let mut lexer = Lexer::new(SCHEMA);
343    let mut tokens = Vec::new();
344    loop {
345        let token = lexer.next_token()?;
346        if matches!(token.kind, nautilus_schema::TokenKind::Eof) {
347            tokens.push(token);
348            break;
349        }
350        tokens.push(token);
351    }
352    let schema = Parser::new(&tokens, SCHEMA).parse_schema()?;
353
354    println!(
355        "Parsed schema with {} declarations\n",
356        schema.declarations.len()
357    );
358    let separator = "=".repeat(60);
359    println!("{}", separator);
360
361    println!("\n1️⃣  Schema Statistics\n");
362    let mut stats = SchemaStats::default();
363    stats.visit_schema(&schema)?;
364    println!("{:#?}", stats);
365
366    println!("\n{}", separator);
367
368    println!("\n2️⃣  Relationship Analysis\n");
369    let mut graph = RelationshipGraph::default();
370    graph.visit_schema(&schema)?;
371    graph.print();
372
373    println!("\n{}", separator);
374
375    println!("\n3️⃣  Default Values\n");
376    let mut defaults = DefaultValueCollector::default();
377    defaults.visit_schema(&schema)?;
378    for (field, default) in &defaults.defaults {
379        println!("  {} = {}", field, default);
380    }
381
382    println!("\n{}", separator);
383
384    println!("\n4️⃣  Naming Convention Validation\n");
385    let mut validator = NamingValidator::new();
386    validator.visit_schema(&schema)?;
387    if validator.errors.is_empty() {
388        println!("  ✅ All names follow conventions!");
389    } else {
390        println!("  ⚠️  Found {} naming issues:", validator.errors.len());
391        for error in &validator.errors {
392            println!("    - {}", error);
393        }
394    }
395
396    println!("\n{}", separator);
397
398    println!("\n5️⃣  Migration Planning\n");
399    let mut orderer = MigrationOrderer::default();
400    orderer.visit_schema(&schema)?;
401    orderer.print();
402
403    println!("\n{}", separator);
404    println!("\n✅ Visitor demo completed successfully!");
405
406    Ok(())
407}

Auto Trait Implementations§

§

impl<'a> Freeze for Lexer<'a>

§

impl<'a> RefUnwindSafe for Lexer<'a>

§

impl<'a> Send for Lexer<'a>

§

impl<'a> Sync for Lexer<'a>

§

impl<'a> Unpin for Lexer<'a>

§

impl<'a> UnsafeUnpin for Lexer<'a>

§

impl<'a> UnwindSafe for Lexer<'a>

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.