Skip to content
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

MetaM の中で throw ができないという問題 #1582

Open
Seasawher opened this issue Feb 13, 2025 · 0 comments
Open

MetaM の中で throw ができないという問題 #1582

Seasawher opened this issue Feb 13, 2025 · 0 comments
Labels
要調査 さらなる調査を要する

Comments

@Seasawher
Copy link
Member

section
  open Lean Parser

  /-- `s : String` をパースして `Syntax` の項を得る。`cat` は構文カテゴリ。-/
  def parse (cat : Name) (s : String) : MetaM Syntax := do
    ofExcept <| runParserCategory (← getEnv) cat s

  /-- 文字列をパースするコマンド -/
  macro "#parse " s:str : command => `(command|
    #eval show MetaM Unit from do
      let cats := #[`tactic, `term, `command, `doElem]
      for cat in cats do
        try
          let stx ← parse cat $s
          IO.println <| toString stx
          return
        catch _ =>
          continue
      throw <| IO.userError s!"failed to parse {$s}"
      -- IO.println s!"failed to parse {$s}"
    )
end

-- 単に連結するとパース不可でエラーになる
/-⋆-//--
error: failed to synthesize
  MonadExcept IO.Error Lean.MetaM
Additional diagnostic information may be available using the `set_option diagnostics true` command.
-/
#guard_msgs in --#
#parse "1 ⋄ 2 ⋄ 3"
@Seasawher Seasawher added the 要調査 さらなる調査を要する label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
要調査 さらなる調査を要する
Projects
None yet
Development

No branches or pull requests

1 participant