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 355)
351fn main() -> Result<()> {
352    println!("=== Nautilus Schema Visitor Pattern Demo ===\n");
353
354    // Parse the schema
355    let mut lexer = Lexer::new(SCHEMA);
356    let mut tokens = Vec::new();
357    loop {
358        let token = lexer.next_token()?;
359        if matches!(token.kind, nautilus_schema::TokenKind::Eof) {
360            tokens.push(token);
361            break;
362        }
363        tokens.push(token);
364    }
365    let schema = Parser::new(&tokens, SCHEMA).parse_schema()?;
366
367    println!(
368        "Parsed schema with {} declarations\n",
369        schema.declarations.len()
370    );
371    let separator = "=".repeat(60);
372    println!("{}", separator);
373
374    // Visitor 1: Collect statistics
375    println!("\n1️⃣  Schema Statistics\n");
376    let mut stats = SchemaStats::default();
377    stats.visit_schema(&schema)?;
378    println!("{:#?}", stats);
379
380    println!("\n{}", separator);
381
382    // Visitor 2: Build relationship graph
383    println!("\n2️⃣  Relationship Analysis\n");
384    let mut graph = RelationshipGraph::default();
385    graph.visit_schema(&schema)?;
386    graph.print();
387
388    println!("\n{}", separator);
389
390    // Visitor 3: Find default values
391    println!("\n3️⃣  Default Values\n");
392    let mut defaults = DefaultValueCollector::default();
393    defaults.visit_schema(&schema)?;
394    for (field, default) in &defaults.defaults {
395        println!("  {} = {}", field, default);
396    }
397
398    println!("\n{}", separator);
399
400    // Visitor 4: Validate naming conventions
401    println!("\n4️⃣  Naming Convention Validation\n");
402    let mut validator = NamingValidator::new();
403    validator.visit_schema(&schema)?;
404    if validator.errors.is_empty() {
405        println!("  ✅ All names follow conventions!");
406    } else {
407        println!("  ⚠️  Found {} naming issues:", validator.errors.len());
408        for error in &validator.errors {
409            println!("    - {}", error);
410        }
411    }
412
413    println!("\n{}", separator);
414
415    // Visitor 5: Determine migration order
416    println!("\n5️⃣  Migration Planning\n");
417    let mut orderer = MigrationOrderer::default();
418    orderer.visit_schema(&schema)?;
419    orderer.print();
420
421    println!("\n{}", separator);
422    println!("\n✅ Visitor demo completed successfully!");
423
424    Ok(())
425}
Source

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

Get the next token.

Examples found in repository?
examples/visitor_demo.rs (line 358)
351fn main() -> Result<()> {
352    println!("=== Nautilus Schema Visitor Pattern Demo ===\n");
353
354    // Parse the schema
355    let mut lexer = Lexer::new(SCHEMA);
356    let mut tokens = Vec::new();
357    loop {
358        let token = lexer.next_token()?;
359        if matches!(token.kind, nautilus_schema::TokenKind::Eof) {
360            tokens.push(token);
361            break;
362        }
363        tokens.push(token);
364    }
365    let schema = Parser::new(&tokens, SCHEMA).parse_schema()?;
366
367    println!(
368        "Parsed schema with {} declarations\n",
369        schema.declarations.len()
370    );
371    let separator = "=".repeat(60);
372    println!("{}", separator);
373
374    // Visitor 1: Collect statistics
375    println!("\n1️⃣  Schema Statistics\n");
376    let mut stats = SchemaStats::default();
377    stats.visit_schema(&schema)?;
378    println!("{:#?}", stats);
379
380    println!("\n{}", separator);
381
382    // Visitor 2: Build relationship graph
383    println!("\n2️⃣  Relationship Analysis\n");
384    let mut graph = RelationshipGraph::default();
385    graph.visit_schema(&schema)?;
386    graph.print();
387
388    println!("\n{}", separator);
389
390    // Visitor 3: Find default values
391    println!("\n3️⃣  Default Values\n");
392    let mut defaults = DefaultValueCollector::default();
393    defaults.visit_schema(&schema)?;
394    for (field, default) in &defaults.defaults {
395        println!("  {} = {}", field, default);
396    }
397
398    println!("\n{}", separator);
399
400    // Visitor 4: Validate naming conventions
401    println!("\n4️⃣  Naming Convention Validation\n");
402    let mut validator = NamingValidator::new();
403    validator.visit_schema(&schema)?;
404    if validator.errors.is_empty() {
405        println!("  ✅ All names follow conventions!");
406    } else {
407        println!("  ⚠️  Found {} naming issues:", validator.errors.len());
408        for error in &validator.errors {
409            println!("    - {}", error);
410        }
411    }
412
413    println!("\n{}", separator);
414
415    // Visitor 5: Determine migration order
416    println!("\n5️⃣  Migration Planning\n");
417    let mut orderer = MigrationOrderer::default();
418    orderer.visit_schema(&schema)?;
419    orderer.print();
420
421    println!("\n{}", separator);
422    println!("\n✅ Visitor demo completed successfully!");
423
424    Ok(())
425}

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.