Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
Packages
Cabal
Commits
732627ed
Commit
732627ed
authored
Jun 13, 2007
by
nominolo@gmail.com
Browse files
add line numbers to all field times
parent
18abf62a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Distribution/ParseUtils.hs
View file @
732627ed
...
...
@@ -47,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module
Distribution.ParseUtils
(
LineNo
,
PError
(
..
),
PWarning
,
locatedErrorMsg
,
syntaxError
,
warning
,
runP
,
ParseResult
(
..
),
Field
(
..
),
Field
(
..
),
fName
,
lineNo
,
FieldDescr
(
..
),
readFields
,
parseFilePathQ
,
parseTokenQ
,
parseModuleNameQ
,
parseDependency
,
parseOptVersion
,
...
...
@@ -182,11 +182,18 @@ trimTrailingSpaces = reverse . dropWhile isSpace . reverse
dropSpaces
::
String
->
String
dropSpaces
=
dropWhile
isSpace
data
Field
=
F
LineNo
String
String
|
Section
String
String
[
Field
]
|
IfBlock
String
[
Field
]
[
Field
]
deriving
(
Show
,
Eq
)
-- for testing
data
Field
=
F
LineNo
String
String
|
Section
LineNo
String
String
[
Field
]
|
IfBlock
LineNo
String
[
Field
]
[
Field
]
deriving
(
Show
,
Eq
)
-- for testing
lineNo
::
Field
->
LineNo
lineNo
(
F
n
_
_
)
=
n
lineNo
(
Section
n
_
_
_
)
=
n
lineNo
(
IfBlock
n
_
_
_
)
=
n
fName
(
F
_
n
_
)
=
n
-- sectionname ::= "library" | "executable"
sectionNames
::
[
String
]
...
...
@@ -260,7 +267,7 @@ getIf (n,rest) lines = do
(
cond
,
_
)
->
-- condition spans more than one line
syntaxError
n
"Multi-line conditions currently not supported."
(
elseBlock
,
lines''
)
<-
tryElseBlock
lines'
return
(
Just
$
IfBlock
cond
ifBlock
elseBlock
,
lines''
)
return
(
Just
$
IfBlock
n
cond
ifBlock
elseBlock
,
lines''
)
where
tryElseBlock
[]
=
return
(
[]
,
[]
)
tryElseBlock
((
n
,
l
)
:
ls
)
=
...
...
@@ -310,7 +317,7 @@ getSection sectName (n,l) lines =
case
break
(
==
'{'
)
(
dropSpaces
l
)
of
(
sectLabel
,
'{'
:
rest
)
->
do
(
b
,
lines'
)
<-
getBlock
(
n
,
'{'
:
rest
)
lines
return
(
Just
$
Section
sectName
sectLabel
b
,
lines'
)
return
(
Just
$
Section
n
sectName
(
trimTrailingSpaces
sectLabel
)
b
,
lines'
)
-- Get the field value of a field at given indentation
getFieldValue
::
Int
->
String
->
[(
Int
,
String
)]
...
...
@@ -477,22 +484,22 @@ test_readFields = case readFields testFile of
[
F
1
"cabal-version"
"3"
,
F
3
"description"
"This is a test file
\n
with a description longer than two lines."
,
IfBlock
"os(windows) "
,
IfBlock
5
"os(windows) "
[
F
6
"license"
"You may not use this software
\n\n
If you do use this software you will be seeked and destroyed."
]
[]
,
IfBlock
"os(linux) "
,
IfBlock
10
"os(linux) "
[
F
11
"main-is"
"foo1"
]
[ ]
,
IfBlock
"os(vista) "
[
Section
"executable"
"RootKit "
,
IfBlock
14
"os(vista) "
[
Section
15
"executable"
"RootKit "
[
F
16
"main-is"
"DRMManager.hs"
]
]
[
Section
"executable"
"VistaRemoteAccess "
[
Section
19
"executable"
"VistaRemoteAccess "
[
F
20
"main-is"
"VCtrl"
]
]
,
Section
"executable"
"Foo-bar "
,
Section
23
"executable"
"Foo-bar "
[
F
24
"main-is"
"Foo.hs"
]
]
...
...
Write
Preview
Supports
Markdown
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