Rename TypeName -> TypeIdentifier

This commit is contained in:
greg 2018-10-18 13:27:09 -07:00
parent 03317233c6
commit 4b9c7e38dd
3 changed files with 18 additions and 18 deletions

View File

@ -15,7 +15,7 @@ pub type Block = Vec<Statement>;
pub type ParamName = Rc<String>;
pub type InterfaceName = Rc<String>; //should be a singleton I think??
pub type FormalParam = (ParamName, Option<TypeName>);
pub type FormalParam = (ParamName, Option<TypeIdentifier>);
#[derive(Debug, PartialEq, Clone)]
pub enum Declaration {
@ -33,7 +33,7 @@ pub enum Declaration {
expr: Expression,
},
Impl {
type_name: TypeName,
type_name: TypeIdentifier,
interface_name: Option<InterfaceName>,
block: Vec<Declaration>,
},
@ -48,7 +48,7 @@ pub struct Signature {
pub name: Rc<String>,
pub operator: bool,
pub params: Vec<FormalParam>,
pub type_anno: Option<TypeName>,
pub type_anno: Option<TypeIdentifier>,
}
#[derive(Debug, PartialEq, Clone)]
@ -57,23 +57,23 @@ pub struct TypeBody(pub Vec<Variant>);
#[derive(Debug, PartialEq, Clone)]
pub enum Variant {
UnitStruct(Rc<String>),
TupleStruct(Rc<String>, Vec<TypeName>),
Record(Rc<String>, Vec<(Rc<String>, TypeName)>),
TupleStruct(Rc<String>, Vec<TypeIdentifier>),
Record(Rc<String>, Vec<(Rc<String>, TypeIdentifier)>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct Expression(pub ExpressionType, pub Option<TypeName>);
pub struct Expression(pub ExpressionType, pub Option<TypeIdentifier>);
#[derive(Debug, PartialEq, Clone)]
pub enum TypeName {
Tuple(Vec<TypeName>),
pub enum TypeIdentifier {
Tuple(Vec<TypeIdentifier>),
Singleton(TypeSingletonName)
}
#[derive(Debug, PartialEq, Clone)]
pub struct TypeSingletonName {
pub name: Rc<String>,
pub params: Vec<TypeName>,
pub params: Vec<TypeIdentifier>,
}
#[derive(Debug, PartialEq, Clone)]

View File

@ -354,7 +354,7 @@ impl Parser {
}
});
parse_method!(typed_identifier(&mut self) -> ParseResult<(Rc<String>, TypeName)> {
parse_method!(typed_identifier(&mut self) -> ParseResult<(Rc<String>, TypeIdentifier)> {
let identifier = self.identifier()?;
expect!(self, Colon);
let type_name = self.type_name()?;
@ -441,7 +441,7 @@ impl Parser {
let result = match (first, second) {
(first, Some(second)) => {
match first {
TypeName::Singleton(TypeSingletonName { ref name, ref params }) if params.len() == 0 =>
TypeIdentifier::Singleton(TypeSingletonName { ref name, ref params }) if params.len() == 0 =>
Declaration::Impl { type_name: second, interface_name: Some(name.clone()), block },
_ => return ParseError::new(&format!("Invalid name for an interface")),
}
@ -468,13 +468,13 @@ impl Parser {
Ok(expr_body)
});
parse_method!(type_anno(&mut self) -> ParseResult<TypeName> {
parse_method!(type_anno(&mut self) -> ParseResult<TypeIdentifier> {
expect!(self, Colon);
self.type_name()
});
parse_method!(type_name(&mut self) -> ParseResult<TypeName> {
use self::TypeName::*;
parse_method!(type_name(&mut self) -> ParseResult<TypeIdentifier> {
use self::TypeIdentifier::*;
Ok(match self.peek() {
LParen => Tuple(delimited!(self, LParen, type_name, Comma, RParen)),
_ => Singleton(self.type_singleton_name()?),
@ -1026,7 +1026,7 @@ mod parse_tests {
use super::Statement::*;
use super::Declaration::*;
use super::Signature;
use super::TypeName::*;
use super::TypeIdentifier::*;
use super::TypeSingletonName;
use super::ExpressionType::*;
use super::Variant::*;

View File

@ -59,7 +59,7 @@ impl SymbolTable {
/* note: this adds names for *forward reference* but doesn't actually create any types. solve that problem
* later */
pub fn add_top_level_symbols(&mut self, ast: &ast::AST) -> Result<(), String> {
use self::ast::{Statement, TypeName, Variant, TypeSingletonName, TypeBody};
use self::ast::{Statement, TypeIdentifier, Variant, TypeSingletonName, TypeBody};
use self::ast::Declaration::*;
for statement in ast.0.iter() {
if let Statement::Declaration(decl) = statement {
@ -100,8 +100,8 @@ impl SymbolTable {
},
Variant::TupleStruct(variant_name, tuple_members) => {
let type_args = tuple_members.iter().map(|type_name| match type_name {
TypeName::Singleton(TypeSingletonName { name, ..}) => name.clone(),
TypeName::Tuple(_) => unimplemented!(),
TypeIdentifier::Singleton(TypeSingletonName { name, ..}) => name.clone(),
TypeIdentifier::Tuple(_) => unimplemented!(),
}).collect();
let spec = SymbolSpec::DataConstructor {
index,