diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 664e6a7..b34f653 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -371,10 +371,20 @@ where span.extend(span2), )) } else { + expect!(self, Tok::Punct(Punct::Semicolon)); Ok((ExternalDecl::Decl(declaration), span)) } } + fn external_declarations(&mut self) -> Result>> { + let mut decls = Vec::new(); + while self.peek_t().is_ok() { + let decl = self.external_declaration()?; + decls.push(decl); + } + Ok(decls) + } + fn function_param_declaration_list(&mut self) -> Result { // If the declarator includes a parameter type list, the declaration of each parameter shall // include an identifier, except for the special case of a parameter list consisting of a single diff --git a/parser/src/parser/snapshots/parser__parser__tests__empty_funky_attributes_no_params_function.snap b/parser/src/parser/snapshots/parser__parser__tests__empty_funky_attributes_no_params_function.snap index 2db9212..0e873fa 100644 --- a/parser/src/parser/snapshots/parser__parser__tests__empty_funky_attributes_no_params_function.snap +++ b/parser/src/parser/snapshots/parser__parser__tests__empty_funky_attributes_no_params_function.snap @@ -3,42 +3,44 @@ source: parser/src/parser/tests.rs expression: parsed --- Ok( - ( - FunctionDef( - FunctionDef { - declaration: Normal( - NormalDecl { - decl_spec: DeclSpec { - ty: Int, - attrs: DeclAttr { - is_extern: true, - is_static: false, - is_thread_local: true, - }, - }, - init_declarators: [ - ( - InitDecl { - declarator: Declarator { - decl: WithParams { - ident: ( - "uwu", - 35..38, - ), - params: [], - }, - pointer: false, - }, - init: None, + [ + ( + FunctionDef( + FunctionDef { + declaration: Normal( + NormalDecl { + decl_spec: DeclSpec { + ty: Int, + attrs: DeclAttr { + is_extern: true, + is_static: false, + is_thread_local: true, }, - 35..38, - ), - ], - }, - ), - body: [], - }, + }, + init_declarators: [ + ( + InitDecl { + declarator: Declarator { + decl: WithParams { + ident: ( + "uwu", + 35..38, + ), + params: [], + }, + pointer: false, + }, + init: None, + }, + 35..38, + ), + ], + }, + ), + body: [], + }, + ), + 1..43, ), - 1..43, - ), + ], ) diff --git a/parser/src/parser/snapshots/parser__parser__tests__empty_void_function.snap b/parser/src/parser/snapshots/parser__parser__tests__empty_void_function.snap index 0037b8c..8ef8cb4 100644 --- a/parser/src/parser/snapshots/parser__parser__tests__empty_void_function.snap +++ b/parser/src/parser/snapshots/parser__parser__tests__empty_void_function.snap @@ -3,42 +3,44 @@ source: parser/src/parser/tests.rs expression: parsed --- Ok( - ( - FunctionDef( - FunctionDef { - declaration: Normal( - NormalDecl { - decl_spec: DeclSpec { - ty: Void, - attrs: DeclAttr { - is_extern: false, - is_static: false, - is_thread_local: false, - }, - }, - init_declarators: [ - ( - InitDecl { - declarator: Declarator { - decl: WithParams { - ident: ( - "uwu", - 6..9, - ), - params: [], - }, - pointer: false, - }, - init: None, + [ + ( + FunctionDef( + FunctionDef { + declaration: Normal( + NormalDecl { + decl_spec: DeclSpec { + ty: Void, + attrs: DeclAttr { + is_extern: false, + is_static: false, + is_thread_local: false, }, - 6..9, - ), - ], - }, - ), - body: [], - }, + }, + init_declarators: [ + ( + InitDecl { + declarator: Declarator { + decl: WithParams { + ident: ( + "uwu", + 6..9, + ), + params: [], + }, + pointer: false, + }, + init: None, + }, + 6..9, + ), + ], + }, + ), + body: [], + }, + ), + 1..14, ), - 1..14, - ), + ], ) diff --git a/parser/src/parser/snapshots/parser__parser__tests__global_variable_declarations.snap b/parser/src/parser/snapshots/parser__parser__tests__global_variable_declarations.snap new file mode 100644 index 0000000..955566c --- /dev/null +++ b/parser/src/parser/snapshots/parser__parser__tests__global_variable_declarations.snap @@ -0,0 +1,91 @@ +--- +source: parser/src/parser/tests.rs +expression: parsed +--- +Ok( + [ + ( + Decl( + Normal( + NormalDecl { + decl_spec: DeclSpec { + ty: Int, + attrs: DeclAttr { + is_extern: false, + is_static: false, + is_thread_local: false, + }, + }, + init_declarators: [ + ( + InitDecl { + declarator: Declarator { + decl: Ident( + ( + "test", + 5..9, + ), + ), + pointer: false, + }, + init: None, + }, + 5..9, + ), + ], + }, + ), + ), + 1..9, + ), + ( + Decl( + Normal( + NormalDecl { + decl_spec: DeclSpec { + ty: Double, + attrs: DeclAttr { + is_extern: false, + is_static: false, + is_thread_local: true, + }, + }, + init_declarators: [ + ( + InitDecl { + declarator: Declarator { + decl: Ident( + ( + "uwu", + 32..35, + ), + ), + pointer: false, + }, + init: None, + }, + 32..35, + ), + ( + InitDecl { + declarator: Declarator { + decl: Ident( + ( + "owo", + 37..40, + ), + ), + pointer: false, + }, + init: None, + }, + 37..40, + ), + ], + }, + ), + ), + 11..40, + ), + ], +) diff --git a/parser/src/parser/tests.rs b/parser/src/parser/tests.rs index 664fe6a..83d7feb 100644 --- a/parser/src/parser/tests.rs +++ b/parser/src/parser/tests.rs @@ -15,7 +15,7 @@ fn the_current_root_parse_thing<'src>(src: impl Iterator, Span lex: src.peekmore(), }; - parser.external_declaration() + parser.external_declarations() } macro_rules! parse_test { @@ -52,4 +52,14 @@ int uwu(long owo, unsigned qwq) {} "#; parse_test!(src); -} \ No newline at end of file +} + +#[test] +fn global_variable_declarations() { + let src = r#" +int test; +_Thread_local double uwu, owo; + "#; + + parse_test!(src); +}