Skip to content

Commit 5ec375b

Browse files
committed
Merge branch 'master' of https://github.com/adler3d/QapGen
2 parents 3798fdc + fedeca5 commit 5ec375b

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

t_target_struct_is_cool.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
### Self-Describing Grammar — The Key Feature
1+
### Self-Describing Grammar — The Key Feature
22

33
```cpp
4-
t_target_struct:i_target_item{
5-
t_keyword{string kw=any_str_from_vec(split("struct,class",","));" "?}
6-
t_body_semicolon:i_struct_impl{";"}
7-
t_body_impl:i_struct_impl{
4+
struct t_target_struct:i_target_item{
5+
struct t_keyword{string kw=any_str_from_vec(split("struct,class",","));" "?};
6+
struct t_body_semicolon:i_struct_impl{";"};
7+
struct t_body_impl:i_struct_impl{
88
"{" // This brace corresponds to the opening brace in the declaration line "t_target_struct:i_target_item{"
99
vector<TAutoPtr<i_target_item>> nested?;
1010
" "?
@@ -15,23 +15,36 @@ t_target_struct:i_target_item{
1515
TAutoPtr<t_cpp_code> c?;
1616
" "?
1717
"}" // This closing brace corresponds to the closing brace of the structure body
18-
}
19-
t_parent{
18+
};
19+
struct t_parent{
2020
string arrow_or_colon=any_str_from_vec(split("=>,:",","));
2121
" "?
2222
t_name parent;
23-
}
23+
};
2424
TAutoPtr<t_keyword> kw?;
2525
t_name name;
2626
" "?
2727
TAutoPtr<t_parent> parent?;
2828
" "?
2929
TAutoPtr<i_struct_impl> body;
30-
}
30+
};
31+
struct t_struct_field:i_struct_field{
32+
TAutoPtr<t_cppcore::i_expr> type;
33+
" "?
34+
t_name name;
35+
TAutoPtr<t_struct_field_value> value?;
36+
" "?
37+
TAutoPtr<t_qst> qst?;
38+
" "?
39+
";"
40+
" "?
41+
TAutoPtr<t_attr> attr?;
42+
" "?
43+
};
3144
```
3245
3346
- In this example, the very beginning of the structure description is **not just the keyword** `struct` or `class`, but the **mandatory field** `t_name name;` which defines the name of the structure.
34-
- This means that the grammar describes **not only the syntax of the language but also itself** — this lexer is capable of reading and understanding its own description.
47+
- This means that the grammar describes **not only the syntax of the language but also itself** — this lexer is capable of reading and understanding its own description.
3548
- The curly braces `"{"` and `"}"` in `t_body_impl` are **not merely syntactic symbols**, but part of a mechanism that allows the grammar to recursively extend itself, including nested definitions.
3649
- This approach enables building **flexible, extensible, and self-documenting parsers** that can adapt and evolve along with the language.
3750
@@ -49,4 +62,4 @@ t_target_struct:i_target_item{
4962
- The curly braces are a crucial element of this mechanism, providing structure and nesting.
5063
- The mandatory field `t_name name;` is the starting point from which all the magic of self-description begins.
5164
52-
<div style="text-align: center">?</div>
65+
<div style="text-align: center">?</div>

0 commit comments

Comments
 (0)