Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sv2v
Overview
Overview
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
lvzhengyang
sv2v
Commits
82290b16
Commit
82290b16
authored
Nov 27, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify lexer character position lookup
parent
2e499dbd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
10 deletions
+4
-10
src/Language/SystemVerilog/Parser/Lex.x
+4
-10
No files found.
src/Language/SystemVerilog/Parser/Lex.x
View file @
82290b16
...
...
@@ -475,7 +475,7 @@ tokens :-
-- our custom lexer state
data
AlexUserState
=
LS
{
lsToks
::
[
Token
]
-- tokens read so far, *in reverse order* for efficiency
,
lsPositions
::
[
Position
]
-- character positions
in reverse order
,
lsPositions
::
[
Position
]
-- character positions
}
deriving
(
Eq
,
Show
)
-- this initial user state does not contain the initial token positions; alex
...
...
@@ -487,7 +487,7 @@ alexInitUserState = LS [] []
-- lexer entrypoint
lexStr
::
String
->
[
Position
]
->
IO
(
Either
String
[
Token
])
lexStr
chars
positions
=
do
let
setEnv
=
modify
$
\
s
->
s
{
lsPositions
=
reverse
positions
}
let
setEnv
=
modify
$
\
s
->
s
{
lsPositions
=
positions
}
let
result
=
runAlex
chars
$
setEnv
>>
alexMonadScan
>>
get
return
$
case
result
of
Left
msg
->
Left
msg
...
...
@@ -540,16 +540,10 @@ modify f = Alex func
where
func
s
=
Right
(
s
{
alex_ust
=
new
},
()
)
where
new
=
f
(
alex_ust
s
)
getPosition
::
Int
->
Alex
Position
getPosition
lookback
=
do
(
_
,
_
,
_
,
str
)
<-
alexGetInput
positions
<-
get
>>=
return
.
lsPositions
return
$
positions
!!
(
lookback
+
length
str
)
tok
::
TokenName
->
AlexInput
->
Int
->
Alex
()
tok
tokId
(
_
,
_
,
_
,
input
)
len
=
do
tok
tokId
(
AlexPn
pos
_
_
,
_
,
_
,
input
)
len
=
do
let
tokStr
=
take
len
input
tokPos
<-
get
Position
(
len
-
1
)
tokPos
<-
get
>>=
return
.
(
!!
pos
)
.
lsPositions
let
t
=
Token
tokId
tokStr
tokPos
modify
$
\
s
->
s
{
lsToks
=
t
:
(
lsToks
s
)
}
alexMonadScan
...
...
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