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
eba994a1
Commit
eba994a1
authored
8 years ago
by
Marijn Haverbeke
Browse files
Options
Downloads
Patches
Plain Diff
Use an ES6 class for StringStream
parent
7dad9d59
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
src/util/StringStream.js
+31
-31
31 additions, 31 deletions
src/util/StringStream.js
with
31 additions
and
31 deletions
src/util/StringStream.js
+
31
−
31
View file @
eba994a1
...
...
@@ -5,57 +5,57 @@ import { countColumn } from "./misc"
// Fed to the mode parsers, provides helper functions to make
// parsers more succinct.
let
StringStream
=
function
(
string
,
tabSize
)
{
this
.
pos
=
this
.
start
=
0
this
.
string
=
string
this
.
tabSize
=
tabSize
||
8
this
.
lastColumnPos
=
this
.
lastColumnValue
=
0
this
.
lineStart
=
0
}
class
StringStream
{
constructor
(
string
,
tabSize
)
{
this
.
pos
=
this
.
start
=
0
this
.
string
=
string
this
.
tabSize
=
tabSize
||
8
this
.
lastColumnPos
=
this
.
lastColumnValue
=
0
this
.
lineStart
=
0
}
StringStream
.
prototype
=
{
eol
:
function
()
{
return
this
.
pos
>=
this
.
string
.
length
},
sol
:
function
()
{
return
this
.
pos
==
this
.
lineStart
},
peek
:
function
()
{
return
this
.
string
.
charAt
(
this
.
pos
)
||
undefined
},
next
:
function
()
{
eol
()
{
return
this
.
pos
>=
this
.
string
.
length
}
sol
()
{
return
this
.
pos
==
this
.
lineStart
}
peek
()
{
return
this
.
string
.
charAt
(
this
.
pos
)
||
undefined
}
next
()
{
if
(
this
.
pos
<
this
.
string
.
length
)
return
this
.
string
.
charAt
(
this
.
pos
++
)
}
,
eat
:
function
(
match
)
{
}
eat
(
match
)
{
let
ch
=
this
.
string
.
charAt
(
this
.
pos
)
let
ok
if
(
typeof
match
==
"
string
"
)
ok
=
ch
==
match
else
ok
=
ch
&&
(
match
.
test
?
match
.
test
(
ch
)
:
match
(
ch
))
if
(
ok
)
{
++
this
.
pos
;
return
ch
}
}
,
eatWhile
:
function
(
match
)
{
}
eatWhile
(
match
)
{
let
start
=
this
.
pos
while
(
this
.
eat
(
match
)){}
return
this
.
pos
>
start
}
,
eatSpace
:
function
()
{
}
eatSpace
()
{
let
start
=
this
.
pos
while
(
/
[\s\u
00a0
]
/
.
test
(
this
.
string
.
charAt
(
this
.
pos
)))
++
this
.
pos
return
this
.
pos
>
start
}
,
skipToEnd
:
function
()
{
this
.
pos
=
this
.
string
.
length
}
,
skipTo
:
function
(
ch
)
{
}
skipToEnd
()
{
this
.
pos
=
this
.
string
.
length
}
skipTo
(
ch
)
{
let
found
=
this
.
string
.
indexOf
(
ch
,
this
.
pos
)
if
(
found
>
-
1
)
{
this
.
pos
=
found
;
return
true
}
}
,
backUp
:
function
(
n
)
{
this
.
pos
-=
n
}
,
column
:
function
()
{
}
backUp
(
n
)
{
this
.
pos
-=
n
}
column
()
{
if
(
this
.
lastColumnPos
<
this
.
start
)
{
this
.
lastColumnValue
=
countColumn
(
this
.
string
,
this
.
start
,
this
.
tabSize
,
this
.
lastColumnPos
,
this
.
lastColumnValue
)
this
.
lastColumnPos
=
this
.
start
}
return
this
.
lastColumnValue
-
(
this
.
lineStart
?
countColumn
(
this
.
string
,
this
.
lineStart
,
this
.
tabSize
)
:
0
)
}
,
indentation
:
function
()
{
}
indentation
()
{
return
countColumn
(
this
.
string
,
null
,
this
.
tabSize
)
-
(
this
.
lineStart
?
countColumn
(
this
.
string
,
this
.
lineStart
,
this
.
tabSize
)
:
0
)
}
,
match
:
function
(
pattern
,
consume
,
caseInsensitive
)
{
}
match
(
pattern
,
consume
,
caseInsensitive
)
{
if
(
typeof
pattern
==
"
string
"
)
{
let
cased
=
str
=>
caseInsensitive
?
str
.
toLowerCase
()
:
str
let
substr
=
this
.
string
.
substr
(
this
.
pos
,
pattern
.
length
)
...
...
@@ -69,9 +69,9 @@ StringStream.prototype = {
if
(
match
&&
consume
!==
false
)
this
.
pos
+=
match
[
0
].
length
return
match
}
}
,
current
:
function
(){
return
this
.
string
.
slice
(
this
.
start
,
this
.
pos
)}
,
hideFirstChars
:
function
(
n
,
inner
)
{
}
current
(){
return
this
.
string
.
slice
(
this
.
start
,
this
.
pos
)}
hideFirstChars
(
n
,
inner
)
{
this
.
lineStart
+=
n
try
{
return
inner
()
}
finally
{
this
.
lineStart
-=
n
}
...
...
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