From 4145259d1205e1be8a46742933b501fdc539e1e2 Mon Sep 17 00:00:00 2001 From: serr Date: Sun, 18 May 2025 20:46:00 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20st?= =?UTF-8?q?ruct=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- analyzers/test/test.l | 1 + analyzers/test/test.y | 14 +++++++++++++- tests/main.go | 8 ++++++++ tests/test_types.txt | 11 ++++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/analyzers/test/test.l b/analyzers/test/test.l index b5ee1ce..40a5bbe 100644 --- a/analyzers/test/test.l +++ b/analyzers/test/test.l @@ -72,6 +72,7 @@ LETTER_OR_DIGIT [a-zA-Z0-9_] "++" { return INC; } "--" { return DEC; } +"struct" { return STRUCT; } "type" { return TYPE; } "go" { return GO; } "defer" { return DEFER; } diff --git a/analyzers/test/test.y b/analyzers/test/test.y index fc707d8..02af1a3 100644 --- a/analyzers/test/test.y +++ b/analyzers/test/test.y @@ -25,7 +25,7 @@ void free_node(char *str) { %token VAR FUNC RETURN STRING_LITERAL FLOAT_LITERAL COMPLEX_LITERAL NUMBER PACKAGE IMPORT %token INC DEC PLUS_EQ MINUS_EQ MUL_EQ DIV_EQ MOD_EQ %token AMPERSAND_EQ PIPE_EQ XOR_EQ LSHIFT_EQ RSHIFT_EQ AND_NOT_EQ -%token FOR BREAK CONTINUE ARROW IF ELSE RANGE DEFER GO TYPE +%token FOR BREAK CONTINUE ARROW IF ELSE RANGE DEFER GO TYPE STRUCT %token CHAN CONST CASE SWITCH %token PLUS MINUS MULT DIV MOD %token STRING @@ -251,6 +251,10 @@ log_expr: // types +struct_types: + STRUCT LBRACE field_list RBRACE + ; + bool_types: BOOL @@ -284,6 +288,7 @@ func_types: type: int_types { } + | struct_types { } | func_types { } | string_types { } | float_types { } @@ -364,6 +369,13 @@ func_declaration: ; // +// struct +field_list: + | arg_declaration + | field_list SEMICOLON arg_declaration + ; +// + // vars decl var_multiple_short_declaration: identifiers_list SHORT_DECLARATION math_expr_or_literals_list diff --git a/tests/main.go b/tests/main.go index c4a180d..e6c8181 100644 --- a/tests/main.go +++ b/tests/main.go @@ -5,6 +5,14 @@ import ( "log" ) +type person struct { + name, second_name string + age int +} + +type epmty struct { +} + func test(int, int) { } diff --git a/tests/test_types.txt b/tests/test_types.txt index a9aaa7d..c312b9b 100644 --- a/tests/test_types.txt +++ b/tests/test_types.txt @@ -2,4 +2,13 @@ package main; import "fmt"; type mile uint; -type BinaryOp func(int, int) int; \ No newline at end of file +type BinaryOp func(int, int) int; + +type empty struct{ +}; + +type person struct{ + name, second_name string; + age int; + work func() +}; \ No newline at end of file