Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
finesse-syntax-jupyterlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Philip Jones
finesse-syntax-jupyterlab
Commits
30fda89e
Commit
30fda89e
authored
Apr 20, 2021
by
Phil Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up type annotations.
parent
40ea1f47
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
29 deletions
+41
-29
codemirror-finesse-python.ts
src/codemirror-finesse-python.ts
+11
-9
codemirror-finesse2.ts
src/codemirror-finesse2.ts
+10
-7
codemirror-my-multiplex.d.ts
src/codemirror-my-multiplex.d.ts
+7
-1
codemirror-my-multiplex.js
src/codemirror-my-multiplex.js
+11
-10
index.ts
src/index.ts
+2
-2
No files found.
src/codemirror-finesse-python.ts
View file @
30fda89e
import
{
ICodeMirror
}
from
'@jupyterlab/codemirror'
;
import
{
defineMultiplexingMode
}
from
'./codemirror-my-multiplex'
;
import
{
defineFinesse2Mode
}
from
'./codemirror-finesse2'
;
export
function
setupFinesseCodeMirror
(
CodeMirror
:
any
):
void
{
defineMultiplexingMode
(
CodeMirror
);
defineFinesse2Mode
(
CodeMirror
);
export
function
setupFinesseCodeMirror
(
codemirror
:
ICodeMirror
):
void
{
const
cm
=
codemirror
.
CodeMirror
;
defineMultiplexingMode
(
codemirror
);
defineFinesse2Mode
(
codemirror
);
CodeMirror
.
defineMode
(
'finesse-python'
,
(
config
:
any
)
=>
{
const
pmode
=
CodeMirror
.
getMode
(
config
,
'python'
);
return
CodeMirror
.
myMultiplexingMode
(
pmode
,
{
cm
.
defineMode
(
'finesse-python'
,
(
config
:
any
)
=>
{
const
pmode
=
cm
.
getMode
(
config
,
'python'
);
return
cm
.
myMultiplexingMode
(
pmode
,
{
open
:
/
(?=
#kat2code
)
/
,
close
:
/
(?=
"""
)
/
,
// Match string end without consuming it
mode
:
CodeMirror
.
getMode
(
config
,
'text/x-finesse2'
),
mode
:
cm
.
getMode
(
config
,
'text/x-finesse2'
),
delimStyle
:
'delim'
});
});
CodeMirror
.
defineMIME
(
'text/x-finesse-python'
,
'finesse-python'
);
cm
.
defineMIME
(
'text/x-finesse-python'
,
'finesse-python'
);
CodeMirror
.
modeInfo
.
push
({
cm
.
modeInfo
.
push
({
name
:
'Finesse Python'
,
mime
:
'text/x-finesse-python'
,
mode
:
'finesse-python'
,
...
...
src/codemirror-finesse2.ts
View file @
30fda89e
import
{
ICodeMirror
}
from
'@jupyterlab/codemirror'
;
const
components
=
[
'bs[12]?'
,
'dbs'
,
...
...
@@ -117,8 +119,9 @@ const regex = {
* link
*/
export
function
defineFinesse2Mode
(
CodeMirror
:
any
):
void
{
CodeMirror
.
defineMode
(
'finesse2'
,
()
=>
{
export
function
defineFinesse2Mode
(
codemirror
:
ICodeMirror
):
void
{
const
cm
=
codemirror
.
CodeMirror
;
cm
.
defineMode
(
'finesse2'
,
()
=>
{
function
tokenBase
(
stream
:
CodeMirror
.
StringStream
,
state
:
any
)
{
return
'line-background-finesse '
+
tokenLex
(
stream
,
state
);
}
...
...
@@ -134,12 +137,12 @@ export function defineFinesse2Mode(CodeMirror: any): void {
stream
.
skipToEnd
();
return
'comment'
;
}
if
(
stream
.
peek
()
==
'$'
)
{
if
(
stream
.
peek
()
==
=
'$'
)
{
stream
.
next
();
}
stream
.
eatWhile
(
/
[^\s]
/
);
let
style
=
null
;
le
t
cur
=
stream
.
current
();
cons
t
cur
=
stream
.
current
();
if
(
state
.
firstOnLine
)
{
if
(
regex
[
'component'
].
test
(
cur
)
||
regex
[
'detector'
].
test
(
cur
))
{
...
...
@@ -163,7 +166,7 @@ export function defineFinesse2Mode(CodeMirror: any): void {
}
else
if
(
regex
[
'variable'
].
test
(
cur
))
{
style
=
'variable-2'
;
}
if
(
style
!=
null
)
{
if
(
style
!=
=
null
)
{
state
.
firstOnLine
=
false
;
return
style
;
}
...
...
@@ -181,11 +184,11 @@ export function defineFinesse2Mode(CodeMirror: any): void {
blankLine
:
function
(
state
:
any
)
{
return
'line-background-finesse'
;
},
token
:
function
(
stream
:
any
,
state
:
any
)
{
token
:
function
(
stream
:
CodeMirror
.
StringStream
,
state
:
any
)
{
return
state
.
tokenize
(
stream
,
state
);
}
};
});
CodeMirror
.
defineMIME
(
'text/x-finesse2'
,
'finesse2'
);
cm
.
defineMIME
(
'text/x-finesse2'
,
'finesse2'
);
}
src/codemirror-my-multiplex.d.ts
View file @
30fda89e
import
{
ICodeMirror
}
from
'@jupyterlab/codemirror'
;
declare
module
'codemirror'
{
function
myMultiplexingMode
(
outer
:
any
,
...
others
:
any
):
any
}
export
function
defineMultiplexingMode
(
CodeMirror
:
any
,
codemirror
:
ICodeMirror
,
):
void
src/codemirror-my-multiplex.js
View file @
30fda89e
...
...
@@ -5,8 +5,9 @@
// original blankLine function doesn't return the style returned by its
// sub-modes, so we have to copy the whole thing in here -_-
export
function
defineMultiplexingMode
(
CodeMirror
)
{
CodeMirror
.
myMultiplexingMode
=
function
(
outer
/*, others */
)
{
export
function
defineMultiplexingMode
(
codemirror
)
{
const
cm
=
codemirror
.
CodeMirror
;
cm
.
myMultiplexingMode
=
function
(
outer
/*, others */
)
{
// Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects
var
others
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
...
...
@@ -22,7 +23,7 @@ export function defineMultiplexingMode(CodeMirror) {
return
{
startState
:
function
()
{
return
{
outer
:
CodeMirror
.
startState
(
outer
),
outer
:
cm
.
startState
(
outer
),
innerActive
:
null
,
inner
:
null
,
startingInner
:
false
...
...
@@ -31,11 +32,11 @@ export function defineMultiplexingMode(CodeMirror) {
copyState
:
function
(
state
)
{
return
{
outer
:
CodeMirror
.
copyState
(
outer
,
state
.
outer
),
outer
:
cm
.
copyState
(
outer
,
state
.
outer
),
innerActive
:
state
.
innerActive
,
inner
:
state
.
innerActive
&&
CodeMirror
.
copyState
(
state
.
innerActive
.
mode
,
state
.
inner
),
cm
.
copyState
(
state
.
innerActive
.
mode
,
state
.
inner
),
startingInner
:
state
.
startingInner
};
},
...
...
@@ -52,15 +53,15 @@ export function defineMultiplexingMode(CodeMirror) {
state
.
startingInner
=
!!
other
.
parseDelimiters
;
state
.
innerActive
=
other
;
// Get the outer indent, making sure to handle
CodeMirror
.Pass
// Get the outer indent, making sure to handle
cm
.Pass
var
outerIndent
=
0
;
if
(
outer
.
indent
)
{
var
possibleOuterIndent
=
outer
.
indent
(
state
.
outer
,
''
,
''
);
if
(
possibleOuterIndent
!==
CodeMirror
.
Pass
)
if
(
possibleOuterIndent
!==
cm
.
Pass
)
outerIndent
=
possibleOuterIndent
;
}
state
.
inner
=
CodeMirror
.
startState
(
other
.
mode
,
outerIndent
);
state
.
inner
=
cm
.
startState
(
other
.
mode
,
outerIndent
);
return
(
other
.
delimStyle
&&
other
.
delimStyle
+
' '
+
other
.
delimStyle
+
'-open'
...
...
@@ -116,7 +117,7 @@ export function defineMultiplexingMode(CodeMirror) {
indent
:
function
(
state
,
textAfter
,
line
)
{
var
mode
=
state
.
innerActive
?
state
.
innerActive
.
mode
:
outer
;
if
(
!
mode
.
indent
)
return
CodeMirror
.
Pass
;
if
(
!
mode
.
indent
)
return
cm
.
Pass
;
return
mode
.
indent
(
state
.
innerActive
?
state
.
inner
:
state
.
outer
,
textAfter
,
...
...
@@ -135,7 +136,7 @@ export function defineMultiplexingMode(CodeMirror) {
var
other
=
others
[
i
];
if
(
other
.
open
===
'
\
n'
)
{
state
.
innerActive
=
other
;
state
.
inner
=
CodeMirror
.
startState
(
state
.
inner
=
cm
.
startState
(
other
.
mode
,
mode
.
indent
?
mode
.
indent
(
state
.
outer
,
''
,
''
)
:
0
);
...
...
src/index.ts
View file @
30fda89e
...
...
@@ -26,8 +26,8 @@ function activate(
app
:
JupyterFrontEnd
,
tracker
:
INotebookTracker
,
codemirror
:
ICodeMirror
)
{
setupFinesseCodeMirror
(
codemirror
.
CodeMirror
);
)
:
void
{
setupFinesseCodeMirror
(
codemirror
);
const
style
=
document
.
createElement
(
'style'
);
style
.
type
=
'text/css'
;
style
.
innerHTML
=
'.finesse { background-color: rgba(0, 0, 0, 0.04); }'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment