-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
144 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
pub mod structure; | ||
pub mod enumeration; | ||
pub mod type_alias; |
65 changes: 65 additions & 0 deletions
65
ecosystem/rust/parser/src/types/type_definition/type_alias/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//! Structure representation. | ||
use crate::prelude::*; | ||
use crate::types::{GenericsParser, TypeParser}; | ||
use ligen::ir::{TypeAlias, TypeDefinition}; | ||
use ligen::parser::{Parser, ParserConfig}; | ||
use crate::identifier::IdentifierParser; | ||
use crate::macro_attributes::attributes::AttributesParser; | ||
use crate::visibility::VisibilityParser; | ||
|
||
#[derive(Default)] | ||
pub struct TypeAliasParser; | ||
|
||
impl TypeAliasParser { | ||
pub fn new() -> Self { | ||
Default::default() | ||
} | ||
} | ||
|
||
impl Parser<proc_macro::TokenStream> for TypeAliasParser { | ||
type Output = TypeDefinition; | ||
fn parse(&self, token_stream: proc_macro::TokenStream, config: &ParserConfig) -> Result<Self::Output> { | ||
self.parse(proc_macro2::TokenStream::from(token_stream), config) | ||
} | ||
} | ||
|
||
impl Parser<proc_macro2::TokenStream> for TypeAliasParser { | ||
type Output = TypeDefinition; | ||
fn parse(&self, tokenstream: proc_macro2::TokenStream, config: &ParserConfig) -> Result<Self::Output> { | ||
syn::parse2::<syn::ItemType>(tokenstream) | ||
.map_err(|e| Error::Message(format!("Failed to parse to structure: {:?}", e))) | ||
.and_then(|structure| self.parse(structure, config)) | ||
} | ||
} | ||
|
||
impl Parser<syn::ItemType> for TypeAliasParser { | ||
type Output = TypeDefinition; | ||
fn parse(&self, type_alias: syn::ItemType, config: &ParserConfig) -> Result<Self::Output> { | ||
let attributes = AttributesParser::default().parse(type_alias.attrs, config)?; | ||
let identifier = IdentifierParser::new().parse(type_alias.ident, config)?; | ||
let visibility = VisibilityParser::new().parse(type_alias.vis, config)?; | ||
let interfaces = Default::default(); | ||
let type_ = TypeParser::default().parse(*type_alias.ty, config)?; | ||
let definition = TypeAlias { type_ }.into(); | ||
let generics = GenericsParser::default().parse(type_alias.generics, config)?; | ||
Ok(Self::Output { attributes, visibility, identifier, generics, interfaces, definition }) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::prelude::*; | ||
|
||
use ligen::parser::assert::*; | ||
use ligen::ir::type_alias::mock; | ||
|
||
use super::TypeAliasParser; | ||
|
||
#[test] | ||
fn type_alias() -> Result<()> { | ||
assert_eq(TypeAliasParser, mock::type_alias(), quote! { | ||
pub type Integer = i32; | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
ligen/ir/src/types/type_definition/kind_definition/type_alias/mock.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use crate::{Type, TypeAlias, TypeDefinition}; | ||
|
||
pub fn type_alias() -> TypeDefinition { | ||
TypeDefinition { | ||
identifier: "Integer".into(), | ||
definition: TypeAlias { | ||
type_: Type::i32() | ||
}.into(), | ||
..Default::default() | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
ligen/ir/src/types/type_definition/kind_definition/type_alias/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! Type alias module. | ||
use crate::{prelude::*, Type}; | ||
|
||
#[cfg(any(test, feature = "mocks"))] | ||
pub mod mock; | ||
|
||
/// Type alias representation. | ||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] | ||
pub struct TypeAlias { | ||
pub type_: Type | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ditor/src/gui/ui/layout/editor/ir/type_/type_definition/kind_definition/type_alias/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pub use crate::prelude::*; | ||
|
||
|
||
use crate::gui::ui::{EditableList, editor::{ir::{Visibility, Identifier, Attributes, Path}, widget::Widget, settings::Settings}}; | ||
|
||
#[derive(Default)] | ||
pub struct TypeAlias; | ||
|
||
impl TypeAlias { | ||
pub fn new() -> Self { | ||
Default::default() | ||
} | ||
} | ||
|
||
impl Widget for TypeAlias { | ||
type Input = ligen_ir::TypeAlias; | ||
fn show(&mut self, settings: &Settings, ui: &mut egui::Ui, type_alias: &mut ligen_ir::TypeAlias) { | ||
// EditableList::new("Variants", "Add variant").show(settings, ui, &mut enumeration.variants, |ui, variant| { | ||
// Variant::new().show(settings, ui, variant); | ||
// }); | ||
} | ||
} |