1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! A Lua 5.3 parser crate.
//!
//! To get started:
//!
//! ```rust
//! use luaparse::{parse, HasSpan};
//! use luaparse::error::Error;
//!
//! let buf = r#"
//! local a = 42
//! local b = 24
//!
//! for i = 1, 100, 1 do
//!   b = a - b + i
//! end
//!
//! print(b)
//! "#;
//!
//! match parse(buf) {
//!     Ok(block) => println!("{}", block),
//!     Err(e) => eprintln!("{:#}", Error::new(e.span(), e).with_buffer(buf)),
//! }
//! ```

#![warn(future_incompatible, rust_2018_idioms, unused)]

pub mod ast;
pub mod error;
pub mod token;

mod cursor;
mod lexer;
mod parser;
mod span;
mod visitor;
mod printer;
mod symbol;

pub use crate::cursor::InputCursor;
pub use crate::lexer::{LexerErrorKind, LexerError, Lexer};
pub use crate::parser::{ParseError, Parser};
pub use crate::span::{HasSpan, Span, Position};
pub use crate::visitor::{AstDescend, VisitorMut};

/// Parses the input as a Lua chunk.
pub fn parse(buf: &str) -> Result<crate::ast::Block<'_>, ParseError<'_>> {
    Parser::new(Lexer::new(InputCursor::new(buf))).chunk()
}