-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.peg
35 lines (31 loc) · 1.21 KB
/
block.peg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
EOL <- ';'
block <-
( a:identifier _ ':' _ )?
'{'
_ i:block_inner { cst_NODECAST(auxil->root->nodes[i], Block)->arena = a; $$ = i; } _
'}' ~ { _cap_ERROR("block", "Expected closing '}' after block"); }
block_inner <-
{
cap_ps_push(auxil);
auxil->stack->mark = BLOCK;
auxil->stack->data = cst_binit_Block((cst_Node*)malloc(sizeof(cst_Node)), cst_ninit_Block((cst_nBlock*)malloc(sizeof(cst_nBlock))), $0s, 0, cap_lno(auxil), cap_cno(auxil, $0s));
_cap_ADDNODE((cst_Node*)auxil->stack->data);
$$ = _cap_LASTNODE;
}
( line_inner _ )*
{
assert(auxil->stack->mark == BLOCK);
((cst_Node*)cap_ps_pop(auxil))->pos_end = $0e;
}
line_inner <-
s:body {
cst_nBlock_addnode(cst_NODECAST((cst_Node*)auxil->stack->data, Block), s);
} / EOL {
if (auxil->config.track_empty_lines)
_cap_ADDNODE(_cap_MKINITNODE(ExtraData, "blank_eol:line_inner", NULL));
}
body <-
( ( n:block / n:block_statement ) _ EOL?
/ ( n:line_statement _ EOL ~ { _cap_ERROR("body", "Expected EOL ';' after line-statement"); }
/ n:expression _ EOL ~ { _cap_ERROR("body", "Expected EOL ';' after expression"); } ) )
{ $$ = n; }