author | wenzelm |
Wed, 05 Nov 2014 21:59:21 +0100 | |
changeset 58907 | 0ee3563803c9 |
parent 58906 | 29788e989d61 |
child 58928 | 23d0ffd48006 |
permissions | -rw-r--r-- |
36947 | 1 |
/* Title: Pure/Isar/keyword.scala |
29449
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
3 |
|
58900 | 4 |
Isar keyword classification. |
29449
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
6 |
|
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
8 |
|
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
9 |
|
36947 | 10 |
object Keyword |
32450 | 11 |
{ |
58900 | 12 |
/** keyword classification **/ |
13 |
||
36681 | 14 |
/* kinds */ |
15 |
||
29449
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
16 |
val DIAG = "diag" |
58868
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
wenzelm
parents:
58853
diff
changeset
|
17 |
val HEADING = "heading" |
46967
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
18 |
val THY_BEGIN = "thy_begin" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
19 |
val THY_END = "thy_end" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
20 |
val THY_DECL = "thy_decl" |
58800
bfed1c26caed
explicit keyword category for commands that may start a block;
wenzelm
parents:
57837
diff
changeset
|
21 |
val THY_DECL_BLOCK = "thy_decl_block" |
48867
e9beabf045ab
some support for inlining file content into outer syntax token language;
wenzelm
parents:
46969
diff
changeset
|
22 |
val THY_LOAD = "thy_load" |
46967
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
23 |
val THY_GOAL = "thy_goal" |
29449
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
24 |
val QED = "qed" |
53571
e58ca0311c0f
more explicit indication of 'done' as proof script element;
wenzelm
parents:
53371
diff
changeset
|
25 |
val QED_SCRIPT = "qed_script" |
46967
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
26 |
val QED_BLOCK = "qed_block" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
27 |
val QED_GLOBAL = "qed_global" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
28 |
val PRF_GOAL = "prf_goal" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
29 |
val PRF_BLOCK = "prf_block" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
30 |
val PRF_OPEN = "prf_open" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
31 |
val PRF_CLOSE = "prf_close" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
32 |
val PRF_CHAIN = "prf_chain" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
33 |
val PRF_DECL = "prf_decl" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
34 |
val PRF_ASM = "prf_asm" |
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
35 |
val PRF_ASM_GOAL = "prf_asm_goal" |
53371
47b23c582127
more explicit indication of 'guess' as improper Isar (aka "script") element;
wenzelm
parents:
51274
diff
changeset
|
36 |
val PRF_ASM_GOAL_SCRIPT = "prf_asm_goal_script" |
46967
499d9bbd8de9
uniform keyword names within ML/Scala -- produce elisp names via external conversion;
wenzelm
parents:
46123
diff
changeset
|
37 |
val PRF_SCRIPT = "prf_script" |
29449
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
38 |
|
36681 | 39 |
|
40 |
/* categories */ |
|
41 |
||
57835 | 42 |
val diag = Set(DIAG) |
43 |
||
58868
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
wenzelm
parents:
58853
diff
changeset
|
44 |
val heading = Set(HEADING) |
57835 | 45 |
|
58868
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
wenzelm
parents:
58853
diff
changeset
|
46 |
val theory = Set(THY_BEGIN, THY_END, THY_LOAD, THY_DECL, THY_DECL_BLOCK, THY_GOAL) |
57837 | 47 |
|
58800
bfed1c26caed
explicit keyword category for commands that may start a block;
wenzelm
parents:
57837
diff
changeset
|
48 |
val theory_block = Set(THY_BEGIN, THY_DECL_BLOCK) |
bfed1c26caed
explicit keyword category for commands that may start a block;
wenzelm
parents:
57837
diff
changeset
|
49 |
|
58868
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
wenzelm
parents:
58853
diff
changeset
|
50 |
val theory_body = Set(THY_LOAD, THY_DECL, THY_DECL_BLOCK, THY_GOAL) |
57835 | 51 |
|
40456 | 52 |
val proof = |
58868
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
wenzelm
parents:
58853
diff
changeset
|
53 |
Set(QED, QED_SCRIPT, QED_BLOCK, QED_GLOBAL, PRF_GOAL, PRF_BLOCK, PRF_OPEN, PRF_CLOSE, |
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
wenzelm
parents:
58853
diff
changeset
|
54 |
PRF_CHAIN, PRF_DECL, PRF_ASM, PRF_ASM_GOAL, PRF_ASM_GOAL_SCRIPT, PRF_SCRIPT) |
57835 | 55 |
|
56 |
val proof_body = |
|
58868
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
wenzelm
parents:
58853
diff
changeset
|
57 |
Set(DIAG, HEADING, PRF_BLOCK, PRF_OPEN, PRF_CLOSE, PRF_CHAIN, PRF_DECL, PRF_ASM, |
c5e1cce7ace3
uniform heading commands work in any context, even in theory header;
wenzelm
parents:
58853
diff
changeset
|
58 |
PRF_ASM_GOAL, PRF_ASM_GOAL_SCRIPT, PRF_SCRIPT) |
57835 | 59 |
|
60 |
val theory_goal = Set(THY_GOAL) |
|
61 |
val proof_goal = Set(PRF_GOAL, PRF_ASM_GOAL, PRF_ASM_GOAL_SCRIPT) |
|
62 |
val qed = Set(QED, QED_SCRIPT, QED_BLOCK) |
|
63 |
val qed_global = Set(QED_GLOBAL) |
|
58900 | 64 |
|
65 |
||
66 |
type Spec = ((String, List[String]), List[String]) |
|
67 |
||
68 |
||
69 |
||
70 |
/** keyword tables **/ |
|
71 |
||
72 |
object Keywords |
|
73 |
{ |
|
74 |
def empty: Keywords = new Keywords() |
|
75 |
} |
|
76 |
||
77 |
class Keywords private( |
|
78 |
val minor: Scan.Lexicon = Scan.Lexicon.empty, |
|
58901 | 79 |
val major: Scan.Lexicon = Scan.Lexicon.empty, |
58906 | 80 |
commands: Map[String, (String, List[String])] = Map.empty) |
58900 | 81 |
{ |
82 |
/* content */ |
|
83 |
||
58901 | 84 |
def is_empty: Boolean = minor.isEmpty && major.isEmpty |
58900 | 85 |
|
58901 | 86 |
override def toString: String = |
87 |
{ |
|
58906 | 88 |
val keywords1 = minor.iterator.map(quote(_)).toList |
89 |
val keywords2 = |
|
90 |
for ((name, (kind, files)) <- commands.toList.sortBy(_._1)) yield { |
|
58901 | 91 |
quote(name) + " :: " + quote(kind) + |
92 |
(if (files.isEmpty) "" else " (" + commas_quote(files) + ")") |
|
93 |
} |
|
58906 | 94 |
(keywords1 ::: keywords2).mkString("keywords\n ", " and\n ", "") |
58900 | 95 |
} |
96 |
||
97 |
||
58902 | 98 |
/* add keywords */ |
99 |
||
58907 | 100 |
def + (name: String): Keywords = new Keywords(minor + name, major, commands) |
101 |
def + (name: String, kind: String): Keywords = this + (name, (kind, Nil)) |
|
58902 | 102 |
def + (name: String, kind: (String, List[String])): Keywords = |
103 |
{ |
|
104 |
val major1 = major + name |
|
58906 | 105 |
val commands1 = commands + (name -> kind) |
106 |
new Keywords(minor, major1, commands1) |
|
58902 | 107 |
} |
108 |
||
109 |
||
58901 | 110 |
/* command kind */ |
58900 | 111 |
|
58906 | 112 |
def command_kind(name: String): Option[String] = commands.get(name).map(_._1) |
58900 | 113 |
|
58901 | 114 |
def is_command_kind(token: Token, pred: String => Boolean): Boolean = |
58900 | 115 |
token.is_command && |
58901 | 116 |
(command_kind(token.source) match { case Some(k) => pred(k) case None => false }) |
58900 | 117 |
|
118 |
||
119 |
/* load commands */ |
|
120 |
||
121 |
def load_command(name: String): Option[List[String]] = |
|
58906 | 122 |
commands.get(name) match { |
58900 | 123 |
case Some((THY_LOAD, exts)) => Some(exts) |
124 |
case _ => None |
|
125 |
} |
|
126 |
||
127 |
private lazy val load_commands: List[(String, List[String])] = |
|
58906 | 128 |
(for ((name, (THY_LOAD, files)) <- commands.iterator) yield (name, files)).toList |
58900 | 129 |
|
130 |
def load_commands_in(text: String): Boolean = |
|
131 |
load_commands.exists({ case (cmd, _) => text.containsSlice(cmd) }) |
|
132 |
} |
|
29449
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
133 |
} |
6e7745d35a30
added outer_keyword.scala: Isar command keyword classification;
wenzelm
parents:
diff
changeset
|
134 |