Rename TypeName -> TypeIdentifier
This commit is contained in:
parent
03317233c6
commit
4b9c7e38dd
@ -15,7 +15,7 @@ pub type Block = Vec<Statement>;
|
|||||||
|
|
||||||
pub type ParamName = Rc<String>;
|
pub type ParamName = Rc<String>;
|
||||||
pub type InterfaceName = Rc<String>; //should be a singleton I think??
|
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)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Declaration {
|
pub enum Declaration {
|
||||||
@ -33,7 +33,7 @@ pub enum Declaration {
|
|||||||
expr: Expression,
|
expr: Expression,
|
||||||
},
|
},
|
||||||
Impl {
|
Impl {
|
||||||
type_name: TypeName,
|
type_name: TypeIdentifier,
|
||||||
interface_name: Option<InterfaceName>,
|
interface_name: Option<InterfaceName>,
|
||||||
block: Vec<Declaration>,
|
block: Vec<Declaration>,
|
||||||
},
|
},
|
||||||
@ -48,7 +48,7 @@ pub struct Signature {
|
|||||||
pub name: Rc<String>,
|
pub name: Rc<String>,
|
||||||
pub operator: bool,
|
pub operator: bool,
|
||||||
pub params: Vec<FormalParam>,
|
pub params: Vec<FormalParam>,
|
||||||
pub type_anno: Option<TypeName>,
|
pub type_anno: Option<TypeIdentifier>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
@ -57,23 +57,23 @@ pub struct TypeBody(pub Vec<Variant>);
|
|||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Variant {
|
pub enum Variant {
|
||||||
UnitStruct(Rc<String>),
|
UnitStruct(Rc<String>),
|
||||||
TupleStruct(Rc<String>, Vec<TypeName>),
|
TupleStruct(Rc<String>, Vec<TypeIdentifier>),
|
||||||
Record(Rc<String>, Vec<(Rc<String>, TypeName)>),
|
Record(Rc<String>, Vec<(Rc<String>, TypeIdentifier)>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct Expression(pub ExpressionType, pub Option<TypeName>);
|
pub struct Expression(pub ExpressionType, pub Option<TypeIdentifier>);
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum TypeName {
|
pub enum TypeIdentifier {
|
||||||
Tuple(Vec<TypeName>),
|
Tuple(Vec<TypeIdentifier>),
|
||||||
Singleton(TypeSingletonName)
|
Singleton(TypeSingletonName)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct TypeSingletonName {
|
pub struct TypeSingletonName {
|
||||||
pub name: Rc<String>,
|
pub name: Rc<String>,
|
||||||
pub params: Vec<TypeName>,
|
pub params: Vec<TypeIdentifier>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
@ -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()?;
|
let identifier = self.identifier()?;
|
||||||
expect!(self, Colon);
|
expect!(self, Colon);
|
||||||
let type_name = self.type_name()?;
|
let type_name = self.type_name()?;
|
||||||
@ -441,7 +441,7 @@ impl Parser {
|
|||||||
let result = match (first, second) {
|
let result = match (first, second) {
|
||||||
(first, Some(second)) => {
|
(first, Some(second)) => {
|
||||||
match first {
|
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 },
|
Declaration::Impl { type_name: second, interface_name: Some(name.clone()), block },
|
||||||
_ => return ParseError::new(&format!("Invalid name for an interface")),
|
_ => return ParseError::new(&format!("Invalid name for an interface")),
|
||||||
}
|
}
|
||||||
@ -468,13 +468,13 @@ impl Parser {
|
|||||||
Ok(expr_body)
|
Ok(expr_body)
|
||||||
});
|
});
|
||||||
|
|
||||||
parse_method!(type_anno(&mut self) -> ParseResult<TypeName> {
|
parse_method!(type_anno(&mut self) -> ParseResult<TypeIdentifier> {
|
||||||
expect!(self, Colon);
|
expect!(self, Colon);
|
||||||
self.type_name()
|
self.type_name()
|
||||||
});
|
});
|
||||||
|
|
||||||
parse_method!(type_name(&mut self) -> ParseResult<TypeName> {
|
parse_method!(type_name(&mut self) -> ParseResult<TypeIdentifier> {
|
||||||
use self::TypeName::*;
|
use self::TypeIdentifier::*;
|
||||||
Ok(match self.peek() {
|
Ok(match self.peek() {
|
||||||
LParen => Tuple(delimited!(self, LParen, type_name, Comma, RParen)),
|
LParen => Tuple(delimited!(self, LParen, type_name, Comma, RParen)),
|
||||||
_ => Singleton(self.type_singleton_name()?),
|
_ => Singleton(self.type_singleton_name()?),
|
||||||
@ -1026,7 +1026,7 @@ mod parse_tests {
|
|||||||
use super::Statement::*;
|
use super::Statement::*;
|
||||||
use super::Declaration::*;
|
use super::Declaration::*;
|
||||||
use super::Signature;
|
use super::Signature;
|
||||||
use super::TypeName::*;
|
use super::TypeIdentifier::*;
|
||||||
use super::TypeSingletonName;
|
use super::TypeSingletonName;
|
||||||
use super::ExpressionType::*;
|
use super::ExpressionType::*;
|
||||||
use super::Variant::*;
|
use super::Variant::*;
|
||||||
|
@ -59,7 +59,7 @@ impl SymbolTable {
|
|||||||
/* note: this adds names for *forward reference* but doesn't actually create any types. solve that problem
|
/* note: this adds names for *forward reference* but doesn't actually create any types. solve that problem
|
||||||
* later */
|
* later */
|
||||||
pub fn add_top_level_symbols(&mut self, ast: &ast::AST) -> Result<(), String> {
|
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::*;
|
use self::ast::Declaration::*;
|
||||||
for statement in ast.0.iter() {
|
for statement in ast.0.iter() {
|
||||||
if let Statement::Declaration(decl) = statement {
|
if let Statement::Declaration(decl) = statement {
|
||||||
@ -100,8 +100,8 @@ impl SymbolTable {
|
|||||||
},
|
},
|
||||||
Variant::TupleStruct(variant_name, tuple_members) => {
|
Variant::TupleStruct(variant_name, tuple_members) => {
|
||||||
let type_args = tuple_members.iter().map(|type_name| match type_name {
|
let type_args = tuple_members.iter().map(|type_name| match type_name {
|
||||||
TypeName::Singleton(TypeSingletonName { name, ..}) => name.clone(),
|
TypeIdentifier::Singleton(TypeSingletonName { name, ..}) => name.clone(),
|
||||||
TypeName::Tuple(_) => unimplemented!(),
|
TypeIdentifier::Tuple(_) => unimplemented!(),
|
||||||
}).collect();
|
}).collect();
|
||||||
let spec = SymbolSpec::DataConstructor {
|
let spec = SymbolSpec::DataConstructor {
|
||||||
index,
|
index,
|
||||||
|
Loading…
Reference in New Issue
Block a user