Skip to content

Commit ca87ed0

Browse files
committed
extract/factor-out common code
1 parent ed1b851 commit ca87ed0

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

hs/BashParser.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ module BashParser (
77

88
import Control.Applicative (some, (<|>), many)
99
import Data.Maybe (catMaybes)
10-
import Text.Parsec (Parsec, char, string, noneOf, modifyState, endOfLine,
11-
getState, try, eof)
10+
import Text.Parsec (char, string, noneOf, modifyState, endOfLine, getState,
11+
try, eof)
1212

13-
import Utils (spaces, line, just, nothing)
13+
import Utils (StringParser, spaces, line, just, nothing)
1414

1515
type Path = String
1616
type Filename = String
1717

1818
data ParserState = ParserState Char Path
19-
type Parser = Parsec String ParserState
19+
type Parser = StringParser ParserState
2020

2121
ppath :: Parser String
2222
ppath = do

hs/Utils.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
module Utils (
2+
StringParser,
23
spaces,
34
line,
45
just,
56
nothing
67
) where
78

8-
import Text.Parsec (Stream, ParsecT, skipMany, char, noneOf, endOfLine,
9+
import Text.Parsec (Parsec, Stream, ParsecT, skipMany, char, noneOf, endOfLine,
910
manyTill)
1011

12+
type StringParser u = Parsec String u
13+
1114
spaces :: Stream s m Char => ParsecT s u m ()
1215
spaces = skipMany $ char ' '
1316

hs/Vflow.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import BashParser (Filename, Path)
1515
import qualified BashParser as B
1616
import VflowParser (Block(NewFile))
1717
import qualified VflowParser as V
18+
import Utils (StringParser)
1819

19-
parse :: Parsec String s a -> s -> Filename -> ExceptT ParseError IO a
20+
parse :: StringParser s a -> s -> Filename -> ExceptT ParseError IO a
2021
parse parser state filename = do
2122
content <- lift $ readFile filename
2223

hs/VflowParser.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import Control.Applicative ((<|>), many)
1515
import Data.Function ((&))
1616
import Data.Functor (void)
1717
import Data.Maybe (catMaybes)
18-
import Text.Parsec (Parsec, SourcePos, getState, getParserState, statePos,
19-
string, endOfLine, noneOf, char, optionMaybe, try, eof)
18+
import Text.Parsec (SourcePos, getState, getParserState, statePos, string,
19+
endOfLine, noneOf, char, optionMaybe, try, eof)
2020

21-
import Utils (spaces, line, just, nothing)
21+
import Utils (StringParser, spaces, line, just, nothing)
2222

2323
type HostLangComment = String
2424
type Indent = Int
2525
data ParserState = ParserState HostLangComment Indent Indent
26-
type Parser = Parsec String ParserState
26+
type Parser = StringParser ParserState
2727

2828
type Name = String
2929
type Comment = String

0 commit comments

Comments
 (0)