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
0fce839d
Commit
0fce839d
authored
Jan 20, 2020
by
Phil Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add finesse2 syntax highlighting.
parent
29634d18
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
186 additions
and
5 deletions
+186
-5
codemirror-finesse.ts
src/codemirror-finesse.ts
+185
-4
index.ts
src/index.ts
+1
-1
No files found.
src/codemirror-finesse.ts
View file @
0fce839d
...
...
@@ -8,18 +8,199 @@ import 'codemirror/mode/python/python';
import
'codemirror/addon/mode/multiplex'
;
declare
module
'codemirror'
{
function
multiplexingMode
(
x
:
CodeMirror
.
Mode
<
any
>
,
...
others
:
object
[]):
CodeMirror
.
Mode
<
any
>
;
var
modeInfo
:
any
[];
// There should be a better way to do this to stop typescript
// complaining....
function
multiplexingMode
(
outerMode
:
CodeMirror
.
Mode
<
any
>
,
...
others
:
object
[]):
CodeMirror
.
Mode
<
any
>
;
}
const
components
=
[
'bs[12]
\
?'
,
'dbs'
,
'gr
\
d*'
,
'isol'
,
'l'
,
'lens'
,
'm[12]
\
?'
,
'mod'
,
's'
,
'sq'
,
]
const
detectors
=
[
'ad'
,
'beam'
,
'bp'
,
'cp'
,
'guoy'
,
'hd'
,
'pd[SN]
\
?
\
d*'
,
'pgaind'
,
'qd'
,
'q
\
d*hd
\
?'
,
'qhd[SN]
\
?'
,
'qnoised[SN]
\
?'
,
'qshot'
,
'qshot[SN]
\
?'
,
'sd'
,
'xd'
,
]
const
commands
=
[
'attr'
,
'cav'
,
'conf'
,
'fadd'
,
'fsig'
,
'gauss'
,
'knm'
,
'lambda'
,
'map'
,
'mask'
,
'maxtem'
,
'pdtype'
,
'phase'
,
'retrace'
,
'smotion'
,
'startnode'
,
'tem'
,
'tf2
\
?'
,
'vacuum'
,
// Plotting:
'const'
,
'deriv_h'
,
'diff'
,
'func'
,
'lock'
,
'noplot'
,
'noxaxis'
,
'put'
,
'scale'
,
'set'
,
'trace'
,
'var'
,
'x2
\
?axis'
,
'yaxis'
,
// Auxiliary
'gnuterm'
,
'multi'
,
'pause'
,
'pyterm'
,
]
function
wordListRegexp
(
words
:
string
[]):
RegExp
{
return
new
RegExp
(
"^(("
+
words
.
join
(
")|("
)
+
"))
\\
b"
);
}
const
regex
=
{
"command"
:
wordListRegexp
(
commands
),
"component"
:
wordListRegexp
(
components
),
"detector"
:
wordListRegexp
(
detectors
),
"name"
:
/
[
a
-
zA
-
Z_
][
a
-
zA
-
Z0
-
9
_
-
]
/
,
"number"
:
/^
(([
+-
]?
inf
)
|
([
+-
]?(
\
d
+
\
.
\
d
*|
\
d
*
\
.
\
d
+|
\
d
+
)([
eE
]
-
?
\
d
*
\
.?
\
d
*
)?
j
?([
pnumkMGT
])?))
$
/
,
"variable"
:
/
\$\w
+/
}
/*
* Available tokens:
*
* keyword
* atom
* number
* def
* variable
* variable-2
* variable-3
* property
* operator
* comment
* string
* string-2
* meta
* qualifier
* builtin
* bracket
* tag
* attribute
* header
* quote
* hr
* link
*/
CodeMirror
.
defineMode
(
"finesse2"
,
()
=>
{
function
tokenBase
(
stream
:
CodeMirror
.
StringStream
,
state
:
any
)
{
if
(
stream
.
sol
())
{
state
.
firstOnLine
=
true
;
}
if
(
stream
.
eatSpace
())
{
return
null
;
}
if
(
/
[
#%
]
/
.
test
(
stream
.
peek
()))
{
stream
.
skipToEnd
();
return
"comment"
;
}
if
(
stream
.
peek
()
==
'$'
)
{
stream
.
next
();
}
stream
.
eatWhile
(
/
\w
/
);
let
style
=
null
;
let
cur
=
stream
.
current
();
//console.log(cur, state.prevToken);
if
(
state
.
firstOnLine
)
{
if
(
regex
[
"component"
].
test
(
cur
)
||
regex
[
"detector"
].
test
(
cur
))
{
// Component definition
style
=
"keyword"
;
}
else
if
(
regex
[
"command"
].
test
(
cur
))
{
// Command
style
=
"builtin"
;
}
}
else
if
(
state
.
prevToken
==
"keyword"
&&
regex
[
"name"
].
test
(
cur
))
{
// Component name
style
=
"def"
;
}
else
if
(
regex
[
"number"
].
test
(
cur
))
{
// Number
style
=
"number"
;
}
else
if
(
regex
[
"variable"
].
test
(
cur
))
{
style
=
"variable-2"
;
}
if
(
style
!=
null
)
{
state
.
firstOnLine
=
false
;
state
.
prevToken
=
style
;
return
style
;
}
stream
.
next
();
}
return
<
CodeMirror
.
Mode
<
any
>>
{
startState
:
function
()
{
return
{
tokenize
:
tokenBase
,
firstOnLine
:
true
,
prevToken
:
<
string
>
null
};
},
token
:
function
(
stream
,
state
)
{
return
state
.
tokenize
(
stream
,
state
)
}
};
});
CodeMirror
.
defineMIME
(
"text/x-finesse2"
,
"finesse2"
);
CodeMirror
.
defineMode
(
"finesse-python"
,
(
config
)
=>
{
let
pmode
=
CodeMirror
.
getMode
(
config
,
"python"
);
return
CodeMirror
.
multiplexingMode
(
pmode
,
{
open
:
/
#katcode
/
,
open
:
/
(?=
#kat2code
)
/
,
close
:
/
(?=
"""
)
/
,
// Match string end without consuming it
mode
:
CodeMirror
.
getMode
(
config
,
"text/
html
"
),
mode
:
CodeMirror
.
getMode
(
config
,
"text/
x-finesse2
"
),
delimStyle
:
"delim"
}
)
...
...
src/index.ts
View file @
0fce839d
...
...
@@ -44,7 +44,7 @@ function activate_finesse(sender: INotebookTracker, panel: NotebookPanel): void
// I ain't proud of this, but it's the sanest way I could find to get
// the syntax highlighting to change on startup without selecting a
// different cell
setTimeout
(()
=>
{
check_all
(
panel
.
content
)},
10
00
);
setTimeout
(()
=>
{
check_all
(
panel
.
content
)},
5
00
);
};
export
default
plugin
;
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