forked from trinitrix/core
1
0
Fork 0

feat(trixy-lang_parser): Provide an api

This commit is contained in:
Benedikt Peetz 2023-12-22 20:39:02 +01:00
parent 70c4cc6f18
commit 26e0bbb972
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
6 changed files with 14 additions and 53 deletions

View File

@ -50,7 +50,7 @@ pub enum Declaration {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub enum Attribute {
#[allow(non_camel_case_types)]
doc{content: String, span: TokenSpan},
doc { content: String, span: TokenSpan },
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]

View File

@ -2,12 +2,17 @@ use core::fmt;
use thiserror::Error;
use crate::lexing::{error::SpannedLexingError, TokenSpan};
use crate::{
lexing::{error::SpannedLexingError, TokenSpan},
parsing::checked::error::SpannedParsingError,
};
#[derive(Error, Debug)]
pub enum TrixyError {
#[error(transparent)]
Parsing(#[from] SpannedLexingError),
Lexing(#[from] SpannedLexingError),
#[error(transparent)]
Parsing(#[from] SpannedParsingError),
}
/// The context of an Error.

View File

@ -2,7 +2,7 @@ use error::TrixyError;
use crate::lexing::TokenStream;
use self::command_spec::unchecked::CommandSpec;
use self::command_spec::checked::CommandSpec;
mod command_spec;
pub mod error;
@ -10,50 +10,6 @@ pub mod lexing;
pub mod parsing;
pub fn parse_trixy_lang(input: &str) -> Result<CommandSpec, TrixyError> {
let input_tokens = TokenStream::lex(input)?;
todo!()
let input_tokens = TokenStream::lex(input)?.parse()?;
Ok(input_tokens)
}
// #[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);
// }
// }

View File

@ -105,6 +105,6 @@ pub fn main() {
}
};
println!("{:#?}", processed);
},
}
}
}

View File

@ -19,7 +19,7 @@ use crate::{
use self::error::{ParsingError, SpannedParsingError};
mod error;
pub mod error;
#[cfg(test)]
mod test;

View File

@ -1,2 +1,2 @@
pub mod checked;
mod unchecked;
mod checked;