3
3
`syntax` コマンドは新しい構文を定義することができます。
4
4
-/
5
5
import Lean
6
- namespace Syntax --#
7
6
8
7
open Lean Parser
9
8
@@ -23,7 +22,7 @@ syntax "#greet" : command
23
22
24
23
-- `#greet` というコマンドが Lean に認識されるようになった。
25
24
-- エラーメッセージは、`#greet` コマンドの解釈方法がないと言っている。
26
- /-- error: elaboration function for 'Syntax. «command#greet»' has not been implemented -/
25
+ /-- error: elaboration function for '«command#greet»' has not been implemented -/
27
26
#guard_msgs in #greet
28
27
29
28
/- Lean に構文を認識させるだけでなく、解釈させるには [ `macro_rules` ] (./MacroRules.md) などの別のコマンドが必要です。-/
@@ -35,7 +34,7 @@ macro_rules
35
34
/- ## パース優先順位
36
35
`syntax` コマンドは Lean に新しい構文解析ルールを追加するので、既存の構文と衝突して意図通りに解釈されないことがあります。
37
36
-/
38
- section
37
+ section --#
39
38
40
39
/-- `a = b as T` という構文を定義 -/
41
40
local syntax term " = " term " as " term : term
@@ -44,21 +43,23 @@ local syntax term " = " term " as " term : term
44
43
local macro_rules
45
44
| `(term| $a = $b as $c) => `(@Eq (α := $c) $a $b)
46
45
47
- set_option pp.mvars false --#
46
+ -- メタ変数の番号を表示しない
47
+ set_option pp.mvars false
48
48
49
49
-- `Nat` と `Prop` を足すことはできないというエラーメッセージ。
50
50
-- `1 + (1 = 2)` だと認識されてしまっているようだ。
51
51
/--
52
52
warning: failed to synthesize
53
53
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.
55
56
-/
56
57
#guard_msgs (warning) in
57
58
#check_failure (1 + 1 = 2 as Nat)
58
59
59
- end
60
+ end --#
60
61
/- パース優先順位(parsing precedence)を設定することで、どの構文から順に解釈されるかを指定することができ、問題を修正できることがあります。このあたりは [ `notation` ] (./Notation.md) コマンドと同様です。 -/
61
- section
62
+ section --#
62
63
63
64
-- 十分低いパース優先順位を設定する
64
65
local syntax :10 term:10 " = " term:10 " as " term:10 : term
@@ -73,5 +74,14 @@ local macro_rules
73
74
74
75
#guard (2 * 3 / 2 = 3 as Rat)
75
76
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