1mod expectation;
4mod id;
5mod lexer;
6mod parse;
7mod parser;
8mod peek;
9mod resolve;
10mod traits;
11
12use unicode_ident::{is_xid_continue, is_xid_start};
13
14pub use self::expectation::Expectation;
15pub(crate) use self::expectation::IntoExpectation;
16pub(crate) use self::id::NonZeroId;
17pub(crate) use self::lexer::{Lexer, LexerMode};
18pub use self::parse::Parse;
19pub use self::parser::{Parser, Peeker};
20pub use self::peek::Peek;
21pub(crate) use self::resolve::{Resolve, ResolveContext};
22pub(crate) use self::traits::Advance;
23
24use crate::compile;
25use crate::SourceId;
26
27pub fn parse_all<T>(source: &str, source_id: SourceId, shebang: bool) -> compile::Result<T>
34where
35 T: Parse,
36{
37 let mut parser = Parser::new(source, source_id, shebang);
38 let ast = parser.parse::<T>()?;
39 parser.eof()?;
40 Ok(ast)
41}
42
43pub(crate) fn is_ident(ident: &str) -> bool {
45 let mut chars = ident.chars();
46
47 let Some(c) = chars.next() else {
48 return false;
49 };
50
51 if !(c == '_' || is_xid_start(c)) {
52 return false;
53 }
54
55 for c in chars {
56 if !is_xid_continue(c) {
57 return false;
58 }
59 }
60
61 true
62}