summaryrefslogtreecommitdiff
path: root/src/chomp/typed.rs
diff options
context:
space:
mode:
authorGreg Brown <gmb60@cam.ac.uk>2021-01-08 18:00:11 +0000
committerGreg Brown <gmb60@cam.ac.uk>2021-01-08 18:00:11 +0000
commite1452227b8bd9ad3805480f8a5a66a75fb8370dd (patch)
treeb02c9dfdc157d753e3f1c8a09bbd2ffb0bbfcc36 /src/chomp/typed.rs
parentfe2eac31d9dbec772796c3ea75be32e9cd01b810 (diff)
Do more restructuring.
Diffstat (limited to 'src/chomp/typed.rs')
-rw-r--r--src/chomp/typed.rs36
1 files changed, 19 insertions, 17 deletions
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<Token![_]>,
ty: Type,
}
@@ -86,16 +87,16 @@ impl From<ast::Epsilon> 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<Span> {
self.inner.span()
}
}
@@ -107,6 +108,12 @@ impl From<ast::Literal> for Literal {
}
}
+impl From<Literal> for ast::Literal {
+ fn from(lit: Literal) -> Self {
+ lit.inner
+ }
+}
+
#[derive(Debug, Eq, Hash, PartialEq)]
pub struct Cat {
fst: Box<TypedExpression>,
@@ -165,14 +172,14 @@ impl Alt {
#[derive(Debug)]
pub struct Fix {
- arg: Ident,
+ arg: Name,
inner: Box<TypedExpression>,
span: Option<Span>,
ty: Type,
}
impl Fix {
- pub(crate) fn new(arg: Ident, inner: TypedExpression, span: Option<Span>, ty: Type) -> Self {
+ pub(crate) fn new(arg: Name, inner: TypedExpression, span: Option<Span>, ty: Type) -> Self {
Self {
arg,
inner: Box::new(inner),
@@ -181,7 +188,7 @@ impl Fix {
}
}
- pub fn unwrap(self) -> (Ident, TypedExpression, Option<Span>) {
+ pub fn unwrap(self) -> (Name, TypedExpression, Option<Span>) {
(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
}
}