1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

add struct to ast

This commit is contained in:
schaeff 2019-07-26 17:54:20 +02:00
parent 2f7b26034a
commit 192f854b02

View file

@ -155,12 +155,31 @@ mod ast {
#[pest_ast(rule(Rule::file))] #[pest_ast(rule(Rule::file))]
pub struct File<'ast> { pub struct File<'ast> {
pub imports: Vec<ImportDirective<'ast>>, pub imports: Vec<ImportDirective<'ast>>,
pub structs: Vec<StructDefinition<'ast>>,
pub functions: Vec<Function<'ast>>, pub functions: Vec<Function<'ast>>,
pub eoi: EOI, pub eoi: EOI,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
#[derive(Debug, FromPest, PartialEq, Clone)]
#[pest_ast(rule(Rule::ty_struct_definition))]
pub struct StructDefinition<'ast> {
pub id: IdentifierExpression<'ast>,
pub fields: Vec<StructField<'ast>>,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Debug, FromPest, PartialEq, Clone)]
#[pest_ast(rule(Rule::struct_field))]
pub struct StructField<'ast> {
pub id: IdentifierExpression<'ast>,
pub ty: Type<'ast>,
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Debug, FromPest, PartialEq, Clone)] #[derive(Debug, FromPest, PartialEq, Clone)]
#[pest_ast(rule(Rule::function_definition))] #[pest_ast(rule(Rule::function_definition))]
pub struct Function<'ast> { pub struct Function<'ast> {
@ -195,6 +214,7 @@ mod ast {
pub enum Type<'ast> { pub enum Type<'ast> {
Basic(BasicType<'ast>), Basic(BasicType<'ast>),
Array(ArrayType<'ast>), Array(ArrayType<'ast>),
Struct(StructType<'ast>),
} }
#[derive(Debug, FromPest, PartialEq, Clone)] #[derive(Debug, FromPest, PartialEq, Clone)]
@ -219,7 +239,15 @@ mod ast {
#[derive(Debug, FromPest, PartialEq, Clone)] #[derive(Debug, FromPest, PartialEq, Clone)]
#[pest_ast(rule(Rule::ty_bool))] #[pest_ast(rule(Rule::ty_bool))]
pub struct StructType<'ast> {
#[pest_ast(outer())]
pub span: Span<'ast>,
}
#[derive(Debug, FromPest, PartialEq, Clone)]
#[pest_ast(rule(Rule::ty_struct))]
pub struct BooleanType<'ast> { pub struct BooleanType<'ast> {
id: IdentifierExpression<'ast>,
#[pest_ast(outer())] #[pest_ast(outer())]
pub span: Span<'ast>, pub span: Span<'ast>,
} }
@ -700,6 +728,7 @@ mod tests {
assert_eq!( assert_eq!(
generate_ast(&source), generate_ast(&source),
Ok(File { Ok(File {
structs: vec![],
functions: vec![Function { functions: vec![Function {
id: IdentifierExpression { id: IdentifierExpression {
value: String::from("main"), value: String::from("main"),
@ -749,6 +778,7 @@ mod tests {
assert_eq!( assert_eq!(
generate_ast(&source), generate_ast(&source),
Ok(File { Ok(File {
structs: vec![],
functions: vec![Function { functions: vec![Function {
id: IdentifierExpression { id: IdentifierExpression {
value: String::from("main"), value: String::from("main"),
@ -816,6 +846,7 @@ mod tests {
assert_eq!( assert_eq!(
generate_ast(&source), generate_ast(&source),
Ok(File { Ok(File {
structs: vec![],
functions: vec![Function { functions: vec![Function {
id: IdentifierExpression { id: IdentifierExpression {
value: String::from("main"), value: String::from("main"),
@ -870,6 +901,7 @@ mod tests {
assert_eq!( assert_eq!(
generate_ast(&source), generate_ast(&source),
Ok(File { Ok(File {
structs: vec![],
functions: vec![Function { functions: vec![Function {
id: IdentifierExpression { id: IdentifierExpression {
value: String::from("main"), value: String::from("main"),
@ -902,6 +934,7 @@ mod tests {
assert_eq!( assert_eq!(
generate_ast(&source), generate_ast(&source),
Ok(File { Ok(File {
structs: vec![],
functions: vec![Function { functions: vec![Function {
id: IdentifierExpression { id: IdentifierExpression {
value: String::from("main"), value: String::from("main"),