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