feat(trixy-lang_parser): Provide an api
This commit is contained in:
parent
70c4cc6f18
commit
26e0bbb972
|
@ -2,12 +2,17 @@ use core::fmt;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::lexing::{error::SpannedLexingError, TokenSpan};
|
use crate::{
|
||||||
|
lexing::{error::SpannedLexingError, TokenSpan},
|
||||||
|
parsing::checked::error::SpannedParsingError,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum TrixyError {
|
pub enum TrixyError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Parsing(#[from] SpannedLexingError),
|
Lexing(#[from] SpannedLexingError),
|
||||||
|
#[error(transparent)]
|
||||||
|
Parsing(#[from] SpannedParsingError),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The context of an Error.
|
/// The context of an Error.
|
||||||
|
|
|
@ -2,7 +2,7 @@ use error::TrixyError;
|
||||||
|
|
||||||
use crate::lexing::TokenStream;
|
use crate::lexing::TokenStream;
|
||||||
|
|
||||||
use self::command_spec::unchecked::CommandSpec;
|
use self::command_spec::checked::CommandSpec;
|
||||||
|
|
||||||
mod command_spec;
|
mod command_spec;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
@ -10,50 +10,6 @@ pub mod lexing;
|
||||||
pub mod parsing;
|
pub mod parsing;
|
||||||
|
|
||||||
pub fn parse_trixy_lang(input: &str) -> Result<CommandSpec, TrixyError> {
|
pub fn parse_trixy_lang(input: &str) -> Result<CommandSpec, TrixyError> {
|
||||||
let input_tokens = TokenStream::lex(input)?;
|
let input_tokens = TokenStream::lex(input)?.parse()?;
|
||||||
|
Ok(input_tokens)
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[cfg(test)]
|
|
||||||
// mod test {
|
|
||||||
// use crate::{
|
|
||||||
// command_spec::unchecked::{CommandSpec, Declaration, Genus, Namespace},
|
|
||||||
// parse_trixy_lang,
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// #[test]
|
|
||||||
// fn test_function_with_namespace() {
|
|
||||||
// let expected = parse_trixy_lang(
|
|
||||||
// "
|
|
||||||
// nasp commands {
|
|
||||||
// fn say_something(name_to_greet: String, what_to_say: String) -> String;
|
|
||||||
// }
|
|
||||||
// ",
|
|
||||||
// )
|
|
||||||
// .unwrap();
|
|
||||||
// let correct: CommandSpec = {
|
|
||||||
// let declarations = vec![Declaration {
|
|
||||||
// namespace: vec![Namespace {
|
|
||||||
// name: "commands".to_owned(),
|
|
||||||
// }],
|
|
||||||
// genus: Genus::Function {
|
|
||||||
// name: "say_something".to_owned(),
|
|
||||||
// inputs: vec![
|
|
||||||
// NamedType {
|
|
||||||
// name: "name_to_greet".to_owned(),
|
|
||||||
// base: Type::String,
|
|
||||||
// },
|
|
||||||
// NamedType {
|
|
||||||
// name: "what_to_say".to_owned(),
|
|
||||||
// base: Type::String,
|
|
||||||
// },
|
|
||||||
// ],
|
|
||||||
// output: Type::String,
|
|
||||||
// },
|
|
||||||
// }];
|
|
||||||
// CommandSpec { declarations }
|
|
||||||
// };
|
|
||||||
// assert_eq!(expected, correct);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
|
@ -105,6 +105,6 @@ pub fn main() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
println!("{:#?}", processed);
|
println!("{:#?}", processed);
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::{
|
||||||
|
|
||||||
use self::error::{ParsingError, SpannedParsingError};
|
use self::error::{ParsingError, SpannedParsingError};
|
||||||
|
|
||||||
mod error;
|
pub mod error;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
|
pub mod checked;
|
||||||
mod unchecked;
|
mod unchecked;
|
||||||
mod checked;
|
|
||||||
|
|
Reference in New Issue