pub struct Lexer<'a> { /* private fields */ }Expand description
Lexer for tokenizing schema source code.
Implementations§
Source§impl<'a> Lexer<'a>
impl<'a> Lexer<'a>
Sourcepub fn new(source: &'a str) -> Self
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}Sourcepub fn next_token(&mut self) -> Result<Token>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more