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
Show 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
{
defineMultiplexingMode
}
from
'./codemirror-my-multiplex'
;
import
{
defineFinesse2Mode
}
from
'./codemirror-finesse2'
;
import
{
defineFinesse2Mode
}
from
'./codemirror-finesse2'
;
export
function
setupFinesseCodeMirror
(
CodeMirror
:
any
):
void
{
export
function
setupFinesseCodeMirror
(
codemirror
:
ICodeMirror
):
void
{
defineMultiplexingMode
(
CodeMirror
);
const
cm
=
codemirror
.
CodeMirror
;
defineFinesse2Mode
(
CodeMirror
);
defineMultiplexingMode
(
codemirror
);
defineFinesse2Mode
(
codemirror
);
CodeMirror
.
defineMode
(
'finesse-python'
,
(
config
:
any
)
=>
{
cm
.
defineMode
(
'finesse-python'
,
(
config
:
any
)
=>
{
const
pmode
=
CodeMirror
.
getMode
(
config
,
'python'
);
const
pmode
=
cm
.
getMode
(
config
,
'python'
);
return
CodeMirror
.
myMultiplexingMode
(
pmode
,
{
return
cm
.
myMultiplexingMode
(
pmode
,
{
open
:
/
(?=
#kat2code
)
/
,
open
:
/
(?=
#kat2code
)
/
,
close
:
/
(?=
"""
)
/
,
// Match string end without consuming it
close
:
/
(?=
"""
)
/
,
// Match string end without consuming it
mode
:
CodeMirror
.
getMode
(
config
,
'text/x-finesse2'
),
mode
:
cm
.
getMode
(
config
,
'text/x-finesse2'
),
delimStyle
:
'delim'
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'
,
name
:
'Finesse Python'
,
mime
:
'text/x-finesse-python'
,
mime
:
'text/x-finesse-python'
,
mode
:
'finesse-python'
,
mode
:
'finesse-python'
,
...
...
src/codemirror-finesse2.ts
View file @
30fda89e
import
{
ICodeMirror
}
from
'@jupyterlab/codemirror'
;
const
components
=
[
const
components
=
[
'bs[12]?'
,
'bs[12]?'
,
'dbs'
,
'dbs'
,
...
@@ -117,8 +119,9 @@ const regex = {
...
@@ -117,8 +119,9 @@ const regex = {
* link
* link
*/
*/
export
function
defineFinesse2Mode
(
CodeMirror
:
any
):
void
{
export
function
defineFinesse2Mode
(
codemirror
:
ICodeMirror
):
void
{
CodeMirror
.
defineMode
(
'finesse2'
,
()
=>
{
const
cm
=
codemirror
.
CodeMirror
;
cm
.
defineMode
(
'finesse2'
,
()
=>
{
function
tokenBase
(
stream
:
CodeMirror
.
StringStream
,
state
:
any
)
{
function
tokenBase
(
stream
:
CodeMirror
.
StringStream
,
state
:
any
)
{
return
'line-background-finesse '
+
tokenLex
(
stream
,
state
);
return
'line-background-finesse '
+
tokenLex
(
stream
,
state
);
}
}
...
@@ -134,12 +137,12 @@ export function defineFinesse2Mode(CodeMirror: any): void {
...
@@ -134,12 +137,12 @@ export function defineFinesse2Mode(CodeMirror: any): void {
stream
.
skipToEnd
();
stream
.
skipToEnd
();
return
'comment'
;
return
'comment'
;
}
}
if
(
stream
.
peek
()
==
'$'
)
{
if
(
stream
.
peek
()
==
=
'$'
)
{
stream
.
next
();
stream
.
next
();
}
}
stream
.
eatWhile
(
/
[^\s]
/
);
stream
.
eatWhile
(
/
[^\s]
/
);
let
style
=
null
;
let
style
=
null
;
le
t
cur
=
stream
.
current
();
cons
t
cur
=
stream
.
current
();
if
(
state
.
firstOnLine
)
{
if
(
state
.
firstOnLine
)
{
if
(
regex
[
'component'
].
test
(
cur
)
||
regex
[
'detector'
].
test
(
cur
))
{
if
(
regex
[
'component'
].
test
(
cur
)
||
regex
[
'detector'
].
test
(
cur
))
{
...
@@ -163,7 +166,7 @@ export function defineFinesse2Mode(CodeMirror: any): void {
...
@@ -163,7 +166,7 @@ export function defineFinesse2Mode(CodeMirror: any): void {
}
else
if
(
regex
[
'variable'
].
test
(
cur
))
{
}
else
if
(
regex
[
'variable'
].
test
(
cur
))
{
style
=
'variable-2'
;
style
=
'variable-2'
;
}
}
if
(
style
!=
null
)
{
if
(
style
!=
=
null
)
{
state
.
firstOnLine
=
false
;
state
.
firstOnLine
=
false
;
return
style
;
return
style
;
}
}
...
@@ -181,11 +184,11 @@ export function defineFinesse2Mode(CodeMirror: any): void {
...
@@ -181,11 +184,11 @@ export function defineFinesse2Mode(CodeMirror: any): void {
blankLine
:
function
(
state
:
any
)
{
blankLine
:
function
(
state
:
any
)
{
return
'line-background-finesse'
;
return
'line-background-finesse'
;
},
},
token
:
function
(
stream
:
any
,
state
:
any
)
{
token
:
function
(
stream
:
CodeMirror
.
StringStream
,
state
:
any
)
{
return
state
.
tokenize
(
stream
,
state
);
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
(
export
function
defineMultiplexingMode
(
CodeMirror
:
any
,
codemirror
:
ICodeMirror
,
):
void
):
void
src/codemirror-my-multiplex.js
View file @
30fda89e
...
@@ -5,8 +5,9 @@
...
@@ -5,8 +5,9 @@
// original blankLine function doesn't return the style returned by its
// original blankLine function doesn't return the style returned by its
// sub-modes, so we have to copy the whole thing in here -_-
// sub-modes, so we have to copy the whole thing in here -_-
export
function
defineMultiplexingMode
(
CodeMirror
)
{
export
function
defineMultiplexingMode
(
codemirror
)
{
CodeMirror
.
myMultiplexingMode
=
function
(
outer
/*, others */
)
{
const
cm
=
codemirror
.
CodeMirror
;
cm
.
myMultiplexingMode
=
function
(
outer
/*, others */
)
{
// Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects
// Others should be {open, close, mode [, delimStyle] [, innerStyle]} objects
var
others
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
var
others
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
);
...
@@ -22,7 +23,7 @@ export function defineMultiplexingMode(CodeMirror) {
...
@@ -22,7 +23,7 @@ export function defineMultiplexingMode(CodeMirror) {
return
{
return
{
startState
:
function
()
{
startState
:
function
()
{
return
{
return
{
outer
:
CodeMirror
.
startState
(
outer
),
outer
:
cm
.
startState
(
outer
),
innerActive
:
null
,
innerActive
:
null
,
inner
:
null
,
inner
:
null
,
startingInner
:
false
startingInner
:
false
...
@@ -31,11 +32,11 @@ export function defineMultiplexingMode(CodeMirror) {
...
@@ -31,11 +32,11 @@ export function defineMultiplexingMode(CodeMirror) {
copyState
:
function
(
state
)
{
copyState
:
function
(
state
)
{
return
{
return
{
outer
:
CodeMirror
.
copyState
(
outer
,
state
.
outer
),
outer
:
cm
.
copyState
(
outer
,
state
.
outer
),
innerActive
:
state
.
innerActive
,
innerActive
:
state
.
innerActive
,
inner
:
inner
:
state
.
innerActive
&&
state
.
innerActive
&&
CodeMirror
.
copyState
(
state
.
innerActive
.
mode
,
state
.
inner
),
cm
.
copyState
(
state
.
innerActive
.
mode
,
state
.
inner
),
startingInner
:
state
.
startingInner
startingInner
:
state
.
startingInner
};
};
},
},
...
@@ -52,15 +53,15 @@ export function defineMultiplexingMode(CodeMirror) {
...
@@ -52,15 +53,15 @@ export function defineMultiplexingMode(CodeMirror) {
state
.
startingInner
=
!!
other
.
parseDelimiters
;
state
.
startingInner
=
!!
other
.
parseDelimiters
;
state
.
innerActive
=
other
;
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
;
var
outerIndent
=
0
;
if
(
outer
.
indent
)
{
if
(
outer
.
indent
)
{
var
possibleOuterIndent
=
outer
.
indent
(
state
.
outer
,
''
,
''
);
var
possibleOuterIndent
=
outer
.
indent
(
state
.
outer
,
''
,
''
);
if
(
possibleOuterIndent
!==
CodeMirror
.
Pass
)
if
(
possibleOuterIndent
!==
cm
.
Pass
)
outerIndent
=
possibleOuterIndent
;
outerIndent
=
possibleOuterIndent
;
}
}
state
.
inner
=
CodeMirror
.
startState
(
other
.
mode
,
outerIndent
);
state
.
inner
=
cm
.
startState
(
other
.
mode
,
outerIndent
);
return
(
return
(
other
.
delimStyle
&&
other
.
delimStyle
&&
other
.
delimStyle
+
' '
+
other
.
delimStyle
+
'-open'
other
.
delimStyle
+
' '
+
other
.
delimStyle
+
'-open'
...
@@ -116,7 +117,7 @@ export function defineMultiplexingMode(CodeMirror) {
...
@@ -116,7 +117,7 @@ export function defineMultiplexingMode(CodeMirror) {
indent
:
function
(
state
,
textAfter
,
line
)
{
indent
:
function
(
state
,
textAfter
,
line
)
{
var
mode
=
state
.
innerActive
?
state
.
innerActive
.
mode
:
outer
;
var
mode
=
state
.
innerActive
?
state
.
innerActive
.
mode
:
outer
;
if
(
!
mode
.
indent
)
return
CodeMirror
.
Pass
;
if
(
!
mode
.
indent
)
return
cm
.
Pass
;
return
mode
.
indent
(
return
mode
.
indent
(
state
.
innerActive
?
state
.
inner
:
state
.
outer
,
state
.
innerActive
?
state
.
inner
:
state
.
outer
,
textAfter
,
textAfter
,
...
@@ -135,7 +136,7 @@ export function defineMultiplexingMode(CodeMirror) {
...
@@ -135,7 +136,7 @@ export function defineMultiplexingMode(CodeMirror) {
var
other
=
others
[
i
];
var
other
=
others
[
i
];
if
(
other
.
open
===
'
\
n'
)
{
if
(
other
.
open
===
'
\
n'
)
{
state
.
innerActive
=
other
;
state
.
innerActive
=
other
;
state
.
inner
=
CodeMirror
.
startState
(
state
.
inner
=
cm
.
startState
(
other
.
mode
,
other
.
mode
,
mode
.
indent
?
mode
.
indent
(
state
.
outer
,
''
,
''
)
:
0
mode
.
indent
?
mode
.
indent
(
state
.
outer
,
''
,
''
)
:
0
);
);
...
...
src/index.ts
View file @
30fda89e
...
@@ -26,8 +26,8 @@ function activate(
...
@@ -26,8 +26,8 @@ function activate(
app
:
JupyterFrontEnd
,
app
:
JupyterFrontEnd
,
tracker
:
INotebookTracker
,
tracker
:
INotebookTracker
,
codemirror
:
ICodeMirror
codemirror
:
ICodeMirror
)
{
)
:
void
{
setupFinesseCodeMirror
(
codemirror
.
CodeMirror
);
setupFinesseCodeMirror
(
codemirror
);
const
style
=
document
.
createElement
(
'style'
);
const
style
=
document
.
createElement
(
'style'
);
style
.
type
=
'text/css'
;
style
.
type
=
'text/css'
;
style
.
innerHTML
=
'.finesse { background-color: rgba(0, 0, 0, 0.04); }'
;
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