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
714c0575
Commit
714c0575
authored
12 years ago
by
Ken Rockot
Committed by
Marijn Haverbeke
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[scheme] implement correct parsing of all numeric formats defined in R5RS
parent
000d08a6
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/scheme/scheme.js
+59
-7
59 additions, 7 deletions
mode/scheme/scheme.js
with
59 additions
and
7 deletions
mode/scheme/scheme.js
+
59
−
7
View file @
714c0575
...
...
@@ -29,6 +29,30 @@ CodeMirror.defineMode("scheme", function (config, mode) {
state
.
indentStack
=
state
.
indentStack
.
prev
;
}
var
binaryMatcher
=
new
RegExp
(
/^
(?:[
-+
]
i|
[
-+
][
01
]
+#*
(?:\/[
01
]
+#*
)?
i|
[
-+
]?[
01
]
+#*
(?:\/[
01
]
+#*
)?
@
[
-+
]?[
01
]
+#*
(?:\/[
01
]
+#*
)?
|
[
-+
]?[
01
]
+#*
(?:\/[
01
]
+#*
)?[
-+
](?:[
01
]
+#*
(?:\/[
01
]
+#*
)?)?
i|
[
-+
]?[
01
]
+#*
(?:\/[
01
]
+#*
)?)(?=[
()
\s
;"
]
|$
)
/i
);
var
octalMatcher
=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+
\.\d
*#*|
\.\d
+#*|
\d
+
)(?:[
esfdl
][
-+
]?\d
+
)?)
|
\d
+#*
\/\d
+#*
)[
-+
](?:(?:(?:\d
+#+
\.?
#*|
\d
+
\.\d
*#*|
\.\d
+#*|
\d
+
)(?:[
esfdl
][
-+
]?\d
+
)?)
|
\d
+#*
\/\d
+#*
)?
i|
(?:(?:(?:\d
+#+
\.?
#*|
\d
+
\.\d
*#*|
\.\d
+#*|
\d
+
)(?:[
esfdl
][
-+
]?\d
+
)?)
|
\d
+#*
\/\d
+#*
))(?=[
()
\s
;"
]
|$
)
/i
);
function
isBinaryNumber
(
stream
)
{
return
stream
.
match
(
binaryMatcher
);
}
function
isOctalNumber
(
stream
)
{
return
stream
.
match
(
octalMatcher
);
}
function
isDecimalNumber
(
stream
,
backup
)
{
if
(
backup
===
true
)
{
stream
.
backUp
(
1
);
}
return
stream
.
match
(
decimalMatcher
);
}
function
isHexNumber
(
stream
)
{
return
stream
.
match
(
hexMatcher
);
}
return
{
startState
:
function
()
{
return
{
...
...
@@ -97,22 +121,50 @@ CodeMirror.defineMode("scheme", function (config, mode) {
}
else
if
(
ch
==
"
'
"
)
{
returnType
=
ATOM
;
}
else
if
(
ch
==
'
#
'
)
{
if
(
stream
.
eat
(
"
|
"
))
{
// Multi-line comment
if
(
stream
.
eat
(
"
|
"
))
{
// Multi-line comment
state
.
mode
=
"
comment
"
;
// toggle to comment mode
returnType
=
COMMENT
;
}
else
if
(
stream
.
eat
(
/
[
tf
]
/
))
{
// #t/#f (atom)
}
else
if
(
stream
.
eat
(
/
[
tf
]
/
i
))
{
// #t/#f (atom)
returnType
=
ATOM
;
}
else
if
(
stream
.
eat
(
'
;
'
))
{
// S-Expr comment
}
else
if
(
stream
.
eat
(
'
;
'
))
{
// S-Expr comment
state
.
mode
=
"
s-expr-comment
"
;
returnType
=
COMMENT
;
}
else
{
var
numTest
=
null
,
hasExactness
=
false
,
hasRadix
=
true
;
if
(
stream
.
eat
(
/
[
ei
]
/i
))
{
hasExactness
=
true
;
}
else
{
stream
.
backUp
(
1
);
// must be radix specifier
}
if
(
stream
.
match
(
/^#b/i
))
{
numTest
=
isBinaryNumber
;
}
else
if
(
stream
.
match
(
/^#o/i
))
{
numTest
=
isOctalNumber
;
}
else
if
(
stream
.
match
(
/^#x/i
))
{
numTest
=
isHexNumber
;
}
else
if
(
stream
.
match
(
/^#d/i
))
{
numTest
=
isDecimalNumber
;
}
else
if
(
stream
.
match
(
/^
[
-+0-9.
]
/
,
false
))
{
hasRadix
=
false
;
numTest
=
isDecimalNumber
;
// re-consume the intial # if all matches failed
}
else
if
(
!
hasExactness
)
{
stream
.
eat
(
'
#
'
);
}
if
(
numTest
!=
null
)
{
if
(
hasRadix
&&
!
hasExactness
)
{
// consume optional exactness after radix
stream
.
match
(
/^#
[
ei
]
/i
);
}
if
(
numTest
(
stream
))
returnType
=
NUMBER
;
}
}
}
else
if
(
/^
[
-+0-9.
]
/
.
test
(
ch
)
&&
isDecimalNumber
(
stream
,
true
))
{
// match non-prefixed number, must be decimal
returnType
=
NUMBER
;
}
else
if
(
ch
==
"
;
"
)
{
// comment
stream
.
skipToEnd
();
// rest of the line is a comment
returnType
=
COMMENT
;
}
else
if
(
/
\d
/
.
test
(
ch
)
&&
stream
.
match
(
/$|^
\d
*
(?:\/\d
+|
(?:\.\d
+
)?(?:[
eE
][
+
\-]?\d
+
)?)\b
/
)
||
ch
==
"
-
"
&&
stream
.
match
(
/^
\d
+
(?:\/\d
+|
(?:\.\d
+
)?(?:[
eE
][
+
\-]?\d
+
)?)\b
/
))
{
returnType
=
NUMBER
;
}
else
if
(
ch
==
"
(
"
||
ch
==
"
[
"
)
{
var
keyWord
=
''
;
var
indentTemp
=
stream
.
column
();
/**
...
...
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