Major refactoring of AST module: private properties and accessors, building clearer, using Boxes.
This commit is contained in:
		
							parent
							
								
									c8ff1d0fa2
								
							
						
					
					
						commit
						20dcb4f6ce
					
				
							
								
								
									
										980
									
								
								src/ast/build.rs
									
									
									
									
									
								
							
							
						
						
									
										980
									
								
								src/ast/build.rs
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										736
									
								
								src/ast/children.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										736
									
								
								src/ast/children.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,736 @@ | |||||||
|  | use crate::ast::*; | ||||||
|  | 
 | ||||||
|  | pub enum ChildRef<'a> { | ||||||
|  |     Identifier(&'a Identifier), | ||||||
|  |     FullyQualifiedName(&'a FullyQualifiedName), | ||||||
|  |     TypeUse(&'a TypeUse), | ||||||
|  |     PrimitiveTypeUse(&'a PrimitiveTypeUse), | ||||||
|  |     InterfaceOrClassTypeUse(&'a InterfaceOrClassTypeUse), | ||||||
|  |     TupleTypeUse(&'a TupleTypeUse), | ||||||
|  |     FunctionTypeUse(&'a FunctionTypeUse), | ||||||
|  |     GenericArguments(&'a GenericArguments), | ||||||
|  |     GenericParameters(&'a GenericParameters), | ||||||
|  |     TupleArguments(&'a TupleArguments), | ||||||
|  |     ImplementsList(&'a ImplementsList), | ||||||
|  |     Parameters(&'a Parameters), | ||||||
|  |     Parameter(&'a Parameter), | ||||||
|  |     ReturnType(&'a ReturnType), | ||||||
|  |     References(&'a References), | ||||||
|  |     UseStatement(&'a UseStatement), | ||||||
|  |     ModuleLevelDeclaration(&'a ModuleLevelDeclaration), | ||||||
|  |     InterfaceLevelDeclaration(&'a InterfaceLevelDeclaration), | ||||||
|  |     ClassLevelDeclaration(&'a ClassLevelDeclaration), | ||||||
|  |     FunctionBody(&'a FunctionBody), | ||||||
|  |     ClassConstructor(&'a ClassConstructor), | ||||||
|  |     ClassConstructorParameter(&'a ClassConstructorParameter), | ||||||
|  |     BlockStatement(&'a BlockStatement), | ||||||
|  |     Statement(&'a Statement), | ||||||
|  |     IfStatement(&'a IfStatement), | ||||||
|  |     ElseIfs(&'a ElseIfs), | ||||||
|  |     ElseBlock(&'a ElseBlock), | ||||||
|  |     Expression(&'a Expression), | ||||||
|  |     TurboFish(&'a TurboFish), | ||||||
|  |     CallArguments(&'a CallArguments), | ||||||
|  |     CallArgument(&'a CallArgument), | ||||||
|  |     ClosureCaptures(&'a ClosureCaptures), | ||||||
|  |     ClosureCapture(&'a ClosureCapture), | ||||||
|  |     ClosureParameters(&'a ClosureParameters), | ||||||
|  |     ClosureParameter(&'a ClosureParameter), | ||||||
|  |     ObjectNavigations(&'a ObjectNavigations), | ||||||
|  |     ObjectNavigation(&'a ObjectNavigation), | ||||||
|  |     DString(&'a DString), | ||||||
|  |     DStringPart(&'a DStringPart), | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | pub trait HasChildren { | ||||||
|  |     fn children(&self) -> Vec<ChildRef>; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for FullyQualifiedName { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.identifiers() | ||||||
|  |             .iter() | ||||||
|  |             .map(|id| ChildRef::Identifier(*id)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for TypeUse { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         match self { | ||||||
|  |             TypeUse::Primitive(primitive_type_use) => primitive_type_use.children(), | ||||||
|  |             TypeUse::InterfaceOrClass(interface_or_class_type_use) => { | ||||||
|  |                 interface_or_class_type_use.children() | ||||||
|  |             } | ||||||
|  |             TypeUse::Tuple(tuple_type_use) => tuple_type_use.children(), | ||||||
|  |             TypeUse::Function(function_type_use) => function_type_use.children(), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for PrimitiveTypeUse { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         match self { | ||||||
|  |             PrimitiveTypeUse::Array(generics) => { | ||||||
|  |                 if let Some(generics) = generics { | ||||||
|  |                     vec![ChildRef::GenericArguments(&generics)] | ||||||
|  |                 } else { | ||||||
|  |                     vec![] | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             _ => vec![], | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for InterfaceOrClassTypeUse { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.push(ChildRef::FullyQualifiedName(self.fqn())); | ||||||
|  |         children.push(ChildRef::GenericArguments(self.generics())); | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for TupleTypeUse { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ChildRef::TupleArguments(self.arguments())] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for FunctionTypeUse { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::GenericParameters(self.generics()), | ||||||
|  |             ChildRef::Parameters(self.parameters()), | ||||||
|  |             ChildRef::ReturnType(self.return_type()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for GenericArguments { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.arguments() | ||||||
|  |             .iter() | ||||||
|  |             .map(|type_use| ChildRef::TypeUse(*type_use)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for GenericParameters { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.identifiers() | ||||||
|  |             .iter() | ||||||
|  |             .map(|id| ChildRef::Identifier(*id)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for TupleArguments { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.arguments() | ||||||
|  |             .iter() | ||||||
|  |             .map(|type_use| ChildRef::TypeUse(*type_use)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ImplementsList { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.type_uses() | ||||||
|  |             .iter() | ||||||
|  |             .map(|type_use| ChildRef::TypeUse(*type_use)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for Parameters { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.parameters() | ||||||
|  |             .iter() | ||||||
|  |             .map(|parameter| ChildRef::Parameter(*parameter)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for Parameter { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::Identifier(self.identifier()), | ||||||
|  |             ChildRef::TypeUse(self.type_use()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ReturnType { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::TypeUse(self.declared_type()), | ||||||
|  |             ChildRef::References(self.references()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for CompilationUnit { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         if let Some(namespace) = self.namespace() { | ||||||
|  |             children.push(ChildRef::FullyQualifiedName(namespace)); | ||||||
|  |         } | ||||||
|  |         children.extend( | ||||||
|  |             self.use_statements() | ||||||
|  |                 .iter() | ||||||
|  |                 .map(|use_statement| ChildRef::UseStatement(*use_statement)), | ||||||
|  |         ); | ||||||
|  |         children.extend( | ||||||
|  |             self.declarations() | ||||||
|  |                 .iter() | ||||||
|  |                 .map(|declaration| ChildRef::ModuleLevelDeclaration(*declaration)), | ||||||
|  |         ); | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for UseStatement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.extend( | ||||||
|  |             self.identifiers() | ||||||
|  |                 .iter() | ||||||
|  |                 .map(|identifier| ChildRef::Identifier(*identifier)), | ||||||
|  |         ); | ||||||
|  |         match self.last() { | ||||||
|  |             UseStatementLast::Identifier(identifier) => { | ||||||
|  |                 children.push(ChildRef::Identifier(identifier)) | ||||||
|  |             } | ||||||
|  |             UseStatementLast::Identifiers(identifiers) => children.extend( | ||||||
|  |                 identifiers | ||||||
|  |                     .iter() | ||||||
|  |                     .map(|identifier| ChildRef::Identifier(identifier.clone())), | ||||||
|  |             ), | ||||||
|  |             UseStatementLast::Star => {} | ||||||
|  |         } | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ModuleLevelDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         use ModuleLevelDeclaration::*; | ||||||
|  |         match self { | ||||||
|  |             Module(module_declaration) => module_declaration.children(), | ||||||
|  |             Interface(interface_declaration) => interface_declaration.children(), | ||||||
|  |             Class(class_declaration) => class_declaration.children(), | ||||||
|  |             Function(function_definition) => function_definition.children(), | ||||||
|  |             PlatformFunction(platform_function_declaration) => { | ||||||
|  |                 platform_function_declaration.children() | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for InterfaceLevelDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         use InterfaceLevelDeclaration::*; | ||||||
|  |         match self { | ||||||
|  |             Module(module_declaration) => module_declaration.children(), | ||||||
|  |             Interface(interface_declaration) => interface_declaration.children(), | ||||||
|  |             Class(class_declaration) => class_declaration.children(), | ||||||
|  |             Function(function_declaration) => function_declaration.children(), | ||||||
|  |             OperatorFunction(operator_function_declaration) => { | ||||||
|  |                 operator_function_declaration.children() | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ClassLevelDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         use ClassLevelDeclaration::*; | ||||||
|  |         match self { | ||||||
|  |             Module(module_declaration) => module_declaration.children(), | ||||||
|  |             Interface(interface_declaration) => interface_declaration.children(), | ||||||
|  |             Class(class_declaration) => class_declaration.children(), | ||||||
|  |             Function(function_definition) => function_definition.children(), | ||||||
|  |             OperatorFunction(operator_function_definition) => { | ||||||
|  |                 operator_function_definition.children() | ||||||
|  |             } | ||||||
|  |             PlatformFunction(platform_function_declaration) => { | ||||||
|  |                 platform_function_declaration.children() | ||||||
|  |             } | ||||||
|  |             Property(property_declaration) => property_declaration.children(), | ||||||
|  |             Field(field_declaration) => field_declaration.children(), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ModuleDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.push(ChildRef::Identifier(self.identifier())); | ||||||
|  |         children.extend( | ||||||
|  |             self.declarations() | ||||||
|  |                 .iter() | ||||||
|  |                 .map(|declaration| ChildRef::ModuleLevelDeclaration(*declaration)), | ||||||
|  |         ); | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for InterfaceDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.push(ChildRef::Identifier(self.identifier())); | ||||||
|  |         children.push(ChildRef::GenericParameters(self.generics())); | ||||||
|  |         children.push(ChildRef::ImplementsList(self.implements())); | ||||||
|  |         children.extend( | ||||||
|  |             self.declarations() | ||||||
|  |                 .iter() | ||||||
|  |                 .map(|declaration| ChildRef::InterfaceLevelDeclaration(*declaration)), | ||||||
|  |         ); | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ClassDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.push(ChildRef::Identifier(self.identifier())); | ||||||
|  |         children.push(ChildRef::GenericParameters(self.generics())); | ||||||
|  |         if let Some(class_constructor) = self.class_constructor() { | ||||||
|  |             children.push(ChildRef::ClassConstructor(class_constructor)); | ||||||
|  |         } | ||||||
|  |         children.push(ChildRef::ImplementsList(self.implements())); | ||||||
|  |         children.extend( | ||||||
|  |             self.declarations() | ||||||
|  |                 .iter() | ||||||
|  |                 .map(|declaration| ChildRef::ClassLevelDeclaration(*declaration)), | ||||||
|  |         ); | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for FunctionDefinition { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::GenericParameters(self.generics()), | ||||||
|  |             ChildRef::Identifier(self.identifier()), | ||||||
|  |             ChildRef::Parameters(self.parameters()), | ||||||
|  |             ChildRef::ReturnType(self.return_type()), | ||||||
|  |             ChildRef::FunctionBody(self.body()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for OperatorFunctionDefinition { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::GenericParameters(self.generics()), | ||||||
|  |             ChildRef::Parameters(self.parameters()), | ||||||
|  |             ChildRef::ReturnType(self.return_type()), | ||||||
|  |             ChildRef::FunctionBody(self.body()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for PlatformFunctionDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::GenericParameters(self.generics()), | ||||||
|  |             ChildRef::Identifier(self.identifier()), | ||||||
|  |             ChildRef::Parameters(self.parameters()), | ||||||
|  |             ChildRef::ReturnType(self.return_type()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for InterfaceFunctionDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![ | ||||||
|  |             ChildRef::GenericParameters(self.generics()), | ||||||
|  |             ChildRef::Identifier(self.identifier()), | ||||||
|  |             ChildRef::Parameters(self.parameters()), | ||||||
|  |             ChildRef::ReturnType(self.return_type()), | ||||||
|  |         ]; | ||||||
|  |         if let Some(body) = self.body() { | ||||||
|  |             children.push(ChildRef::FunctionBody(body)) | ||||||
|  |         } | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for InterfaceOperatorFunctionDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![ | ||||||
|  |             ChildRef::GenericParameters(self.generics()), | ||||||
|  |             ChildRef::Parameters(self.parameters()), | ||||||
|  |             ChildRef::ReturnType(self.return_type()), | ||||||
|  |         ]; | ||||||
|  |         if let Some(body) = self.body() { | ||||||
|  |             children.push(ChildRef::FunctionBody(body)) | ||||||
|  |         } | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for FunctionBody { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         match self { | ||||||
|  |             Self::Equals(expression) => expression.children(), | ||||||
|  |             Self::Block(block_statement) => block_statement.children(), | ||||||
|  |             Self::Alias(identifier) => vec![ChildRef::Identifier(identifier.as_ref())], | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ClassConstructor { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.parameters() | ||||||
|  |             .iter() | ||||||
|  |             .map(|parameter| ChildRef::ClassConstructorParameter(*parameter)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ClassConstructorParameter { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         match self { | ||||||
|  |             Self::Property(property_declaration) => property_declaration.children(), | ||||||
|  |             Self::Field(field_declaration) => field_declaration.children(), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for PropertyDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::Identifier(self.identifier()), | ||||||
|  |             ChildRef::TypeUse(self.declared_type()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for FieldDeclaration { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::Identifier(self.identifier()), | ||||||
|  |             ChildRef::TypeUse(self.declared_type()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for BlockStatement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.extend( | ||||||
|  |             self.statements() | ||||||
|  |                 .iter() | ||||||
|  |                 .map(|statement| ChildRef::Statement(statement)), | ||||||
|  |         ); | ||||||
|  |         if let Some(expression) = self.expression() { | ||||||
|  |             children.push(ChildRef::Expression(expression)); | ||||||
|  |         } | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for Statement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         use Statement::*; | ||||||
|  |         match self { | ||||||
|  |             BlockStatement(block_statement) => block_statement.children(), | ||||||
|  |             VariableDeclarationStatement(variable_declaration_statement) => { | ||||||
|  |                 variable_declaration_statement.children() | ||||||
|  |             } | ||||||
|  |             AssignStatement(assign_statement) => assign_statement.children(), | ||||||
|  |             CallStatement(call_statement) => call_statement.children(), | ||||||
|  |             ReturnStatement(return_statement) => return_statement.children(), | ||||||
|  |             IfStatement(if_statement) => if_statement.children(), | ||||||
|  |             IfElseStatement(if_else_statement) => if_else_statement.children(), | ||||||
|  |             WhileStatement(while_statement) => while_statement.children(), | ||||||
|  |             ForStatement(for_statement) => for_statement.children(), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for VariableDeclarationStatement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.push(ChildRef::Identifier(self.identifier())); | ||||||
|  |         if let Some(declared_type) = self.declared_type() { | ||||||
|  |             children.push(ChildRef::TypeUse(declared_type)); | ||||||
|  |         } | ||||||
|  |         if let Some(initializer) = self.initializer() { | ||||||
|  |             children.push(ChildRef::Expression(initializer)); | ||||||
|  |         } | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for AssignStatement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::Expression(self.lhs()), | ||||||
|  |             ChildRef::Expression(self.rhs()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for CallStatement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ChildRef::Expression(self.expression())] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ReturnStatement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         if let Some(expression) = self.expression() { | ||||||
|  |             vec![ChildRef::Expression(expression)] | ||||||
|  |         } else { | ||||||
|  |             vec![] | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for IfStatement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::Expression(self.condition()), | ||||||
|  |             ChildRef::BlockStatement(self.then_block()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for IfElseStatement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.push(ChildRef::IfStatement(self.if_statement())); | ||||||
|  |         children.push(ChildRef::ElseIfs(self.else_ifs())); | ||||||
|  |         if let Some(else_block) = self.else_block() { | ||||||
|  |             children.push(ChildRef::ElseBlock(else_block)); | ||||||
|  |         } | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ElseIfs { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.if_statements() | ||||||
|  |             .iter() | ||||||
|  |             .map(|statement| ChildRef::IfStatement(statement)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ElseBlock { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ChildRef::BlockStatement(self.block_statement())] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for WhileStatement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::Expression(self.condition()), | ||||||
|  |             ChildRef::BlockStatement(self.body()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ForStatement { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::Identifier(self.variable()), | ||||||
|  |             ChildRef::Expression(self.iterator()), | ||||||
|  |             ChildRef::BlockStatement(self.body()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for Expression { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         use Expression::*; | ||||||
|  |         match self { | ||||||
|  |             Ternary(ternary) => ternary.children(), | ||||||
|  |             Binary(binary) => binary.children(), | ||||||
|  |             UnaryPrefix(prefix) => prefix.children(), | ||||||
|  |             UnarySuffix(suffix) => suffix.children(), | ||||||
|  |             Call(call) => call.children(), | ||||||
|  |             ObjectAccess(object_access) => object_access.children(), | ||||||
|  |             Literal(literal) => literal.children(), | ||||||
|  |             FullyQualifiedName(fully_qualified_name) => fully_qualified_name.children(), | ||||||
|  |             Closure(closure) => closure.children(), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for TernaryExpression { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::Expression(self.condition()), | ||||||
|  |             ChildRef::Expression(self.true_expression()), | ||||||
|  |             ChildRef::Expression(self.false_expression()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for BinaryExpression { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::Expression(self.left()), | ||||||
|  |             ChildRef::Expression(self.right()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for PrefixExpression { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ChildRef::Expression(self.expression())] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for SuffixExpression { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ChildRef::Expression(self.expression())] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for CallExpression { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.push(ChildRef::Expression(self.callee())); | ||||||
|  |         if let Some(turbo_fish) = self.turbo_fish() { | ||||||
|  |             children.push(ChildRef::TurboFish(turbo_fish)); | ||||||
|  |         } | ||||||
|  |         children.push(ChildRef::CallArguments(self.arguments())); | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for TurboFish { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ChildRef::GenericArguments(self.generics())] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for CallArguments { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.arguments() | ||||||
|  |             .iter() | ||||||
|  |             .map(|argument| ChildRef::CallArgument(*argument)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for CallArgument { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ChildRef::Expression(self.expression())] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for Closure { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.push(ChildRef::ClosureCaptures(self.captures())); | ||||||
|  |         children.push(ChildRef::ClosureParameters(self.parameters())); | ||||||
|  |         children.extend( | ||||||
|  |             self.statements() | ||||||
|  |                 .iter() | ||||||
|  |                 .map(|statement| ChildRef::Statement(statement)), | ||||||
|  |         ); | ||||||
|  |         if let Some(expression) = self.expression() { | ||||||
|  |             children.push(ChildRef::Expression(expression)); | ||||||
|  |         } | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ClosureCaptures { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.captures() | ||||||
|  |             .iter() | ||||||
|  |             .map(|capture| ChildRef::ClosureCapture(*capture)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ClosureCapture { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ChildRef::Identifier(self.identifier())] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ClosureParameters { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.parameters() | ||||||
|  |             .iter() | ||||||
|  |             .map(|parameter| ChildRef::ClosureParameter(*parameter)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ClosureParameter { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         let mut children = vec![]; | ||||||
|  |         children.push(ChildRef::Identifier(self.identifier())); | ||||||
|  |         if let Some(type_use) = self.type_use() { | ||||||
|  |             children.push(ChildRef::TypeUse(type_use)); | ||||||
|  |         } | ||||||
|  |         children | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ObjectAccess { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![ | ||||||
|  |             ChildRef::Expression(self.receiver()), | ||||||
|  |             ChildRef::ObjectNavigations(self.navigations()), | ||||||
|  |         ] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ObjectNavigations { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.navigations() | ||||||
|  |             .iter() | ||||||
|  |             .map(|navigation| ChildRef::ObjectNavigation(*navigation)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for ObjectNavigation { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         vec![match self { | ||||||
|  |             ObjectNavigation::Identifier(identifier) => ChildRef::Identifier(identifier), | ||||||
|  |             ObjectNavigation::Index(index_expression) => ChildRef::Expression(index_expression), | ||||||
|  |         }] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for Literal { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         match self { | ||||||
|  |             Literal::DString(d_string) => vec![ChildRef::DString(d_string)], | ||||||
|  |             Literal::BacktickString(d_string) => vec![ChildRef::DString(d_string)], | ||||||
|  |             _ => vec![], | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for DString { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         self.parts() | ||||||
|  |             .iter() | ||||||
|  |             .map(|part| ChildRef::DStringPart(*part)) | ||||||
|  |             .collect() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl HasChildren for DStringPart { | ||||||
|  |     fn children(&self) -> Vec<ChildRef> { | ||||||
|  |         match self { | ||||||
|  |             DStringPart::Expression(expression) => vec![ChildRef::Expression(expression)], | ||||||
|  |             _ => vec![], | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										2005
									
								
								src/ast/mod.rs
									
									
									
									
									
								
							
							
						
						
									
										2005
									
								
								src/ast/mod.rs
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -1,6 +1,7 @@ | |||||||
| use crate::ast::*; | use crate::ast::*; | ||||||
| use crate::util::indent_writer::IndentWriter; | use crate::util::indent_writer::IndentWriter; | ||||||
| use std::fmt::Debug; | use std::fmt::Debug; | ||||||
|  | use crate::ast::unparse::Unparse; | ||||||
| 
 | 
 | ||||||
| pub trait PrettyPrint { | pub trait PrettyPrint { | ||||||
|     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()>; |     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()>; | ||||||
| @ -20,24 +21,7 @@ impl PrettyPrint for Operator { | |||||||
| impl PrettyPrint for BinaryOperator { | impl PrettyPrint for BinaryOperator { | ||||||
|     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         writer.write_indented("BinaryOperator(")?; |         writer.write_indented("BinaryOperator(")?; | ||||||
|         use BinaryOperator::*; |         self.unparse(writer)?; | ||||||
|         match self { |  | ||||||
|             Or => writer.write("||"), |  | ||||||
|             And => writer.write("&&"), |  | ||||||
|             EqualTo => writer.write("=="), |  | ||||||
|             NotEqualTo => writer.write("!="), |  | ||||||
|             Greater => writer.write(">"), |  | ||||||
|             Less => writer.write("<"), |  | ||||||
|             GreaterEqual => writer.write(">="), |  | ||||||
|             LessEqual => writer.write("<="), |  | ||||||
|             Add => writer.write("+"), |  | ||||||
|             Subtract => writer.write("-"), |  | ||||||
|             Multiply => writer.write("*"), |  | ||||||
|             Divide => writer.write("/"), |  | ||||||
|             Modulo => writer.write("%"), |  | ||||||
|             LeftShift => writer.write("<<"), |  | ||||||
|             RightShift => writer.write(">>"), |  | ||||||
|         }?; |  | ||||||
|         writer.writeln(")")?; |         writer.writeln(")")?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| @ -46,15 +30,7 @@ impl PrettyPrint for BinaryOperator { | |||||||
| impl PrettyPrint for PrefixUnaryOperator { | impl PrettyPrint for PrefixUnaryOperator { | ||||||
|     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         writer.write_indented("PrefixUnaryOperator(")?; |         writer.write_indented("PrefixUnaryOperator(")?; | ||||||
|         use PrefixUnaryOperator::*; |         self.unparse(writer)?; | ||||||
|         match self { |  | ||||||
|             Spread => writer.write("..."), |  | ||||||
|             BorrowMut => writer.write("&mut"), |  | ||||||
|             Borrow => writer.write("&"), |  | ||||||
|             Mut => writer.write("mut"), |  | ||||||
|             Not => writer.write("!"), |  | ||||||
|             Negative => writer.write("-"), |  | ||||||
|         }?; |  | ||||||
|         writer.writeln(")")?; |         writer.writeln(")")?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| @ -63,11 +39,7 @@ impl PrettyPrint for PrefixUnaryOperator { | |||||||
| impl PrettyPrint for SuffixUnaryOperator { | impl PrettyPrint for SuffixUnaryOperator { | ||||||
|     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         writer.write_indented("SuffixUnaryOperator(")?; |         writer.write_indented("SuffixUnaryOperator(")?; | ||||||
|         use SuffixUnaryOperator::*; |         self.unparse(writer)?; | ||||||
|         match self { |  | ||||||
|             PlusPlus => writer.write("++"), |  | ||||||
|             MinusMinus => writer.write("--"), |  | ||||||
|         }?; |  | ||||||
|         writer.write(")")?; |         writer.write(")")?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| @ -95,20 +67,26 @@ impl PrettyPrint for TypeUse { | |||||||
|     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         use TypeUse::*; |         use TypeUse::*; | ||||||
|         match self { |         match self { | ||||||
|             Void => { |             Primitive(primitive_type_use) => { | ||||||
|                 writer.writeln_indented("TypeUse(Void)")?; |                 writer.writeln_indented("PrimitiveTypeUse")?; | ||||||
|  |                 writer.increase_indent(); | ||||||
|  |                 primitive_type_use.pretty_print(writer)?; | ||||||
|  |                 writer.decrease_indent() | ||||||
|             } |             } | ||||||
|             InterfaceOrClass(t) => { |             InterfaceOrClass(t) => { | ||||||
|  |                 writer.writeln_indented("InterfaceOrClassTypeUse")?; | ||||||
|                 writer.increase_indent(); |                 writer.increase_indent(); | ||||||
|                 t.pretty_print(writer)?; |                 t.pretty_print(writer)?; | ||||||
|                 writer.decrease_indent(); |                 writer.decrease_indent(); | ||||||
|             } |             } | ||||||
|             Tuple(t) => { |             Tuple(t) => { | ||||||
|  |                 writer.writeln_indented("TupleTypeUse")?; | ||||||
|                 writer.increase_indent(); |                 writer.increase_indent(); | ||||||
|                 t.pretty_print(writer)?; |                 t.pretty_print(writer)?; | ||||||
|                 writer.decrease_indent(); |                 writer.decrease_indent(); | ||||||
|             } |             } | ||||||
|             Function(t) => { |             Function(t) => { | ||||||
|  |                 writer.writeln_indented("FunctionTypeUse")?; | ||||||
|                 writer.increase_indent(); |                 writer.increase_indent(); | ||||||
|                 t.pretty_print(writer)?; |                 t.pretty_print(writer)?; | ||||||
|                 writer.decrease_indent(); |                 writer.decrease_indent(); | ||||||
| @ -118,6 +96,33 @@ impl PrettyPrint for TypeUse { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl PrettyPrint for PrimitiveTypeUse { | ||||||
|  |     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|  |         use PrimitiveTypeUse::*; | ||||||
|  |         match self { | ||||||
|  |             Byte => writer.writeln_indented("Byte"), | ||||||
|  |             Short => writer.writeln_indented("Short"), | ||||||
|  |             Char => writer.writeln_indented("Char"), | ||||||
|  |             Int => writer.writeln_indented("Int"), | ||||||
|  |             Long => writer.writeln_indented("Long"), | ||||||
|  |             Double => writer.writeln_indented("Double"), | ||||||
|  |             Bool => writer.writeln_indented("Bool"), | ||||||
|  |             String => writer.writeln_indented("String"), | ||||||
|  |             Array(generics) => { | ||||||
|  |                 writer.writeln_indented("Array")?; | ||||||
|  |                 if let Some(generics) = generics { | ||||||
|  |                     writer.increase_indent(); | ||||||
|  |                     generics.pretty_print(writer)?; | ||||||
|  |                     writer.decrease_indent(); | ||||||
|  |                 } | ||||||
|  |                 Ok(()) | ||||||
|  |             } | ||||||
|  |             Any => writer.writeln_indented("Any"), | ||||||
|  |             Void => writer.writeln_indented("Void"), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| impl PrettyPrint for InterfaceOrClassTypeUse { | impl PrettyPrint for InterfaceOrClassTypeUse { | ||||||
|     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         writer.writeln_indented(&format!( |         writer.writeln_indented(&format!( | ||||||
| @ -606,12 +611,12 @@ impl PrettyPrint for UseStatementLast { | |||||||
|         writer.writeln_indented("UseStatementLast")?; |         writer.writeln_indented("UseStatementLast")?; | ||||||
|         writer.increase_indent(); |         writer.increase_indent(); | ||||||
|         match self { |         match self { | ||||||
|             UseStatementLast::Identifier(i) => i.borrow().pretty_print(writer)?, |             UseStatementLast::Identifier(i) => i.pretty_print(writer)?, | ||||||
|             UseStatementLast::Identifiers(is) => { |             UseStatementLast::Identifiers(is) => { | ||||||
|                 for i in is { |                 for i in is { | ||||||
|                     i.borrow().pretty_print(writer)?; |                     i.pretty_print(writer)?; | ||||||
|                 } |                 } | ||||||
|             }, |             } | ||||||
|             UseStatementLast::Star => { |             UseStatementLast::Star => { | ||||||
|                 writer.writeln_indented("Star")?; |                 writer.writeln_indented("Star")?; | ||||||
|             } |             } | ||||||
| @ -785,7 +790,7 @@ impl PrettyPrint for Expression { | |||||||
|             UnarySuffix(e) => e.pretty_print(writer), |             UnarySuffix(e) => e.pretty_print(writer), | ||||||
|             Call(e) => e.pretty_print(writer), |             Call(e) => e.pretty_print(writer), | ||||||
|             ObjectAccess(o) => o.pretty_print(writer), |             ObjectAccess(o) => o.pretty_print(writer), | ||||||
|             Literal(literial) => literial.pretty_print(writer), |             Literal(literal) => literal.pretty_print(writer), | ||||||
|             FullyQualifiedName(fqn) => fqn.pretty_print(writer), |             FullyQualifiedName(fqn) => fqn.pretty_print(writer), | ||||||
|             Closure(closure) => closure.pretty_print(writer), |             Closure(closure) => closure.pretty_print(writer), | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -5,8 +5,8 @@ macro_rules! to_unparse_vec { | |||||||
|     ( $nodes:expr ) => { |     ( $nodes:expr ) => { | ||||||
|         $nodes |         $nodes | ||||||
|             .iter() |             .iter() | ||||||
|             .map(|node| node as &dyn Unparse) |             .map(|node| *node as &dyn Unparse) | ||||||
|             .collect::<Vec<&dyn Unparse>>() |             .collect::<Vec<_>>() | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -112,6 +112,7 @@ impl Unparse for PrefixUnaryOperator { | |||||||
|             Spread => writer.write("..."), |             Spread => writer.write("..."), | ||||||
|             BorrowMut => writer.write("&mut"), |             BorrowMut => writer.write("&mut"), | ||||||
|             Borrow => writer.write("&"), |             Borrow => writer.write("&"), | ||||||
|  |             Star => writer.write("*"), | ||||||
|             Mut => writer.write("mut"), |             Mut => writer.write("mut"), | ||||||
|             Not => writer.write("!"), |             Not => writer.write("!"), | ||||||
|             Negative => writer.write("-"), |             Negative => writer.write("-"), | ||||||
| @ -125,6 +126,8 @@ impl Unparse for SuffixUnaryOperator { | |||||||
|         match self { |         match self { | ||||||
|             PlusPlus => writer.write("++"), |             PlusPlus => writer.write("++"), | ||||||
|             MinusMinus => writer.write("--"), |             MinusMinus => writer.write("--"), | ||||||
|  |             Call => writer.write("()"), | ||||||
|  |             Index => writer.write("[]"), | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -143,7 +146,7 @@ impl ListUnparse for FullyQualifiedName { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn inner(&self) -> Vec<&dyn Unparse> { |     fn inner(&self) -> Vec<&dyn Unparse> { | ||||||
|         to_unparse_vec!(self.identifiers) |         to_unparse_vec!(self.identifiers()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -165,56 +168,56 @@ impl Unparse for TypeUse { | |||||||
| 
 | 
 | ||||||
| impl Unparse for InterfaceOrClassTypeUse { | impl Unparse for InterfaceOrClassTypeUse { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         for _ in 0..self.borrow_count { |         for _ in 0..self.borrow_count() { | ||||||
|             writer.write("&")?; |             writer.write("&")?; | ||||||
|         } |         } | ||||||
|         if self.is_mutable { |         if self.is_mutable() { | ||||||
|             writer.write("mut")?; |             writer.write("mut")?; | ||||||
|         } |         } | ||||||
|         if self.borrow_count > 0 || self.is_mutable { |         if self.borrow_count() > 0 || self.is_mutable() { | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         self.fqn.unparse(writer)?; |         self.fqn().unparse(writer)?; | ||||||
|         self.generics.unparse(writer)?; |         self.generics().unparse(writer)?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Unparse for TupleTypeUse { | impl Unparse for TupleTypeUse { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         for _ in 0..self.borrow_count { |         for _ in 0..self.borrow_count() { | ||||||
|             writer.write("&")?; |             writer.write("&")?; | ||||||
|         } |         } | ||||||
|         if self.is_mutable { |         if self.is_mutable() { | ||||||
|             writer.write("mut")?; |             writer.write("mut")?; | ||||||
|         } |         } | ||||||
|         if self.borrow_count > 0 || self.is_mutable { |         if self.borrow_count() > 0 || self.is_mutable() { | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         self.arguments.unparse(writer)?; |         self.arguments().unparse(writer)?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Unparse for FunctionTypeUse { | impl Unparse for FunctionTypeUse { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         for _ in 0..self.borrow_count { |         for _ in 0..self.borrow_count() { | ||||||
|             writer.write("&")?; |             writer.write("&")?; | ||||||
|         } |         } | ||||||
|         if let Some(function_type_modifier) = &self.function_modifier { |         if let Some(function_type_modifier) = self.function_modifier() { | ||||||
|             function_type_modifier.unparse(writer)?; |             function_type_modifier.unparse(writer)?; | ||||||
|         } |         } | ||||||
|         if self.borrow_count > 0 || self.function_modifier.is_some() { |         if self.borrow_count() > 0 || self.function_modifier().is_some() { | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         writer.write("fn ")?; |         writer.write("fn ")?; | ||||||
|         if !self.generics.is_empty() { |         if !self.generics().is_empty() { | ||||||
|             self.generics.unparse(writer)?; |             self.generics().unparse(writer)?; | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         self.parameters.unparse(writer)?; |         self.parameters().unparse(writer)?; | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         self.return_type.unparse(writer)?; |         self.return_type().unparse(writer)?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -235,7 +238,7 @@ impl ListUnparse for GenericArguments { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn inner(&self) -> Vec<&dyn Unparse> { |     fn inner(&self) -> Vec<&dyn Unparse> { | ||||||
|         to_unparse_vec!(self.0) |         to_unparse_vec!(self.arguments()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -255,7 +258,7 @@ impl ListUnparse for GenericParameters { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn inner(&self) -> Vec<&dyn Unparse> { |     fn inner(&self) -> Vec<&dyn Unparse> { | ||||||
|         to_unparse_vec!(self.0) |         to_unparse_vec!(self.identifiers()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -275,7 +278,7 @@ impl ListUnparse for TupleArguments { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn inner(&self) -> Vec<&dyn Unparse> { |     fn inner(&self) -> Vec<&dyn Unparse> { | ||||||
|         to_unparse_vec!(self.0) |         to_unparse_vec!(self.arguments()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -291,7 +294,7 @@ impl ListUnparse for ImplementsList { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn inner(&self) -> Vec<&dyn Unparse> { |     fn inner(&self) -> Vec<&dyn Unparse> { | ||||||
|         to_unparse_vec!(self.0) |         to_unparse_vec!(self.type_uses()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -325,15 +328,15 @@ impl ListUnparse for Parameters { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn inner(&self) -> Vec<&dyn Unparse> { |     fn inner(&self) -> Vec<&dyn Unparse> { | ||||||
|         to_unparse_vec!(self.0) |         to_unparse_vec!(self.parameters()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Unparse for Parameter { | impl Unparse for Parameter { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         self.identifier.unparse(writer)?; |         self.identifier().unparse(writer)?; | ||||||
|         writer.write(": ")?; |         writer.write(": ")?; | ||||||
|         self.type_use.unparse(writer)?; |         self.type_use().unparse(writer)?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -343,10 +346,10 @@ impl Unparse for Parameter { | |||||||
| impl Unparse for ReturnType { | impl Unparse for ReturnType { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         writer.write("-> ")?; |         writer.write("-> ")?; | ||||||
|         self.declared_type.unparse(writer)?; |         self.declared_type().unparse(writer)?; | ||||||
|         if !self.references.is_empty() { |         if !self.references().is_empty() { | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|             self.references.unparse(writer)?; |             self.references().unparse(writer)?; | ||||||
|         } |         } | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| @ -362,7 +365,7 @@ impl ListUnparse for References { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn inner(&self) -> Vec<&dyn Unparse> { |     fn inner(&self) -> Vec<&dyn Unparse> { | ||||||
|         to_unparse_vec!(self.0) |         to_unparse_vec!(self.identifiers()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -370,20 +373,55 @@ impl ListUnparse for References { | |||||||
| 
 | 
 | ||||||
| impl Unparse for CompilationUnit { | impl Unparse for CompilationUnit { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if let Some(namespace) = &self.namespace { |         if let Some(namespace) = self.namespace() { | ||||||
|             writer.write("ns ")?; |             writer.write("ns ")?; | ||||||
|             namespace.unparse(writer)?; |             namespace.unparse(writer)?; | ||||||
|             writer.write(";\n\n")?; |             writer.write(";\n\n")?; | ||||||
|         } |         } | ||||||
|         for use_statement in &self.use_statements { |         for use_statement in self.use_statements() { | ||||||
|             use_statement.unparse(writer)?; |             use_statement.unparse(writer)?; | ||||||
|             writer.write(";\n")?; |             writer.write(";\n")?; | ||||||
|         } |         } | ||||||
|         unparse_list(writer, "\n\n", &to_unparse_vec!(self.declarations))?; |         unparse_list(writer, "\n\n", &to_unparse_vec!(self.declarations()))?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl Unparse for UseStatement { | ||||||
|  |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|  |         writer.write_indented("use ")?; | ||||||
|  |         for (i, identifier) in self.identifiers().iter().enumerate() { | ||||||
|  |             identifier.unparse(writer)?; | ||||||
|  |             if i != self.identifiers().len() - 2 { | ||||||
|  |                 // 2 because of use
 | ||||||
|  |                 writer.write("::")?; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         self.last().unparse(writer)?; | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Unparse for UseStatementLast { | ||||||
|  |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|  |         match self { | ||||||
|  |             UseStatementLast::Star => writer.write("*"), | ||||||
|  |             UseStatementLast::Identifiers(identifiers) => { | ||||||
|  |                 writer.write("{")?; | ||||||
|  |                 for (i, identifier) in identifiers.iter().enumerate() { | ||||||
|  |                     identifier.unparse(writer)?; | ||||||
|  |                     if i != identifiers.len() - 1 { | ||||||
|  |                         writer.write(", ")?; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 writer.write("}")?; | ||||||
|  |                 Ok(()) | ||||||
|  |             } | ||||||
|  |             UseStatementLast::Identifier(i) => i.unparse(writer), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /* Declarations allowed in each level */ | /* Declarations allowed in each level */ | ||||||
| 
 | 
 | ||||||
| impl Unparse for ModuleLevelDeclaration { | impl Unparse for ModuleLevelDeclaration { | ||||||
| @ -442,58 +480,58 @@ impl Unparse for ClassLevelDeclaration { | |||||||
| 
 | 
 | ||||||
| impl Unparse for ModuleDeclaration { | impl Unparse for ModuleDeclaration { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if self.is_public { |         if self.is_public() { | ||||||
|             writer.write_indented("pub mod ")?; |             writer.write_indented("pub mod ")?; | ||||||
|         } else { |         } else { | ||||||
|             writer.write_indented("mod ")?; |             writer.write_indented("mod ")?; | ||||||
|         } |         } | ||||||
|         self.identifier.unparse(writer)?; |         self.identifier().unparse(writer)?; | ||||||
|         unparse_contained_declarations!(self.declarations, writer); |         unparse_contained_declarations!(self.declarations(), writer); | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Unparse for InterfaceDeclaration { | impl Unparse for InterfaceDeclaration { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if self.is_public { |         if self.is_public() { | ||||||
|             writer.write_indented("pub int ")?; |             writer.write_indented("pub int ")?; | ||||||
|         } else { |         } else { | ||||||
|             writer.write_indented("int ")?; |             writer.write_indented("int ")?; | ||||||
|         } |         } | ||||||
|         self.identifier.unparse(writer)?; |         self.identifier().unparse(writer)?; | ||||||
|         if !self.generics.is_empty() { |         if !self.generics().is_empty() { | ||||||
|             self.generics.unparse(writer)?; |             self.generics().unparse(writer)?; | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         if !self.implements.is_empty() { |         if !self.implements().is_empty() { | ||||||
|             self.implements.unparse(writer)?; |             self.implements().unparse(writer)?; | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         unparse_contained_declarations!(self.declarations, writer); |         unparse_contained_declarations!(self.declarations(), writer); | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Unparse for ClassDeclaration { | impl Unparse for ClassDeclaration { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if self.is_public { |         if self.is_public() { | ||||||
|             writer.write_indented("pub class ")?; |             writer.write_indented("pub class ")?; | ||||||
|         } else { |         } else { | ||||||
|             writer.write_indented("class ")?; |             writer.write_indented("class ")?; | ||||||
|         } |         } | ||||||
|         self.identifier.unparse(writer)?; |         self.identifier().unparse(writer)?; | ||||||
|         if !self.generics.is_empty() { |         if !self.generics().is_empty() { | ||||||
|             self.generics.unparse(writer)?; |             self.generics().unparse(writer)?; | ||||||
|         } |         } | ||||||
|         if let Some(class_constructor) = &self.class_constructor { |         if let Some(class_constructor) = self.class_constructor() { | ||||||
|             class_constructor.unparse(writer)?; |             class_constructor.unparse(writer)?; | ||||||
|         } |         } | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         if !self.implements.is_empty() { |         if !self.implements().is_empty() { | ||||||
|             self.implements.unparse(writer)?; |             self.implements().unparse(writer)?; | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         unparse_contained_declarations!(self.declarations, writer); |         unparse_contained_declarations!(self.declarations(), writer); | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -502,78 +540,78 @@ impl Unparse for ClassDeclaration { | |||||||
| 
 | 
 | ||||||
| impl Unparse for FunctionDefinition { | impl Unparse for FunctionDefinition { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if self.is_public { |         if self.is_public() { | ||||||
|             writer.write_indented("pub ")?; |             writer.write_indented("pub ")?; | ||||||
|             if let Some(modifier) = &self.modifier { |             if let Some(modifier) = self.modifier() { | ||||||
|                 modifier.unparse(writer)?; |                 modifier.unparse(writer)?; | ||||||
|                 writer.write(" fn ")?; |                 writer.write(" fn ")?; | ||||||
|             } else { |             } else { | ||||||
|                 writer.write(" fn ")?; |                 writer.write(" fn ")?; | ||||||
|             } |             } | ||||||
|         } else if let Some(modifier) = &self.modifier { |         } else if let Some(modifier) = self.modifier() { | ||||||
|             writer.write_indented("")?; |             writer.write_indented("")?; | ||||||
|             modifier.unparse(writer)?; |             modifier.unparse(writer)?; | ||||||
|             writer.write(" fn ")?; |             writer.write(" fn ")?; | ||||||
|         } else { |         } else { | ||||||
|             writer.write_indented("fn ")?; |             writer.write_indented("fn ")?; | ||||||
|         } |         } | ||||||
|         if !self.generics.is_empty() { |         if !self.generics().is_empty() { | ||||||
|             self.generics.unparse(writer)?; |             self.generics().unparse(writer)?; | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         self.identifier.unparse(writer)?; |         self.identifier().unparse(writer)?; | ||||||
|         self.parameters.unparse(writer)?; |         self.parameters().unparse(writer)?; | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         self.return_type.unparse(writer)?; |         self.return_type().unparse(writer)?; | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         self.body.unparse(writer)?; |         self.body().unparse(writer)?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Unparse for OperatorFunctionDefinition { | impl Unparse for OperatorFunctionDefinition { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if self.is_public { |         if self.is_public() { | ||||||
|             writer.write_indented("pub ")?; |             writer.write_indented("pub ")?; | ||||||
|             if let Some(modifier) = &self.modifier { |             if let Some(modifier) = self.modifier() { | ||||||
|                 modifier.unparse(writer)?; |                 modifier.unparse(writer)?; | ||||||
|                 writer.write(" op ")?; |                 writer.write(" op ")?; | ||||||
|             } else { |             } else { | ||||||
|                 writer.write("op ")?; |                 writer.write("op ")?; | ||||||
|             } |             } | ||||||
|         } else if let Some(modifier) = &self.modifier { |         } else if let Some(modifier) = self.modifier() { | ||||||
|             writer.write_indented("")?; |             writer.write_indented("")?; | ||||||
|             modifier.unparse(writer)?; |             modifier.unparse(writer)?; | ||||||
|             writer.write(" op ")?; |             writer.write(" op ")?; | ||||||
|         } else { |         } else { | ||||||
|             writer.write_indented("op ")?; |             writer.write_indented("op ")?; | ||||||
|         } |         } | ||||||
|         self.operator.unparse(writer)?; |         self.operator().unparse(writer)?; | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         self.parameters.unparse(writer)?; |         self.parameters().unparse(writer)?; | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         self.return_type.unparse(writer)?; |         self.return_type().unparse(writer)?; | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         self.body.unparse(writer)?; |         self.body().unparse(writer)?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Unparse for PlatformFunctionDeclaration { | impl Unparse for PlatformFunctionDeclaration { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if self.is_public { |         if self.is_public() { | ||||||
|             writer.write_indented("pub platform fn ")?; |             writer.write_indented("pub platform fn ")?; | ||||||
|         } else { |         } else { | ||||||
|             writer.write_indented("platform fn ")?; |             writer.write_indented("platform fn ")?; | ||||||
|         } |         } | ||||||
|         if !self.generics.is_empty() { |         if !self.generics().is_empty() { | ||||||
|             self.generics.unparse(writer)?; |             self.generics().unparse(writer)?; | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         self.identifier.unparse(writer)?; |         self.identifier().unparse(writer)?; | ||||||
|         self.parameters.unparse(writer)?; |         self.parameters().unparse(writer)?; | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         self.return_type.unparse(writer)?; |         self.return_type().unparse(writer)?; | ||||||
|         writer.write(";")?; |         writer.write(";")?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| @ -581,22 +619,22 @@ impl Unparse for PlatformFunctionDeclaration { | |||||||
| 
 | 
 | ||||||
| impl Unparse for InterfaceFunctionDeclaration { | impl Unparse for InterfaceFunctionDeclaration { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if let Some(modifier) = &self.modifier { |         if let Some(modifier) = self.modifier() { | ||||||
|             writer.write_indented("")?; |             writer.write_indented("")?; | ||||||
|             modifier.unparse(writer)?; |             modifier.unparse(writer)?; | ||||||
|             writer.write(" fn ")?; |             writer.write(" fn ")?; | ||||||
|         } else { |         } else { | ||||||
|             writer.write_indented("fn ")?; |             writer.write_indented("fn ")?; | ||||||
|         } |         } | ||||||
|         if !self.generics.is_empty() { |         if !self.generics().is_empty() { | ||||||
|             self.parameters.unparse(writer)?; |             self.generics().unparse(writer)?; | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         self.identifier.unparse(writer)?; |         self.identifier().unparse(writer)?; | ||||||
|         self.parameters.unparse(writer)?; |         self.parameters().unparse(writer)?; | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         self.return_type.unparse(writer)?; |         self.return_type().unparse(writer)?; | ||||||
|         if let Some(body) = &self.body { |         if let Some(body) = self.body() { | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|             body.unparse(writer)?; |             body.unparse(writer)?; | ||||||
|         } |         } | ||||||
| @ -606,23 +644,23 @@ impl Unparse for InterfaceFunctionDeclaration { | |||||||
| 
 | 
 | ||||||
| impl Unparse for InterfaceOperatorFunctionDeclaration { | impl Unparse for InterfaceOperatorFunctionDeclaration { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if let Some(modifier) = &self.modifier { |         if let Some(modifier) = self.modifier() { | ||||||
|             writer.write_indented("")?; |             writer.write_indented("")?; | ||||||
|             modifier.unparse(writer)?; |             modifier.unparse(writer)?; | ||||||
|             writer.write(" op ")?; |             writer.write(" op ")?; | ||||||
|         } else { |         } else { | ||||||
|             writer.write_indented("op ")?; |             writer.write_indented("op ")?; | ||||||
|         } |         } | ||||||
|         if !self.generics.is_empty() { |         if !self.generics().is_empty() { | ||||||
|             self.generics.unparse(writer)?; |             self.generics().unparse(writer)?; | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|         } |         } | ||||||
|         self.operator.unparse(writer)?; |         self.operator().unparse(writer)?; | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         self.parameters.unparse(writer)?; |         self.parameters().unparse(writer)?; | ||||||
|         writer.write(" ")?; |         writer.write(" ")?; | ||||||
|         self.return_type.unparse(writer)?; |         self.return_type().unparse(writer)?; | ||||||
|         if let Some(body) = &self.body { |         if let Some(body) = self.body() { | ||||||
|             writer.write(" ")?; |             writer.write(" ")?; | ||||||
|             body.unparse(writer)?; |             body.unparse(writer)?; | ||||||
|         } |         } | ||||||
| @ -686,7 +724,7 @@ impl ListUnparse for ClassConstructor { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn inner(&self) -> Vec<&dyn Unparse> { |     fn inner(&self) -> Vec<&dyn Unparse> { | ||||||
|         to_unparse_vec!(self.0) |         to_unparse_vec!(self.parameters()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -702,66 +740,31 @@ impl Unparse for ClassConstructorParameter { | |||||||
| 
 | 
 | ||||||
| impl Unparse for PropertyDeclaration { | impl Unparse for PropertyDeclaration { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if self.is_mutable { |         if self.is_mutable() { | ||||||
|             writer.write("mut ")?; |             writer.write("mut ")?; | ||||||
|         } |         } | ||||||
|         self.identifier.unparse(writer)?; |         self.identifier().unparse(writer)?; | ||||||
|         writer.write(": ")?; |         writer.write(": ")?; | ||||||
|         self.declared_type.unparse(writer)?; |         self.declared_type().unparse(writer)?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Unparse for FieldDeclaration { | impl Unparse for FieldDeclaration { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         if self.is_mutable { |         if self.is_mutable() { | ||||||
|             writer.write("mut ")?; |             writer.write("mut ")?; | ||||||
|         } |         } | ||||||
|         writer.write("fld ")?; |         writer.write("fld ")?; | ||||||
|         self.identifier.unparse(writer)?; |         self.identifier().unparse(writer)?; | ||||||
|         writer.write(": ")?; |         writer.write(": ")?; | ||||||
|         self.declared_type.unparse(writer)?; |         self.declared_type().unparse(writer)?; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Statements */ | /* Statements */ | ||||||
| 
 | 
 | ||||||
| impl Unparse for UseStatement { |  | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |  | ||||||
|         writer.write_indented("use ")?; |  | ||||||
|         for (i, identifier) in self.identifiers.iter().enumerate() { |  | ||||||
|             identifier.unparse(writer)?; |  | ||||||
|             if i != self.identifiers.len() - 2 { |  | ||||||
|                 // 2 because of use
 |  | ||||||
|                 writer.write("::")?; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         self.last.unparse(writer)?; |  | ||||||
|         Ok(()) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl Unparse for UseStatementLast { |  | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |  | ||||||
|         match self { |  | ||||||
|             UseStatementLast::Star => writer.write("*"), |  | ||||||
|             UseStatementLast::Identifiers(identifiers) => { |  | ||||||
|                 writer.write("{")?; |  | ||||||
|                 for (i, identifier) in identifiers.iter().enumerate() { |  | ||||||
|                     identifier.borrow().unparse(writer)?; |  | ||||||
|                     if i != identifiers.len() - 1 { |  | ||||||
|                         writer.write(", ")?; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|                 writer.write("}")?; |  | ||||||
|                 Ok(()) |  | ||||||
|             } |  | ||||||
|             UseStatementLast::Identifier(i) => i.borrow().unparse(writer), |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl Unparse for BlockStatement { | impl Unparse for BlockStatement { | ||||||
|     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { |     fn unparse(&self, writer: &mut IndentWriter) -> std::io::Result<()> { | ||||||
|         writer.writeln_indented("{")?; |         writer.writeln_indented("{")?; | ||||||
| @ -1024,7 +1027,7 @@ impl ListUnparse for CallArguments { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn inner(&self) -> Vec<&dyn Unparse> { |     fn inner(&self) -> Vec<&dyn Unparse> { | ||||||
|         to_unparse_vec!(self.0) |         to_unparse_vec!(self.arguments()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,5 +1,7 @@ | |||||||
| #![feature(new_range_api)] | #![feature(new_range_api)] | ||||||
| #![allow(warnings)] | #![allow(warnings)] | ||||||
|  | extern crate core; | ||||||
|  | 
 | ||||||
| pub mod ast; | pub mod ast; | ||||||
| pub mod diagnostic; | pub mod diagnostic; | ||||||
| pub mod module; | pub mod module; | ||||||
|  | |||||||
| @ -120,6 +120,7 @@ Star = { "*" } | |||||||
| LeftShift = { "<<" } | LeftShift = { "<<" } | ||||||
| RightShift = { ">>" } | RightShift = { ">>" } | ||||||
| Index = { "[]" } | Index = { "[]" } | ||||||
|  | BorrowMut = { Borrow ~ Mut } | ||||||
| 
 | 
 | ||||||
| Operator = { | Operator = { | ||||||
|       Or |       Or | ||||||
| @ -135,16 +136,19 @@ Operator = { | |||||||
|     | Multiply |     | Multiply | ||||||
|     | Divide |     | Divide | ||||||
|     | Modulo |     | Modulo | ||||||
|  |     | LeftShift | ||||||
|  |     | RightShift | ||||||
|  |     // unary prefix | ||||||
|  |     | Spread | ||||||
|  |     | BorrowMut | ||||||
|  |     | Borrow | ||||||
|  |     | Star | ||||||
|     | Not |     | Not | ||||||
|     | Negative |     | Negative | ||||||
|  |     // unary suffix | ||||||
|     | PlusPlus |     | PlusPlus | ||||||
|     | MinusMinus |     | MinusMinus | ||||||
|     | CallOp |     | CallOp | ||||||
|     | Spread |  | ||||||
|     | Borrow |  | ||||||
|     | Star |  | ||||||
|     | LeftShift |  | ||||||
|     | RightShift |  | ||||||
|     | Index |     | Index | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -457,10 +461,10 @@ InterfaceDefaultOperatorFunction = { | |||||||
|       Def |       Def | ||||||
|     ~ FunctionModifier? |     ~ FunctionModifier? | ||||||
|     ~ Op |     ~ Op | ||||||
|  |     ~ GenericParameters? | ||||||
|     ~ Operator |     ~ Operator | ||||||
|     ~ Parameters |     ~ Parameters | ||||||
|     ~ ReturnType |     ~ ReturnType | ||||||
|     ~ RefList? |  | ||||||
|     ~ FunctionBody |     ~ FunctionBody | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -698,10 +702,6 @@ PrefixExpression = { | |||||||
|     ~ SuffixExpression |     ~ SuffixExpression | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| BorrowMut = { |  | ||||||
|     Borrow ~ Mut |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| SuffixExpression = { | SuffixExpression = { | ||||||
|       PrimaryExpression |       PrimaryExpression | ||||||
|     ~ ( |     ~ ( | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Jesse Brault
						Jesse Brault