grammar doesn't need the option() construct
This commit is contained in:
@@ -4,6 +4,15 @@ An experiment in writing a low-level programming language with the intent to
|
|||||||
replace C. Zig intends to be a small language, yet powerful enough to write
|
replace C. Zig intends to be a small language, yet powerful enough to write
|
||||||
readable, safe, optimal, and concise code to solve any computing problem.
|
readable, safe, optimal, and concise code to solve any computing problem.
|
||||||
|
|
||||||
|
## Design Principles
|
||||||
|
|
||||||
|
* Never compromise power or performance.
|
||||||
|
* Keep the language small and easy to understand. C programmers should pretty
|
||||||
|
much be able to understand Zig source code without learning anything about
|
||||||
|
Zig.
|
||||||
|
* Interoperability with C is crucial. Using C libraries should not require
|
||||||
|
"Zig bindings".
|
||||||
|
|
||||||
## Goals
|
## Goals
|
||||||
|
|
||||||
* Ability to run arbitrary code at compile time and generate code.
|
* Ability to run arbitrary code at compile time and generate code.
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ Root<node> : many(FnDecl) token(EOF) {
|
|||||||
$$ = ast_create_root($1);
|
$$ = ast_create_root($1);
|
||||||
};
|
};
|
||||||
|
|
||||||
FnDecl<node> : token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) option(ReturnType) Block {
|
FnDecl<node> : token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) token(Arrow) Type Block {
|
||||||
$$ = ast_create_fn_decl($2, $4, $6, $7);
|
$$ = ast_create_fn_decl($2, $4, $7, $8);
|
||||||
};
|
} | token(Fn) token(Symbol) token(LParen) list(ParamDecl, token(Comma)) token(RParen) Block {
|
||||||
|
$$ = ast_create_void_fn_decl($2, $4, $6);
|
||||||
ReturnType<node> : token(Arrow) Type {
|
|
||||||
$$ = $2;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ParamDecl<node> : token(Symbol) token(Colon) Type {
|
ParamDecl<node> : token(Symbol) token(Colon) Type {
|
||||||
@@ -26,8 +24,10 @@ PointerType<node> : token(Star) token(Const) Type {
|
|||||||
$$ = ast_create_pointer_type($2, $3);
|
$$ = ast_create_pointer_type($2, $3);
|
||||||
};
|
};
|
||||||
|
|
||||||
Block<node> : token(LBrace) many(Statement) option(Expression) token(RBrace) {
|
Block<node> : token(LBrace) many(Statement) Expression token(RBrace) {
|
||||||
$$ = ast_create_block($2, $3);
|
$$ = ast_create_expr_block($2, $3);
|
||||||
|
} | token(LBrace) many(Statement) token(RBrace) {
|
||||||
|
$$ = ast_create_block($2);
|
||||||
};
|
};
|
||||||
|
|
||||||
Statement<node> : ExpressionStatement {
|
Statement<node> : ExpressionStatement {
|
||||||
|
|||||||
@@ -141,10 +141,6 @@ struct RuleMany {
|
|||||||
RuleNode *child;
|
RuleNode *child;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RuleOption {
|
|
||||||
RuleNode *child;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct RuleOr {
|
struct RuleOr {
|
||||||
Buf name;
|
Buf name;
|
||||||
Buf union_field_name;
|
Buf union_field_name;
|
||||||
@@ -171,7 +167,6 @@ enum RuleNodeType {
|
|||||||
RuleNodeTypeTuple,
|
RuleNodeTypeTuple,
|
||||||
RuleNodeTypeMany,
|
RuleNodeTypeMany,
|
||||||
RuleNodeTypeList,
|
RuleNodeTypeList,
|
||||||
RuleNodeTypeOption,
|
|
||||||
RuleNodeTypeOr,
|
RuleNodeTypeOr,
|
||||||
RuleNodeTypeToken,
|
RuleNodeTypeToken,
|
||||||
RuleNodeTypeSubRule,
|
RuleNodeTypeSubRule,
|
||||||
@@ -185,7 +180,6 @@ struct RuleNode {
|
|||||||
RuleTuple tuple;
|
RuleTuple tuple;
|
||||||
RuleMany many;
|
RuleMany many;
|
||||||
RuleList list;
|
RuleList list;
|
||||||
RuleOption option;
|
|
||||||
RuleOr _or;
|
RuleOr _or;
|
||||||
RuleToken token;
|
RuleToken token;
|
||||||
RuleSubRule sub_rule;
|
RuleSubRule sub_rule;
|
||||||
@@ -403,9 +397,6 @@ static void gen(Gen *g, RuleNode *node, Buf *out_field_name, ParserState *cur_st
|
|||||||
case RuleNodeTypeList:
|
case RuleNodeTypeList:
|
||||||
zig_panic("TODO");
|
zig_panic("TODO");
|
||||||
break;
|
break;
|
||||||
case RuleNodeTypeOption:
|
|
||||||
zig_panic("TODO");
|
|
||||||
break;
|
|
||||||
case RuleNodeTypeOr:
|
case RuleNodeTypeOr:
|
||||||
{
|
{
|
||||||
buf_init_from_buf(out_field_name, &node->_or.union_field_name);
|
buf_init_from_buf(out_field_name, &node->_or.union_field_name);
|
||||||
|
|||||||
Reference in New Issue
Block a user