def _branch_elem_expand(start, end, context): token = sequence(zeroToOne(sequence(tn(ID, 'id'), tn(ASSIGN))), tn(TOKEN_ID, 'token'), zeroToOne(_MultRule('mult')) ) keyword = sequence(zeroToOne(sequence(tn(ID, 'id'), tn(ASSIGN))), tn(KEYWORD_NAME, 'keyword'), zeroToOne(_MultRule('mult')) ) rule = sequence(zeroToOne(sequence(tn(ID, 'id'), tn(ASSIGN))), tn(RULE_ID, 'rule'), zeroToOne(_MultRule('mult')) ) group = sequence(zeroToOne(sequence(tn(ID, 'id'), tn(ASSIGN))), _GroupRule('group'), zeroToOne(_MultRule('mult')) ) start.connect(fork( token, keyword, rule, group )).connect(end)
def _rule_expand(start, end, context): branch = _BranchRule('branch') start\ .connect(zeroToOne(tn(GRAMMAR_ANNOTATION, 'is-grammar')))\ .connect(tn(RULE_ID, 'rule-id'))\ .connect(tn(ASSIGN))\ .connect(branch)\ .connect(zeroToMany(sequence(tn(OR), branch)))\ .connect(tn(SEMICOLON))\ .connect(end)