diff --git a/crates/stef-build/src/definition.rs b/crates/stef-build/src/definition.rs index 95b80a9..390c218 100644 --- a/crates/stef-build/src/definition.rs +++ b/crates/stef-build/src/definition.rs @@ -2,7 +2,7 @@ use proc_macro2::{Ident, Span, TokenStream}; use quote::{quote, ToTokens}; use stef_parser::{ Comment, Const, DataType, Definition, Enum, ExternalType, Fields, Generics, Import, Literal, - Module, NamedField, Schema, Struct, TypeAlias, UnnamedField, Variant, Name, + Module, Name, NamedField, Schema, Struct, TypeAlias, UnnamedField, Variant, }; use super::{decode, encode}; diff --git a/crates/stef-parser/src/parser/aliases.rs b/crates/stef-parser/src/parser/aliases.rs index 207b29b..6f5876f 100644 --- a/crates/stef-parser/src/parser/aliases.rs +++ b/crates/stef-parser/src/parser/aliases.rs @@ -95,10 +95,7 @@ fn parse_name<'i>(input: &mut Input<'i>) -> Result, Cause> { .recognize() .with_span() .parse_next(input) - .map(|(value, span)| Name { - value, - span: span.into(), - }) + .map(Into::into) .map_err(|e| { e.map(|()| Cause::InvalidName { at: input.location(), diff --git a/crates/stef-parser/src/parser/consts.rs b/crates/stef-parser/src/parser/consts.rs index e19d646..53506d2 100644 --- a/crates/stef-parser/src/parser/consts.rs +++ b/crates/stef-parser/src/parser/consts.rs @@ -113,10 +113,7 @@ pub(super) fn parse_name<'i>(input: &mut Input<'i>) -> Result, Cause> { .recognize() .with_span() .parse_next(input) - .map(|(value, span)| Name { - value, - span: span.into(), - }) + .map(Into::into) .map_err(|e| { e.map(|()| Cause::InvalidName { at: input.location(), diff --git a/crates/stef-parser/src/parser/enums.rs b/crates/stef-parser/src/parser/enums.rs index 11981d0..0dcfe92 100644 --- a/crates/stef-parser/src/parser/enums.rs +++ b/crates/stef-parser/src/parser/enums.rs @@ -114,10 +114,7 @@ pub(super) fn parse_name<'i>(input: &mut Input<'i>) -> Result, Cause> { .recognize() .with_span() .parse_next(input) - .map(|(value, span)| Name { - value, - span: span.into(), - }) + .map(Into::into) .map_err(|e| { e.map(|()| Cause::InvalidName { at: input.location(), diff --git a/crates/stef-parser/src/parser/fields.rs b/crates/stef-parser/src/parser/fields.rs index 9e5dfd4..8cc6fb6 100644 --- a/crates/stef-parser/src/parser/fields.rs +++ b/crates/stef-parser/src/parser/fields.rs @@ -12,7 +12,7 @@ use winnow::{ }; use super::{comments, ids, types, ws, Input, ParserExt, Result}; -use crate::{highlight, location, Fields, NamedField, UnnamedField}; +use crate::{highlight, location, Fields, Name, NamedField, UnnamedField}; /// Encountered an invalid field declaration. #[derive(Debug, ParserError)] @@ -130,7 +130,7 @@ fn parse_named_field<'i>(input: &mut Input<'i>) -> Result, Cause> ( ws(comments::parse.map_err(Cause::from)), ( - delimited(space0, parse_field_name.with_span(), ':'), + delimited(space0, parse_field_name, ':'), preceded(space0, types::parse.map_err(Cause::from)), preceded(space0, ids::parse.map_err(Cause::from)), ) @@ -139,20 +139,22 @@ fn parse_named_field<'i>(input: &mut Input<'i>) -> Result, Cause> .parse_next(input) .map(|(comment, ((name, ty, id), span))| NamedField { comment, - name: name.into(), + name, ty, id, span: span.into(), }) } -fn parse_field_name<'i>(input: &mut Input<'i>) -> Result<&'i str, Cause> { +fn parse_field_name<'i>(input: &mut Input<'i>) -> Result, Cause> { ( one_of('a'..='z'), take_while(0.., ('a'..='z', '0'..='9', '_')), ) .recognize() + .with_span() .parse_next(input) + .map(Into::into) .map_err(|e| { e.map(|()| Cause::InvalidName { at: input.location(), diff --git a/crates/stef-parser/src/parser/generics.rs b/crates/stef-parser/src/parser/generics.rs index 3fd9a3a..7816597 100644 --- a/crates/stef-parser/src/parser/generics.rs +++ b/crates/stef-parser/src/parser/generics.rs @@ -67,10 +67,7 @@ fn parse_name<'i>(input: &mut Input<'i>) -> Result, Cause> { .recognize() .with_span() .parse_next(input) - .map(|(name, span)| Name { - value: name, - span: span.into(), - }) + .map(Into::into) .map_err(|e| { e.map(|()| Cause::InvalidName { at: input.location(), diff --git a/crates/stef-parser/src/parser/imports.rs b/crates/stef-parser/src/parser/imports.rs index 039a1de..1ac6ba3 100644 --- a/crates/stef-parser/src/parser/imports.rs +++ b/crates/stef-parser/src/parser/imports.rs @@ -99,10 +99,7 @@ pub(super) fn parse_segment<'i>(input: &mut Input<'i>) -> Result, Cause .recognize() .with_span() .parse_next(input) - .map(|(value, span)| Name { - value, - span: span.into(), - }) + .map(Into::into) .map_err(|e| { e.map(|()| Cause::InvalidSegmentName { at: input.location(), diff --git a/crates/stef-parser/src/parser/modules.rs b/crates/stef-parser/src/parser/modules.rs index d2410c4..6f4dd17 100644 --- a/crates/stef-parser/src/parser/modules.rs +++ b/crates/stef-parser/src/parser/modules.rs @@ -97,10 +97,7 @@ fn parse_name<'i>(input: &mut Input<'i>) -> Result, Cause> { .recognize() .with_span() .parse_next(input) - .map(|(value, span)| Name { - value, - span: span.into(), - }) + .map(Into::into) .map_err(|e| { e.map(|()| Cause::InvalidName { at: input.location(), diff --git a/crates/stef-parser/src/parser/structs.rs b/crates/stef-parser/src/parser/structs.rs index 2dddda8..72a6e63 100644 --- a/crates/stef-parser/src/parser/structs.rs +++ b/crates/stef-parser/src/parser/structs.rs @@ -94,10 +94,7 @@ pub(super) fn parse_name<'i>(input: &mut Input<'i>) -> Result, Cause> { .recognize() .with_span() .parse_next(input) - .map(|(value, span)| Name { - value, - span: span.into(), - }) + .map(Into::into) .map_err(|e| { e.map(|()| Cause::InvalidName { at: input.location(), diff --git a/crates/stef-parser/src/parser/types.rs b/crates/stef-parser/src/parser/types.rs index 9f31d9b..4389e20 100644 --- a/crates/stef-parser/src/parser/types.rs +++ b/crates/stef-parser/src/parser/types.rs @@ -176,8 +176,5 @@ fn parse_external_name<'i>(input: &mut Input<'i>) -> Result, Cause> { .recognize() .with_span() .parse_next(input) - .map(|(value, span)| Name { - value, - span: span.into(), - }) + .map(Into::into) }