Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CodeMirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
CodeMirror
Commits
28bc0e03
Commit
28bc0e03
authored
9 years ago
by
pabloferz
Committed by
Marijn Haverbeke
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[julia mode] String, function calls and definitions improvements
parent
4b0229d1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mode/julia/julia.js
+78
-18
78 additions, 18 deletions
mode/julia/julia.js
with
78 additions
and
18 deletions
mode/julia/julia.js
+
78
−
18
View file @
28bc0e03
...
...
@@ -69,12 +69,12 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
}
// Handle scope changes
var
leaving
_e
xpr
=
state
.
leaving
_e
xpr
;
var
leaving
E
xpr
=
state
.
leaving
E
xpr
;
if
(
stream
.
sol
())
{
leaving
_e
xpr
=
false
;
leaving
E
xpr
=
false
;
}
state
.
leaving
_e
xpr
=
false
;
if
(
leaving
_e
xpr
)
{
state
.
leaving
E
xpr
=
false
;
if
(
leaving
E
xpr
)
{
if
(
stream
.
match
(
/^'+/
))
{
return
'
operator
'
;
}
...
...
@@ -108,16 +108,16 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
if
(
scope
===
'
[
'
&&
ch
===
'
]
'
)
{
state
.
scopes
.
pop
();
state
.
leaving
_e
xpr
=
true
;
state
.
leaving
E
xpr
=
true
;
}
if
(
scope
===
'
{
'
&&
ch
===
'
}
'
)
{
state
.
scopes
.
pop
();
state
.
leaving
_e
xpr
=
true
;
state
.
leaving
E
xpr
=
true
;
}
if
(
ch
===
'
)
'
)
{
state
.
leaving
_e
xpr
=
true
;
state
.
leaving
E
xpr
=
true
;
}
var
match
;
...
...
@@ -142,7 +142,6 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return
'
operator
'
;
}
// Handle Number Literals
if
(
stream
.
match
(
/^
[
0-9
\.]
/
,
false
))
{
var
imMatcher
=
RegExp
(
/^im
\b
/
);
...
...
@@ -155,7 +154,7 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
if
(
floatLiteral
)
{
// Float literals may be "imaginary"
stream
.
match
(
imMatcher
);
state
.
leaving
_e
xpr
=
true
;
state
.
leaving
E
xpr
=
true
;
return
'
number
'
;
}
// Integers
...
...
@@ -175,7 +174,7 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
if
(
intLiteral
)
{
// Integer literals may be "long"
stream
.
match
(
imMatcher
);
state
.
leaving
_e
xpr
=
true
;
state
.
leaving
E
xpr
=
true
;
return
'
number
'
;
}
}
...
...
@@ -189,7 +188,7 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
}
// Handle symbols
if
(
!
leaving
_e
xpr
&&
stream
.
match
(
symbol
))
{
if
(
!
leaving
E
xpr
&&
stream
.
match
(
symbol
))
{
return
'
builtin
'
;
}
...
...
@@ -225,8 +224,25 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return
'
builtin
'
;
}
var
isDefinition
=
state
.
isDefinition
||
state
.
lastToken
==
'
function
'
||
state
.
lastToken
==
'
macro
'
||
state
.
lastToken
==
'
type
'
||
state
.
lastToken
==
'
immutable
'
;
if
(
stream
.
match
(
identifiers
))
{
state
.
leaving_expr
=
true
;
if
(
isDefinition
)
{
if
(
stream
.
peek
()
===
'
.
'
)
{
state
.
isDefinition
=
true
;
return
'
variable
'
;
}
state
.
isDefinition
=
false
;
return
'
def
'
;
}
if
(
stream
.
match
(
/^
(
{
[^
}
]
*}
)
*
\(
/
,
false
))
{
return
callOrDef
(
stream
,
state
);
}
state
.
leavingExpr
=
true
;
return
'
variable
'
;
}
...
...
@@ -235,11 +251,47 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return
ERRORCLASS
;
}
function
callOrDef
(
stream
,
state
)
{
var
match
=
stream
.
match
(
/^
(\(\s
*
)
/
);
if
(
match
)
{
if
(
state
.
firstParenPos
<
0
)
state
.
firstParenPos
=
state
.
scopes
.
length
;
state
.
scopes
.
push
(
'
(
'
);
state
.
charsAdvanced
+=
match
[
1
].
length
;
}
if
(
currentScope
(
state
)
==
'
(
'
&&
stream
.
match
(
/^
\)
/
))
{
state
.
scopes
.
pop
();
state
.
charsAdvanced
+=
1
;
if
(
state
.
scopes
.
length
<=
state
.
firstParenPos
)
{
var
isDefinition
=
stream
.
match
(
/^
\s
*
?
=
(?!
=
)
/
,
false
);
stream
.
backUp
(
state
.
charsAdvanced
);
state
.
firstParenPos
=
-
1
;
state
.
charsAdvanced
=
0
;
if
(
isDefinition
)
return
'
def
'
;
return
'
builtin
'
;
}
}
// Unfortunately javascript does not support multiline strings, so we have
// to undo anything done upto here if a function call or definition splits
// over two or more lines.
if
(
stream
.
match
(
/^$/g
,
false
))
{
stream
.
backUp
(
state
.
charsAdvanced
);
while
(
state
.
scopes
.
length
>
state
.
firstParenPos
+
1
)
state
.
scopes
.
pop
();
state
.
firstParenPos
=
-
1
;
state
.
charsAdvanced
=
0
;
return
'
variable
'
;
}
state
.
charsAdvanced
+=
stream
.
match
(
/^
([^
()
]
*
)
/
)[
1
].
length
;
return
callOrDef
(
stream
,
state
);
}
function
tokenStringFactory
(
delimiter
)
{
while
(
'
ru
b
'
.
indexOf
(
delimiter
.
charAt
(
0
).
toLowerCase
())
>=
0
)
{
while
(
'
b
ru
v
'
.
indexOf
(
delimiter
.
charAt
(
0
).
toLowerCase
())
>=
0
)
{
delimiter
=
delimiter
.
substr
(
1
);
}
var
singleline
=
delimiter
.
length
==
1
;
var
singleline
=
delimiter
==
"
'
"
;
var
OUTCLASS
=
'
string
'
;
function
tokenString
(
stream
,
state
)
{
...
...
@@ -274,9 +326,14 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
var
style
=
state
.
tokenize
(
stream
,
state
);
var
current
=
stream
.
current
();
if
(
current
&&
style
)
{
state
.
lastToken
=
current
;
}
// Handle '.' connected identifiers
if
(
current
===
'
.
'
)
{
style
=
stream
.
match
(
identifiers
,
false
)
?
null
:
ERRORCLASS
;
style
=
stream
.
match
(
identifiers
,
false
)
||
stream
.
match
(
macro
,
false
)
?
null
:
ERRORCLASS
;
if
(
style
===
null
&&
state
.
lastStyle
===
'
meta
'
)
{
// Apply 'meta' style to '.' connected identifiers when
// appropriate.
...
...
@@ -284,7 +341,6 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
}
return
style
;
}
return
style
;
}
...
...
@@ -293,7 +349,11 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
return
{
tokenize
:
tokenBase
,
scopes
:
[],
leaving_expr
:
false
lastToken
:
null
,
leavingExpr
:
false
,
isDefinition
:
false
,
charsAdvanced
:
0
,
firstParenPos
:
-
1
};
},
...
...
@@ -305,7 +365,7 @@ CodeMirror.defineMode("julia", function(_conf, parserConf) {
indent
:
function
(
state
,
textAfter
)
{
var
delta
=
0
;
if
(
textAfter
==
"
end
"
||
textAfter
==
"
]
"
||
textAfter
==
"
}
"
||
textAfter
==
"
else
"
||
textAfter
==
"
elseif
"
||
textAfter
==
"
catch
"
||
textAfter
==
"
finally
"
)
{
if
(
textAfter
==
"
end
"
||
textAfter
==
"
]
"
||
textAfter
==
"
}
"
||
textAfter
==
"
else
"
||
textAfter
==
"
elseif
"
||
textAfter
==
"
catch
"
||
textAfter
==
"
finally
"
)
{
delta
=
-
1
;
}
return
(
state
.
scopes
.
length
+
delta
)
*
_conf
.
indentUnit
;
...
...
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