diff --git a/src/ast.rs b/src/ast.rs index 00b3a24..2abcea8 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -16,3 +16,47 @@ pub struct ConstantDef<'a> { pub ident: &'a str, pub value: Constant<'a>, } + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum SimpleType { + Integer, + Real, + Boolean, + Char, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum RecordField<'input> { + Fixed { + identifier_list: Vec<&'input str>, + type_denoter: Type<'input>, + }, + Case { + // TODO: 6.4.3.3 Record-types + }, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum Type<'input> { + Identifier(&'input str), + Simple(SimpleType), + Enumerated(Vec<&'input str>), + Subrange { + start: Constant<'input>, + end: Constant<'input>, + }, + Array { + index: Vec>, + component: Box>, + packed: bool, + }, + Record { + fields: Vec>, + }, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct TypeDef<'input> { + pub ident: &'input str, + pub value: Type<'input>, +} diff --git a/src/grammar.lalrpop b/src/grammar.lalrpop index 016a58c..9e2b498 100644 --- a/src/grammar.lalrpop +++ b/src/grammar.lalrpop @@ -18,6 +18,7 @@ extern { "string" => Token::String(<&'input str>), "-" => Token::SpecialMinus, "+" => Token::SpecialPlus, + "=" => Token::SpecialEqual, } } @@ -42,3 +43,10 @@ pub Constant: ast::Constant<'input> = { "+"? => ast::Constant::Identifier { is_negative: false, ident }, "-" => ast::Constant::Identifier { is_negative: true, ident }, } + +pub ConstantDef: ast::ConstantDef<'input> = { + "=" => ast::ConstantDef { + ident, + value + } +} diff --git a/src/main.rs b/src/main.rs index 36ade0a..318f92d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,8 +66,28 @@ mod test { check("2.2", ast::Constant::Number(ast::Number::Real("2.2"))); check("1e10", ast::Constant::Number(ast::Number::Real("1e10"))); - check(r#""hello world""#, ast::Constant::String("\"hello world\"")); - check(r#""\"hell\"o world""#, ast::Constant::String("\"\\\"hell\\\"o world\"")); + check( + r#""\"hell\"o world""#, + ast::Constant::String("\"\\\"hell\\\"o world\""), + ); + } + + #[test] + fn parse_constant_definition() { + #[track_caller] + fn check(input: &str, value: ast::ConstantDef) { + let lexer = Lexer::new(input); + let parser = grammar::ConstantDefParser::new(); + assert_eq!(parser.parse("", lexer).unwrap(), value) + } + + check( + "MYIDENTIFIER = 2.2", + ast::ConstantDef { + ident: "MYIDENTIFIER", + value: ast::Constant::Number(ast::Number::Real("2.2")), + }, + ); } }