Skip to content

Commit 394e9e9

Browse files
authored
Merge pull request #1102 from lean-ja/Seasawher/issue1101
syntax コマンドの name := 構文を紹介する
2 parents bf0c7b4 + 369383e commit 394e9e9

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

LeanByExample/Reference/Declarative/Syntax.lean

+19-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
`syntax` コマンドは新しい構文を定義することができます。
44
-/
55
import Lean
6-
namespace Syntax --#
76

87
open Lean Parser
98

@@ -23,7 +22,7 @@ syntax "#greet" : command
2322

2423
-- `#greet` というコマンドが Lean に認識されるようになった。
2524
-- エラーメッセージは、`#greet` コマンドの解釈方法がないと言っている。
26-
/-- error: elaboration function for 'Syntax.«command#greet»' has not been implemented -/
25+
/-- error: elaboration function for '«command#greet»' has not been implemented -/
2726
#guard_msgs in #greet
2827

2928
/- Lean に構文を認識させるだけでなく、解釈させるには [`macro_rules`](./MacroRules.md) などの別のコマンドが必要です。-/
@@ -35,7 +34,7 @@ macro_rules
3534
/- ## パース優先順位
3635
`syntax` コマンドは Lean に新しい構文解析ルールを追加するので、既存の構文と衝突して意図通りに解釈されないことがあります。
3736
-/
38-
section
37+
section --#
3938

4039
/-- `a = b as T` という構文を定義 -/
4140
local syntax term " = " term " as " term : term
@@ -44,21 +43,23 @@ local syntax term " = " term " as " term : term
4443
local macro_rules
4544
| `(term| $a = $b as $c) => `(@Eq (α := $c) $a $b)
4645

47-
set_option pp.mvars false --#
46+
-- メタ変数の番号を表示しない
47+
set_option pp.mvars false
4848

4949
-- `Nat` と `Prop` を足すことはできないというエラーメッセージ。
5050
-- `1 + (1 = 2)` だと認識されてしまっているようだ。
5151
/--
5252
warning: failed to synthesize
5353
HAdd Nat Prop ?_
54-
Additional diagnostic information may be available using the `set_option diagnostics true` command.
54+
Additional diagnostic information may be available
55+
using the `set_option diagnostics true` command.
5556
-/
5657
#guard_msgs (warning) in
5758
#check_failure (1 + 1 = 2 as Nat)
5859

59-
end
60+
end --#
6061
/- パース優先順位(parsing precedence)を設定することで、どの構文から順に解釈されるかを指定することができ、問題を修正できることがあります。このあたりは [`notation`](./Notation.md) コマンドと同様です。 -/
61-
section
62+
section --#
6263

6364
-- 十分低いパース優先順位を設定する
6465
local syntax:10 term:10 " = " term:10 " as " term:10 : term
@@ -73,5 +74,14 @@ local macro_rules
7374

7475
#guard (2 * 3 / 2 = 3 as Rat)
7576

76-
end
77-
end Syntax --#
77+
end --#
78+
/- ## name 構文
79+
`(name := ...)` という構文により、名前を付けることができます。名前を付けると、その名前で `Lean.ParserDescr` の項が生成されます。
80+
-/
81+
82+
-- `#hoge` というコマンドを定義する
83+
-- `name` 構文で名前を付けることができる
84+
syntax (name := hogeCmd) "#hoge" : command
85+
86+
-- 構文に対して付けた名前で、ParserDescr 型の項が生成されている
87+
#check (hogeCmd : ParserDescr)

0 commit comments

Comments
 (0)