Skip to content

Commit b9189e2

Browse files
committed
refactor the parser
1 parent a08246d commit b9189e2

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

lsp/src/Language/LSP/Server/Control.hs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,30 +187,20 @@ ioLoop ioLogger logger clientIn serverDefinition vfs sendMsg = do
187187
go (parse parser remainder)
188188

189189
parser = do
190-
_ <- string "Content-"
191-
len <- lengthFirst <|> typeFirst
192-
Attoparsec.take len
193-
194-
lengthFirst = do
195-
len <- headLength
190+
try contentType <|> (return ())
191+
len <- contentLength
192+
try contentType <|> (return ())
196193
_ <- string _ONE_CRLF
197-
<|> (headType >> string _ONE_CRLF)
198-
return len
199-
200-
typeFirst = do
201-
_ <- headType
202-
_ <- string "Content-"
203-
len <- headLength
204-
_ <- string _ONE_CRLF
205-
return len
194+
Attoparsec.take len
206195

207-
headLength = do
208-
_ <- string "Length: "
196+
contentLength = do
197+
_ <- string "Content-Length: "
209198
len <- decimal
210199
_ <- string _ONE_CRLF
211200
return len
212201

213-
headType = do
202+
contentType = do
203+
_ <- string "Content-Type: "
214204
skipWhile (/='\r')
215205
_ <- string _ONE_CRLF
216206
return ()

0 commit comments

Comments
 (0)