-
Notifications
You must be signed in to change notification settings - Fork 31
feat(parse): add proto::extensions::SimpleExtensionDeclaration parser
#170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
d1ecc3e
68babd8
759847f
0d143a3
cfe8c77
91d7724
c6e7e2c
165568c
f05ea37
204bc94
dd1d796
4f56530
b62e0e3
a983a4c
b424a1e
00aa50d
fcc9797
013b50c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| use super::simple_extension_declaration::SimpleExtensionDeclarationError; | ||
| use crate::parse::{Anchor, Context, Parse}; | ||
| use crate::proto; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub struct ExtensionFunction { | ||
| anchor: Anchor<Self>, | ||
| name: String, | ||
|
ilikepi63 marked this conversation as resolved.
Outdated
|
||
| extension_uri_reference: Anchor<Self>, | ||
|
ilikepi63 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| impl<C: Context> Parse<C> for proto::extensions::simple_extension_declaration::ExtensionFunction { | ||
| type Parsed = ExtensionFunction; | ||
| type Error = SimpleExtensionDeclarationError; | ||
|
|
||
| fn parse(self, _ctx: &mut C) -> Result<Self::Parsed, Self::Error> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parser should add the function to the context, checking that the referenced extension uri is valid, the used anchor is unique, and that the definition contains a matching function with the given name in the referenced extension. |
||
| let proto::extensions::simple_extension_declaration::ExtensionFunction { | ||
| extension_uri_reference, | ||
| function_anchor, | ||
| name, | ||
| } = self; | ||
|
|
||
| // Construct the parsed ExtensionFunction | ||
| let extension_function = ExtensionFunction { | ||
| extension_uri_reference: Anchor::new(extension_uri_reference), | ||
| name, | ||
| anchor: Anchor::new(function_anchor), | ||
| }; | ||
|
|
||
| Ok(extension_function) | ||
| } | ||
| } | ||
|
|
||
| impl From<ExtensionFunction> | ||
| for proto::extensions::simple_extension_declaration::ExtensionFunction | ||
| { | ||
| fn from(value: ExtensionFunction) -> Self { | ||
| let ExtensionFunction { | ||
| anchor, | ||
| name, | ||
| extension_uri_reference, | ||
| } = value; | ||
|
|
||
| Self { | ||
| extension_uri_reference: extension_uri_reference.into_inner(), | ||
| function_anchor: anchor.into_inner(), | ||
| name: name, | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| use crate::parse::{Anchor, Context, Parse}; | ||
| use crate::proto; | ||
|
Comment on lines
+3
to
+4
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: can you merge those? |
||
|
|
||
| use super::simple_extension_declaration::SimpleExtensionDeclarationError; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub struct ExtensionType { | ||
| anchor: Anchor<Self>, | ||
| name: String, | ||
|
ilikepi63 marked this conversation as resolved.
Outdated
|
||
| extension_uri_reference: Anchor<Self>, | ||
|
ilikepi63 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| impl<C: Context> Parse<C> for proto::extensions::simple_extension_declaration::ExtensionType { | ||
| type Parsed = ExtensionType; | ||
| type Error = SimpleExtensionDeclarationError; | ||
|
|
||
| fn parse(self, _ctx: &mut C) -> Result<Self::Parsed, Self::Error> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parser should also add this declaration to the context. |
||
| let proto::extensions::simple_extension_declaration::ExtensionType { | ||
| extension_uri_reference, | ||
| type_anchor, | ||
| name, | ||
| } = self; | ||
|
|
||
| // Construct the parsed ExtensionType | ||
| let extension_type_variation = ExtensionType { | ||
| extension_uri_reference: Anchor::new(extension_uri_reference), | ||
| name, | ||
| anchor: Anchor::new(type_anchor), | ||
| }; | ||
|
|
||
| Ok(extension_type_variation) | ||
| } | ||
| } | ||
|
|
||
| impl From<ExtensionType> for proto::extensions::simple_extension_declaration::ExtensionType { | ||
| fn from(value: ExtensionType) -> Self { | ||
| let ExtensionType { | ||
| anchor, | ||
| name, | ||
| extension_uri_reference, | ||
| } = value; | ||
|
|
||
| Self { | ||
| extension_uri_reference: extension_uri_reference.into_inner(), | ||
| type_anchor: anchor.into_inner(), | ||
| name: name, | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| use crate::parse::{Anchor, Context, Parse}; | ||
| use crate::proto; | ||
|
Comment on lines
+3
to
+4
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: can you merge those? |
||
|
|
||
| use super::simple_extension_declaration::SimpleExtensionDeclarationError; | ||
|
|
||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub struct ExtensionTypeVariation { | ||
| anchor: Anchor<Self>, | ||
| name: String, | ||
|
ilikepi63 marked this conversation as resolved.
Outdated
|
||
| extension_uri_reference: Anchor<Self>, | ||
|
ilikepi63 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| impl<C: Context> Parse<C> | ||
| for proto::extensions::simple_extension_declaration::ExtensionTypeVariation | ||
| { | ||
| type Parsed = ExtensionTypeVariation; | ||
| type Error = SimpleExtensionDeclarationError; | ||
|
|
||
| fn parse(self, _ctx: &mut C) -> Result<Self::Parsed, Self::Error> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| let proto::extensions::simple_extension_declaration::ExtensionTypeVariation { | ||
| extension_uri_reference, | ||
| type_variation_anchor, | ||
| name, | ||
| } = self; | ||
|
|
||
| // Construct the parsed ExtensionTypeVariation | ||
| let extension_type_variation = ExtensionTypeVariation { | ||
| extension_uri_reference: Anchor::new(extension_uri_reference), | ||
| name, | ||
| anchor: Anchor::new(type_variation_anchor), | ||
| }; | ||
|
|
||
| Ok(extension_type_variation) | ||
| } | ||
| } | ||
|
|
||
| impl From<ExtensionTypeVariation> | ||
| for proto::extensions::simple_extension_declaration::ExtensionTypeVariation | ||
| { | ||
| fn from(value: ExtensionTypeVariation) -> Self { | ||
| let ExtensionTypeVariation { | ||
| anchor, | ||
| name, | ||
| extension_uri_reference, | ||
| } = value; | ||
|
|
||
| Self { | ||
| extension_uri_reference: extension_uri_reference.into_inner(), | ||
| type_variation_anchor: anchor.into_inner(), | ||
| name: name, | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| use crate::{ | ||
| parse::{Context, Parse}, | ||
| proto, | ||
| }; | ||
|
|
||
| use super::{ | ||
| extension_function, extension_type, extension_type_variation, | ||
| simple_extension_declaration::SimpleExtensionDeclarationError, | ||
| }; | ||
|
|
||
| /// MappingType | ||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub enum MappingType { | ||
| ExtensionType(extension_type::ExtensionType), | ||
| ExtensionTypeVariation(extension_type_variation::ExtensionTypeVariation), | ||
| ExtensionFunction(extension_function::ExtensionFunction), | ||
| } | ||
|
|
||
| impl<C: Context> Parse<C> for proto::extensions::simple_extension_declaration::MappingType { | ||
| type Parsed = MappingType; | ||
| type Error = SimpleExtensionDeclarationError; | ||
|
|
||
| fn parse(self, ctx: &mut C) -> Result<Self::Parsed, Self::Error> { | ||
| Ok(match self { | ||
| proto::extensions::simple_extension_declaration::MappingType::ExtensionFunction(inner) => MappingType::ExtensionFunction(inner.parse(ctx)?), | ||
| proto::extensions::simple_extension_declaration::MappingType::ExtensionType(inner) => MappingType::ExtensionType(inner.parse(ctx)?), | ||
| proto::extensions::simple_extension_declaration::MappingType::ExtensionTypeVariation(inner) => MappingType::ExtensionTypeVariation(inner.parse(ctx)?), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl From<MappingType> for proto::extensions::simple_extension_declaration::MappingType { | ||
| fn from(value: MappingType) -> Self { | ||
| match value { | ||
| MappingType::ExtensionFunction(inner) => { | ||
| proto::extensions::simple_extension_declaration::MappingType::ExtensionFunction( | ||
| inner.into(), | ||
| ) | ||
| } | ||
| MappingType::ExtensionType(inner) => { | ||
| proto::extensions::simple_extension_declaration::MappingType::ExtensionType( | ||
| inner.into(), | ||
| ) | ||
| } | ||
| MappingType::ExtensionTypeVariation(inner) => { | ||
| proto::extensions::simple_extension_declaration::MappingType::ExtensionTypeVariation( | ||
|
ilikepi63 marked this conversation as resolved.
Outdated
|
||
| inner.into(), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| mod extension_function; | ||
| mod extension_type; | ||
| mod extension_type_variation; | ||
| mod mapping_type; | ||
| mod simple_extension_declaration; | ||
|
ilikepi63 marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| use crate::{ | ||
| parse::{Context, Parse}, | ||
| proto, | ||
| }; | ||
| use thiserror::Error; | ||
|
|
||
| use super::mapping_type::MappingType; | ||
|
|
||
| // SimpleExtensionDeclaration | ||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub struct SimpleExtensionDeclaration { | ||
| pub mapping_type: Option<MappingType>, | ||
|
ilikepi63 marked this conversation as resolved.
Outdated
ilikepi63 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| #[derive(Debug, PartialEq, Error)] | ||
| pub enum SimpleExtensionDeclarationError {} | ||
|
|
||
| impl<C: Context> Parse<C> for proto::extensions::SimpleExtensionDeclaration { | ||
| type Parsed = SimpleExtensionDeclaration; | ||
| type Error = SimpleExtensionDeclarationError; | ||
|
|
||
| fn parse(self, ctx: &mut C) -> Result<Self::Parsed, Self::Error> { | ||
| let proto::extensions::SimpleExtensionDeclaration { mapping_type } = self; | ||
|
|
||
| Ok(SimpleExtensionDeclaration { | ||
| mapping_type: mapping_type | ||
| .map(|mapping_type| mapping_type.parse(ctx).ok()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want this to silently error on parser errors. |
||
| .flatten(), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl From<SimpleExtensionDeclaration> for proto::extensions::SimpleExtensionDeclaration { | ||
| fn from(declaration: SimpleExtensionDeclaration) -> Self { | ||
| let SimpleExtensionDeclaration { mapping_type } = declaration; | ||
|
|
||
| proto::extensions::SimpleExtensionDeclaration { | ||
| mapping_type: mapping_type.map(|mapping_type| mapping_type.into()), | ||
|
ilikepi63 marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.