xshade_parser/ast/
mod.rs

1use ::serde_json::{to_string, Error};
2
3pub mod span;
4pub mod identifier;
5pub mod block_declaration;
6pub mod function_argument_declaration;
7pub mod function_declaration;
8pub mod literal_type;
9pub mod operator_type;
10pub mod program_declaration;
11pub mod program_stage_declaration;
12pub mod struct_declaration;
13pub mod struct_member_declaration;
14pub mod statements;
15pub mod expressions;
16pub mod import_declaration;
17pub mod export_declaration;
18pub mod type_identifier;
19
20pub use self::span::*;
21pub use self::identifier::*;
22pub use self::block_declaration::*;
23pub use self::function_argument_declaration::*;
24pub use self::function_declaration::*;
25pub use self::literal_type::*;
26pub use self::operator_type::*;
27pub use self::program_declaration::*;
28pub use self::program_stage_declaration::*;
29pub use self::struct_declaration::*;
30pub use self::struct_member_declaration::*;
31pub use self::statements::*;
32pub use self::expressions::*;
33pub use self::import_declaration::*;
34pub use self::export_declaration::*;
35pub use self::type_identifier::*;
36
37pub trait Spanned {
38    fn get_span(&self) -> Span;
39}
40
41pub type Ast = Vec<AstItem>;
42
43#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
44pub enum AstItem {
45    Import(ImportDeclaration),
46    Export(ExportDeclaration),
47    Struct(StructDeclaration),
48    Program(ProgramDeclaration),
49    Function(FunctionDeclaration),
50    Block(BlockDeclaration),
51}
52
53impl Spanned for AstItem {
54    fn get_span(&self) -> Span {
55        match *self {
56            AstItem::Import(ref item) => item.span,
57            AstItem::Export(ref item) => item.span,
58            AstItem::Struct(ref item) => item.span,
59            AstItem::Program(ref item) => item.span,
60            AstItem::Function(ref item) => item.span,
61            AstItem::Block(ref item) => item.span,
62        }
63    }
64}
65
66pub fn serialize(ast: &Ast) -> Result<String, Error> {
67    to_string(ast)
68}