feat(library/init/lean/parser/basic): merge explicit and default (0) token precedences
This commit is contained in:
parent
6f68a0d1eb
commit
d7d968cead
3 changed files with 13 additions and 10 deletions
|
|
@ -110,12 +110,15 @@ def eoi : syntax_node_kind := ⟨`lean.parser.eoi⟩
|
|||
|
||||
def mk_parser_state (tokens : list token_config) : except string parser_state :=
|
||||
do -- the only hardcoded tokens, because they are never directly mentioned by a `parser`
|
||||
let builtin_tokens : list token_config := [⟨"/-", 0, none⟩, ⟨"--", 0, none⟩],
|
||||
let builtin_tokens : list token_config := [{«prefix» := "/-"}, {«prefix» := "--"}],
|
||||
t ← (builtin_tokens ++ tokens).mfoldl (λ (t : trie token_config) tk,
|
||||
match t.find tk.prefix with
|
||||
| some tk' := if tk.lbp = tk'.lbp then pure t else throw $
|
||||
"invalid token '" ++ tk.prefix ++ "', has been defined with precendences " ++
|
||||
to_string tk.lbp ++ " and " ++ to_string tk'.lbp
|
||||
| some tk' := (match tk.lbp, tk'.lbp with
|
||||
| l, 0 := pure $ t.insert tk.prefix tk
|
||||
| 0, _ := pure t
|
||||
| l, l' := if l = l' then pure t else throw $
|
||||
"invalid token '" ++ tk.prefix ++ "', has been defined with precedences " ++
|
||||
to_string l ++ " and " ++ to_string l')
|
||||
| none := pure $ t.insert tk.prefix tk)
|
||||
trie.mk,
|
||||
pure ⟨t, message_log.empty⟩
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ node_choice! decl_val {
|
|||
@[derive has_tokens has_view]
|
||||
def infer_modifier.parser : command_parser :=
|
||||
node_choice! infer_modifier {
|
||||
relaxed: try $ node! relaxed_infer_modifier ["{":max_prec, "}"],
|
||||
strict: try $ node! strict_infer_modifier ["(":max_prec, ")"],
|
||||
relaxed: try $ node! relaxed_infer_modifier ["{", "}"],
|
||||
strict: try $ node! strict_infer_modifier ["(", ")"],
|
||||
}
|
||||
|
||||
@[derive has_tokens has_view]
|
||||
|
|
@ -95,7 +95,7 @@ def structure_field.parser : command_parser :=
|
|||
node_choice! structure_field {
|
||||
-- TODO(Sebastian): this `try` is too coarse
|
||||
local_notation: try node! structure_notation [
|
||||
"(":max_prec, «notation»: notation_like.parser, ")"],
|
||||
"(", «notation»: notation_like.parser, ")"],
|
||||
field: term.bracketed_binder.parser,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -87,13 +87,13 @@ node! binder_content [
|
|||
@[derive has_tokens has_view]
|
||||
def bracketed_binder.parser : term_parser :=
|
||||
node_choice! bracketed_binder {
|
||||
explicit: node! explicit_binder ["(":max_prec, content: node_choice! explicit_binder_content {
|
||||
explicit: node! explicit_binder ["(", content: node_choice! explicit_binder_content {
|
||||
«notation»: command.notation_like.parser,
|
||||
other: binder_content.parser
|
||||
}, right: symbol ")"],
|
||||
implicit: node! implicit_binder ["{":max_prec, content: binder_content.parser, "}"],
|
||||
implicit: node! implicit_binder ["{", content: binder_content.parser, "}"],
|
||||
strict_implicit: node! strict_implicit_binder [
|
||||
left: any_of [symbol "{{" max_prec, symbol "⦃" max_prec],
|
||||
left: any_of [symbol "{{", symbol "⦃"],
|
||||
content: binder_content.parser,
|
||||
right: any_of [symbol "}}", symbol "⦄"]
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue