Skip to content

feat: anonymous inline rules #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/lib/desugar/eliminate_inline.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn find_leaf_inline_rules(rules : Map[String, @elab.Rule]) -> Set[String] {
Token(_) => true
RuleCall(rule_name, [], _type) =>
not(all_inline_rules.contains(rule_name))
Param(_) | RuleCall(_, _, _) => panic()
Param(_) | RuleCall(_) | AnonmousInlineRule(_) => panic()
}
})
})
Expand All @@ -44,7 +44,7 @@ fn eliminate_inline_rules(
match item.term {
Token(_) => false
RuleCall(rule_name, [], _type) => inline_rules.contains(rule_name)
Param(_) | RuleCall(_, _, _) => panic()
Param(_) | RuleCall(_, _, _) | AnonmousInlineRule(_) => panic()
}
})
}
Expand All @@ -60,7 +60,7 @@ fn eliminate_inline_rules(
let rule = spec.rules[rule_name].unwrap()
expand_points[index] = ({ val: 0 }, rule.clauses.length() - 1)
}
Param(_) | RuleCall(_, _, _) => panic()
Param(_) | RuleCall(_, _, _) | AnonmousInlineRule(_) => panic()
}
}
let expand_point_indexes = expand_points.keys().to_array()
Expand Down Expand Up @@ -127,7 +127,7 @@ fn eliminate_inline_rules(
} else {
new_items.push(item)
}
Param(_) | RuleCall(_, _, _) => panic()
Param(_) | RuleCall(_, _, _) | AnonmousInlineRule(_) => panic()
}
}
yield_({
Expand Down
3 changes: 3 additions & 0 deletions src/lib/desugar/eliminate_parametric_rules.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn eliminate_rule_args(spec : @elab.ParserSpec) -> @elab.ParserSpec {
Some(term) => term
None => term
}
AnonmousInlineRule(_) => panic()
}
}

Expand Down Expand Up @@ -139,6 +140,7 @@ fn derive_term_ident(term : @elab.Term) -> String {
RuleCall(rule_name, [], _type) => rule_name
RuleCall(rule_name, args, _type) =>
rule_name + "__" + args.iter().map(derive_term_ident).join("_")
AnonmousInlineRule(_) => panic()
}
}

Expand Down Expand Up @@ -187,6 +189,7 @@ fn infer_return_type(
Token(token) => token.type_
Param(_, type_) => type_
RuleCall(_, _, type_) => type_
AnonmousInlineRule(_) => panic()
},
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/driver/driver.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fn compile(
Token(token) => T(get_terminal_by_name(token.name))
RuleCall(rule_name, [], _type) =>
NT(get_nonterminal_by_name(rule_name))
Param(_) | RuleCall(_, _, _) => panic()
Param(_) | RuleCall(_) | AnonmousInlineRule(_) => panic()
}
}),
prec: clause.prec,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/elab/east.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub(all) enum Term {
Token(Token)
Param(String, TypeExpr)
RuleCall(Symbol, Array[Term], TypeExpr)
AnonmousInlineRule(Array[Item], Action)
}

///|
Expand All @@ -147,5 +148,6 @@ pub fn Item::type_(self : Item) -> TypeExpr {
Token(token) => token.type_
Param(_, type_) => type_
RuleCall(_, _, type_) => type_
AnonmousInlineRule(_, action) => action.type_
}
}
3 changes: 2 additions & 1 deletion src/lib/elab/elaborate.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub fn elaborate(
rule.type_,
)
}
AnonmousInlineRule(_, _) => ...
}
}

Expand Down Expand Up @@ -214,7 +215,7 @@ pub fn elaborate(
}
break
}
Param(_) | RuleCall(_) => ()
Param(_) | RuleCall(_) | AnonmousInlineRule(_) => ()
}
}
last_prec
Expand Down
1 change: 1 addition & 0 deletions src/lib/parser/ast.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,5 @@ pub(all) enum Term {
Symbol(Symbol)
Image(String)
RuleCall(Symbol, Array[Term])
AnonmousInlineRule(Array[ClauseItem], ClauseAction)
} derive(ToJson)
Loading