Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProB 2 Jupyter Kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
ProB 2 Jupyter Kernel
Commits
8f93a4b2
Commit
8f93a4b2
authored
Jun 14, 2018
by
dgelessus
Browse files
Options
Downloads
Patches
Plain Diff
Improve B syntax highlighting
Now supports comments, strings, numbers, keywords, and operators.
parent
c4e12f95
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
kernelspec/prob2/kernel.js
+62
-5
62 additions, 5 deletions
kernelspec/prob2/kernel.js
with
62 additions
and
5 deletions
kernelspec/prob2/kernel.js
+
62
−
5
View file @
8f93a4b2
...
@@ -18,11 +18,68 @@ define([
...
@@ -18,11 +18,68 @@ define([
},
},
token
:
function
(
stream
,
state
)
{
token
:
function
(
stream
,
state
)
{
if
(
stream
.
match
(
/^
[
A-Z_
]
+/
))
{
switch
(
state
.
state
)
{
case
"
initial
"
:
if
(
stream
.
match
(
/^
\/\/
/
))
{
// Line comment found, consume the rest of the line.
stream
.
match
(
/^.+/
);
return
"
comment
"
;
}
else
if
(
stream
.
match
(
/^
\/\*
/
))
{
// Block comment start found, switch to comment state.
state
.
state
=
"
comment
"
;
return
"
comment
"
;
}
else
if
(
stream
.
match
(
/^"
(?:[^\\
"
\n]
|
\\[^\n])
*"/
))
{
return
"
string
"
;
}
else
if
(
stream
.
match
(
/^"""/
))
{
// Multiline string found, switch to string state.
state
.
state
=
"
string
"
;
return
"
string
"
;
}
else
if
(
stream
.
match
(
/^
(?:[
0-9
]
+|0x
[
0-9A-Fa-f
]
+
)
/
))
{
return
"
number
"
;
}
else
if
(
stream
.
match
(
/^
(?:[
⋂∏∑⋃
]
|
(?:
ABSTRACT|CONCRETE
)
_
(?:
CONSTANTS|VARIABLES
)
|ANY|ASSERT|ASSERTIONS|BE|BEGIN|CASE|CHOICE|CONSTANTS|CONSTRAINTS|DEFINITIONS|EXPRESSIONS|PREDICATES|DO|EITHER|ELSE|ELSIF|END|EXTENDS|IF|IMPLEMENTATION|IMPORTS|IN|INCLUDES|INITIALI
[
SZ
]
ATION|INTER|INVARIANT|LET|LOCAL_OPERATIONS|MACHINE|MODEL|SYSTEM|OF|OPERATIONS|EVENTS|OR|PI|PRE|PROMOTES|PROPERTIES|REFINES|REFINEMENT|SEES|SELECT|SETS|SET|SIGMA|THEN|UNION|USES|VALUES|VAR|VARIANT|VARIABLES|WHEN|WHERE|WHILE|skip|FREETYPES
)
/
))
{
return
"
keyword
"
;
return
"
keyword
"
;
}
else
if
(
stream
.
match
(
/^
(?:[
⊥ℤℕ⊤∅
]
|BOOL|bfalse|FALSE|INT|INTEGER|MAXINT|MININT|NAT|NAT1|NATURAL|NATURAL1|ℕ1|ℕ₁|STRING|TRUE
)
/
))
{
return
"
atom
"
;
}
else
if
(
stream
.
match
(
/^
(?:[
ℙ¬
]
|FIN|FIN1|POW|POW1|ℙ1|ℙ₁|arity|bin|bool|btree|card|closure|closure1|conc|const|dom|father|first|fnc|front|id|infix|inter|iseq|iseq1|iterate|last|left|max|min|mirror|not|perm|postfix|pred|prefix|prj1|prj2|rank|ran|rec|rel|rev|right|seq|seq1|sizet|size|sons|son|struct|subtree|succ|tail|top|tree|union
)
/
))
{
return
"
builtin
"
;
}
else
if
(
stream
.
match
(
/^
(?:[
!∀#∃$%λ&∧'
\*
×
\+
⇸⤀
\-
−→↠⇾
\.
·‥
\/
÷∉⊈⊄≠
\\
∩↑:∈;<
\u
e103⋖↔⇽←⊆⊂⩤◀≤⇔◁=⇒>⤔↣⤖⊗≥∪↓
\^
⌒∨
\|
∣∥↦▷⩥▶~∼
\u
e100
\u
e101
\u
e102
]
|
\*\*
|
\+[\-
−
]
>|
\+[\-
−
]
>>|
[\-
−
][\-
−
]
>|
[\-
−
][\-
−
]
>>|
[\-
−
]
>|
\.\.
|
\/
:|
\/
<:|
\/
<<:|
\/
=|
\/\\
|
\/\|\\
|::|:∈|:=|<
\+
|<
[\-
−
]
>|<
[\-
−
]
|<
[\-
−
][\-
−
]
|<:|<<:|<<
\|
|<=|<=>|>
\|
|==|=>|>
\+
>|>
[\-
−
]
>|>
\+
>>|>
[\-
−
]
>>|><|>=|
\\\/
|
\\\|\/)
|mod|or|
\|\|
|
\|[\-
−
]
>|
\|
>|
\|
>>|⁻¹|<<
[\-
−
]
>|<
[\-
−
]
>>|<<
[\-
−
]
>>/
))
{
return
"
operator
"
;
}
else
if
(
stream
.
match
(
/^
[
A-Za-z_
][
A-Za-z0-9_
]
*/
))
{
return
"
variable
"
;
}
else
if
(
stream
.
match
(
/^
[\s
()
\[\]
{},
]
+/
))
{
return
null
;
}
else
{
}
else
{
stream
.
match
(
/^.+/
);
stream
.
match
(
/^.+/
);
return
null
;
return
"
error
"
;
}
case
"
comment
"
:
while
(
!
stream
.
eol
())
{
// Consume everything that is not an asterisk.
stream
.
match
(
/^
[^\*\n]
+/
);
if
(
stream
.
match
(
/^
\*\/
/
))
{
// Asterisk and slash found, switch back to initial state.
state
.
state
=
"
initial
"
;
return
"
comment
"
;
}
else
{
// Asterisk without slash found, consume and stay in comment state.
stream
.
match
(
/^
\*
/
);
}
}
return
"
comment
"
;
case
"
string
"
:
if
(
stream
.
match
(
/
(?:[^\\
"
\n]
|
\\[^\n])
*"""/
))
{
// End of multiline string found, switch back to initial state.
stream
.
state
=
"
initial
"
;
}
else
{
// No end of multiline string found, consume the rest of the line.
stream
.
match
(
/.+/
);
}
return
"
string
"
;
default
:
throw
new
Error
(
"
Unhandled state:
"
+
state
.
state
);
}
}
},
},
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment