From e1452227b8bd9ad3805480f8a5a66a75fb8370dd Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Fri, 8 Jan 2021 18:00:11 +0000 Subject: Do more restructuring. --- src/chomp/typed.rs | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'src/chomp/typed.rs') diff --git a/src/chomp/typed.rs b/src/chomp/typed.rs index 69108ae..ab6cbc8 100644 --- a/src/chomp/typed.rs +++ b/src/chomp/typed.rs @@ -1,11 +1,12 @@ use std::hash::{Hash, Hasher}; use proc_macro2::Span; -use syn::{Ident, LitStr, Token}; +use syn::{Ident, Token}; use super::{ ast, set::{FirstSet, FlastSet}, + Name, }; #[derive(Debug, Default, Clone, Eq, Hash, PartialEq)] @@ -71,7 +72,7 @@ impl Type { #[derive(Debug, Eq, Hash, PartialEq)] pub struct Epsilon { - inner: Token![_], + inner: Option, ty: Type, } @@ -86,16 +87,16 @@ impl From for Epsilon { #[derive(Debug, Eq, Hash, PartialEq)] pub struct Literal { - inner: LitStr, + inner: ast::Literal, ty: Type, } impl Literal { - pub fn inner(&self) -> &LitStr { + pub fn inner(&self) -> &ast::Literal { &self.inner } - pub fn span(&self) -> Span { + pub fn span(&self) -> Option { self.inner.span() } } @@ -107,6 +108,12 @@ impl From for Literal { } } +impl From for ast::Literal { + fn from(lit: Literal) -> Self { + lit.inner + } +} + #[derive(Debug, Eq, Hash, PartialEq)] pub struct Cat { fst: Box, @@ -165,14 +172,14 @@ impl Alt { #[derive(Debug)] pub struct Fix { - arg: Ident, + arg: Name, inner: Box, span: Option, ty: Type, } impl Fix { - pub(crate) fn new(arg: Ident, inner: TypedExpression, span: Option, ty: Type) -> Self { + pub(crate) fn new(arg: Name, inner: TypedExpression, span: Option, ty: Type) -> Self { Self { arg, inner: Box::new(inner), @@ -181,7 +188,7 @@ impl Fix { } } - pub fn unwrap(self) -> (Ident, TypedExpression, Option) { + pub fn unwrap(self) -> (Name, TypedExpression, Option) { (self.arg, *self.inner, self.span) } } @@ -204,22 +211,17 @@ impl Hash for Fix { #[derive(Debug, Eq, Hash, PartialEq)] pub struct Variable { - ident: Ident, - index: usize, + inner: ast::Variable, ty: Type, } impl Variable { - pub(crate) fn new(var: ast::Variable, ty: Type) -> Self { - Self { - ident: var.name, - index: var.index, - ty, - } + pub(crate) fn new(inner: ast::Variable, ty: Type) -> Self { + Self { inner, ty } } pub fn index(&self) -> usize { - self.index + self.inner.index } } -- cgit v1.2.3