use crate::syntax::*; use crate::syntax::error::ParserError; use crate::syntax::tokens::*; grammar(file_id: usize); extern { type Location = usize; type Error = ParserError; enum Token { "(" => Token::OpenParen, ")" => Token::CloseParen, "[" => Token::OpenSquare, "]" => Token::CloseSquare, "{" => Token::OpenBrace, "}" => Token::CloseBrace, ";" => Token::Semi, ":" => Token::Colon, "," => Token::Comma, "`" => Token::BackTick, "\\" => Token::Lambda(_), "->" => Token::Arrow, "" => Token::TypeName(), "" => Token::ValueName(), "" => Token::OperatorName(), "" => Token::PrimitiveTypeName(), "" => Token::PrimitiveValueName(), "" => Token::Integer(), "" => Token::Character(), "" => Token::String(), } } pub Type: Type = { FunctionType, } FunctionType: Type = { TypeApplication, "->" => Type::Function(Box::new(argtype), Box::new(ret)), } TypeApplication: Type = { BaseType, "> => { let constructor = Type::Constructor(Location::new(file_id, s..e), c); Type::Application(Box::new(constructor), arguments) }, "> => { let constructor = Type::Constructor(Location::new(file_id, s..e), c); Type::Application(Box::new(constructor), arguments) }, } BaseType: Type = { "> => Type::Variable(Location::new(file_id, s..e), v), "> => Type::Primitive(Location::new(file_id, s..e), p), "(" ")" => t, } pub ConstantValue: ConstantValue = { "> => ConstantValue::Integer(Location::new(file_id, s..e), x), "> => ConstantValue::Character(Location::new(file_id, s..e), x), "> => ConstantValue::String(Location::new(file_id, s..e), x), }