Skip to content

Commit 41e25d3

Browse files
Added support for Coq (#2803)
1 parent 53d34b2 commit 41e25d3

12 files changed

+902
-1
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@
280280
"title": "Content-Security-Policy",
281281
"owner": "ScottHelme"
282282
},
283+
"coq": {
284+
"title": "Coq",
285+
"owner": "RunDevelopment"
286+
},
283287
"crystal": {
284288
"title": "Crystal",
285289
"require": "ruby",

components/prism-coq.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(function (Prism) {
2+
3+
// https://github.com/coq/coq
4+
5+
var commentSource = /\(\*(?:[^(*]|\((?!\*)|\*(?!\))|<self>)*\*\)/.source;
6+
for (var i = 0; i < 2; i++) {
7+
commentSource = commentSource.replace(/<self>/g, function () { return commentSource; });
8+
}
9+
commentSource = commentSource.replace(/<self>/g, '[]');
10+
11+
Prism.languages.coq = {
12+
'comment': RegExp(commentSource),
13+
'string': {
14+
pattern: /"(?:[^"]|"")*"(?!")/,
15+
greedy: true
16+
},
17+
'attribute': [
18+
{
19+
pattern: RegExp(
20+
/#\[(?:[^\]("]|"(?:[^"]|"")*"(?!")|\((?!\*)|<comment>)*\]/.source
21+
.replace(/<comment>/g, function () { return commentSource; })
22+
),
23+
greedy: true,
24+
alias: 'attr-name',
25+
inside: {
26+
'comment': RegExp(commentSource),
27+
'string': {
28+
pattern: /"(?:[^"]|"")*"(?!")/,
29+
greedy: true
30+
},
31+
32+
'operator': /=/,
33+
'punctuation': /^#\[|\]$|[,()]/
34+
}
35+
},
36+
{
37+
pattern: /\b(?:Cumulative|Global|Local|Monomorphic|NonCumulative|Polymorphic|Private|Program)\b/,
38+
alias: 'attr-name'
39+
}
40+
],
41+
42+
'keyword': /\b(?:_|Abort|About|Add|Admit|Admitted|All|apply|Arguments|as|As|Assumptions|at|Axiom|Axioms|Back|BackTo|Backtrace|Bind|BinOp|BinOpSpec|BinRel|Blacklist|by|Canonical|Case|Cd|Check|Class|Classes|Close|Coercion|Coercions|cofix|CoFixpoint|CoInductive|Collection|Combined|Compute|Conjecture|Conjectures|Constant|Constants|Constraint|Constructors|Context|Corollary|Create|CstOp|Custom|Cut|Debug|Declare|Defined|Definition|Delimit|Dependencies|Dependent|Derive|Diffs|Drop|Elimination|else|end|End|Entry|Equality|Eval|Example|Existential|Existentials|Existing|exists|exists2|Export|Extern|Extraction|Fact|Fail|Field|File|Firstorder|fix|Fixpoint|Flags|Focus|for|forall|From|fun|Funclass|Function|Functional|GC|Generalizable|Goal|Grab|Grammar|Graph|Guarded|Haskell|Heap|Hide|Hint|HintDb|Hints|Hypotheses|Hypothesis|Identity|if|IF|Immediate|Implicit|Implicits|Import|in|Include|Induction|Inductive|Infix|Info|Initial|InjTyp|Inline|Inspect|Instance|Instances|Intro|Intros|Inversion|Inversion_clear|JSON|Language|Left|Lemma|let|Let|Lia|Libraries|Library|Load|LoadPath|Locate|Ltac|Ltac2|match|Match|measure|Method|Minimality|ML|Module|Modules|Morphism|move|Next|NoInline|Notation|Number|Obligation|Obligations|OCaml|Opaque|Open|Optimize|Parameter|Parameters|Parametric|Path|Paths|Prenex|Preterm|Primitive|Print|Profile|Projections|Proof|Prop|PropBinOp|Property|PropOp|Proposition|PropUOp|Pwd|Qed|Quit|Rec|Record|Recursive|Redirect|Reduction|Register|Relation|Remark|Remove|removed|Require|Reserved|Reset|Resolve|Restart|return|Rewrite|Right|Ring|Rings|Saturate|Save|Scheme|Scope|Scopes|Search|SearchHead|SearchPattern|SearchRewrite|Section|Separate|Set|Setoid|Show|Signatures|Solve|Solver|Sort|Sortclass|Sorted|Spec|SProp|Step|Strategies|Strategy|String|struct|Structure|SubClass|Subgraph|SuchThat|Tactic|Term|TestCompile|then|Theorem|Time|Timeout|To|Transparent|Type|Typeclasses|Types|Typing|Undelimit|Undo|Unfocus|Unfocused|Unfold|Universe|Universes|UnOp|UnOpSpec|Unshelve|using|Variable|Variables|Variant|Verbose|View|Visibility|wf|where|with|Zify)\b/,
43+
44+
'number': /\b(?:0x[a-f0-9][a-f0-9_]*(?:\.[a-f0-9_]+)?(?:p[+-]?\d[\d_]*)?|\d[\d_]*(?:\.[\d_]+)?(?:e[+-]?\d[\d_]*)?)\b/i,
45+
46+
'punct': {
47+
pattern: /@\{|\{\||\[=|:>/,
48+
alias: 'punctuation'
49+
},
50+
'operator': /\/\\|\\\/|\.{2,3}|:{1,2}=|\*\*|[-=]>|<(?:->?|[+:=>]|<:)|>(?:=|->)|\|[-|]?|[-!%&*+/<=>?@^~']/,
51+
'punctuation': /\.\(|`\(|@\{|`\{|\{\||\[=|:>|[:.,;(){}\[\]]/
52+
};
53+
54+
}(Prism));

components/prism-coq.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-coq.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<h2>Full example</h2>
2+
<pre><code>(* Source: https://coq.inria.fr/a-short-introduction-to-coq *)
3+
4+
Inductive seq : nat -> Set :=
5+
| niln : seq 0
6+
| consn : forall n : nat, nat -> seq n -> seq (S n).
7+
8+
Fixpoint length (n : nat) (s : seq n) {struct s} : nat :=
9+
match s with
10+
| niln => 0
11+
| consn i _ s' => S (length i s')
12+
end.
13+
14+
Theorem length_corr : forall (n : nat) (s : seq n), length n s = n.
15+
Proof.
16+
intros n s.
17+
18+
(* reasoning by induction over s. Then, we have two new goals
19+
corresponding on the case analysis about s (either it is
20+
niln or some consn *)
21+
induction s.
22+
23+
(* We are in the case where s is void. We can reduce the
24+
term: length 0 niln *)
25+
simpl.
26+
27+
(* We obtain the goal 0 = 0. *)
28+
trivial.
29+
30+
(* now, we treat the case s = consn n e s with induction
31+
hypothesis IHs *)
32+
simpl.
33+
34+
(* The induction hypothesis has type length n s = n.
35+
So we can use it to perform some rewriting in the goal: *)
36+
rewrite IHs.
37+
38+
(* Now the goal is the trivial equality: S n = S n *)
39+
trivial.
40+
41+
(* Now all sub cases are closed, we perform the ultimate
42+
step: typing the term built using tactics and save it as
43+
a witness of the theorem. *)
44+
Qed.
45+
</code></pre>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#[program]
2+
#[program=yes]
3+
#[deprecated(since="8.9.0")]
4+
#[local, universes(polymorphic)]
5+
#[universes(polymorphic(foo,bar))]
6+
#[canonical=yes, canonical=no]
7+
#[ export ]
8+
9+
----------------------------------------------------
10+
11+
[
12+
["attribute", [
13+
["punctuation", "#["],
14+
"program",
15+
["punctuation", "]"]
16+
]],
17+
["attribute", [
18+
["punctuation", "#["],
19+
"program",
20+
["operator", "="],
21+
"yes",
22+
["punctuation", "]"]
23+
]],
24+
["attribute", [
25+
["punctuation", "#["],
26+
"deprecated",
27+
["punctuation", "("],
28+
"since",
29+
["operator", "="],
30+
["string", "\"8.9.0\""],
31+
["punctuation", ")"],
32+
["punctuation", "]"]
33+
]],
34+
["attribute", [
35+
["punctuation", "#["],
36+
"local",
37+
["punctuation", ","],
38+
" universes",
39+
["punctuation", "("],
40+
"polymorphic",
41+
["punctuation", ")"],
42+
["punctuation", "]"]
43+
]],
44+
["attribute", [
45+
["punctuation", "#["],
46+
"universes",
47+
["punctuation", "("],
48+
"polymorphic",
49+
["punctuation", "("],
50+
"foo",
51+
["punctuation", ","],
52+
"bar",
53+
["punctuation", ")"],
54+
["punctuation", ")"],
55+
["punctuation", "]"]
56+
]],
57+
["attribute", [
58+
["punctuation", "#["],
59+
"canonical",
60+
["operator", "="],
61+
"yes",
62+
["punctuation", ","],
63+
" canonical",
64+
["operator", "="],
65+
"no",
66+
["punctuation", "]"]
67+
]],
68+
["attribute", [
69+
["punctuation", "#["],
70+
" export ",
71+
["punctuation", "]"]
72+
]]
73+
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(**)
2+
(* comment *)
3+
(*
4+
comment
5+
*)
6+
7+
(* comments (* can be (* nested *) *) *)
8+
9+
----------------------------------------------------
10+
11+
[
12+
["comment", "(**)"],
13+
["comment", "(* comment *)"],
14+
["comment", "(*\r\n comment\r\n *)"],
15+
16+
["comment", "(* comments (* can be (* nested *) *) *)"]
17+
]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy