Wire functions through everything, with some unimplemented, and add a basic scoped map.

This commit is contained in:
2023-10-07 11:06:28 +02:00
parent eba5227ebc
commit 736d27953f
18 changed files with 392 additions and 97 deletions

View File

@@ -8,7 +8,7 @@
//!
//! * Turning the string into a series of language-specific [`Token`]s.
//! * Taking those tokens, and computing a basic syntax tree from them,
//! using our parser ([`ProgramParser`] or [`StatementParser`], generated
//! using our parser ([`ProgramParser`] or [`TopLevelParser`], generated
//! by [`lalrpop`](https://lalrpop.github.io/lalrpop/)).
//! * Validating the tree we have parsed, using [`Program::validate`],
//! returning any warnings or errors we have found.
@@ -44,7 +44,7 @@ mod validate;
use crate::syntax::arbitrary::GenerationEnvironment;
pub use crate::syntax::ast::*;
pub use crate::syntax::location::Location;
pub use crate::syntax::parser::{ProgramParser, StatementParser};
pub use crate::syntax::parser::{ProgramParser, TopLevelParser};
pub use crate::syntax::tokens::{LexerError, Token};
#[cfg(test)]
use ::pretty::{Arena, Pretty};
@@ -243,18 +243,18 @@ impl Program {
}
}
impl Statement {
/// Parse a statement that you have in memory, using the given index for [`Location`]s.
impl TopLevel {
/// Parse a top-level item that you have in memory, using the given index for [`Location`]s.
///
/// As with [`Program::parse`], if you use a bad file index, you'll get weird behaviors
/// when you try to print errors, but things should otherwise work fine. This function
/// will only parse a single statement, which is useful in the REPL, but probably shouldn't
/// be used when reading in whole files.
pub fn parse(file_idx: usize, buffer: &str) -> Result<Statement, ParserError> {
pub fn parse(file_idx: usize, buffer: &str) -> Result<TopLevel, ParserError> {
let lexer = Token::lexer(buffer)
.spanned()
.map(|(token, range)| (range.start, token, range.end));
StatementParser::new()
TopLevelParser::new()
.parse(file_idx, lexer)
.map_err(|e| ParserError::convert(file_idx, e))
}
@@ -276,7 +276,7 @@ fn order_of_operations() {
assert_eq!(
Program::from_str(muladd1).unwrap(),
Program {
statements: vec![Statement::Binding(
items: vec![TopLevel::Statement(Statement::Binding(
Location::new(testfile, 0..1),
Name::manufactured("x"),
Expression::Primitive(
@@ -303,7 +303,7 @@ fn order_of_operations() {
)
]
)
),],
))],
}
);
}