git @ Cat's Eye Technologies Falderal / 1db0246
Parse Functionality-defintion pragmas. catseye 13 years ago
2 changed file(s) with 27 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
3232 > parseBits ('\n':rest) = parseBits rest
3333
3434 > showParseBits = show . parseBits
35
36 Pragmas should be able extend over multiple lines, just like anything else.
37 But they can't currently.
38
39 -> Functionality "Retain every second character" is implemented by Haskell function Test.Falderal.Demo:everySecond
3540
3641 Tests for everySecond
3742 ---------------------
175175 parsePragma text =
176176 case consumeWords ["Tests", "for"] text of
177177 Just rest ->
178 tryFunctionalities functionalities rest
178 TestsFor $ tryFunctionalities functionalities rest
179179 Nothing ->
180180 case consumeWords ["Functionality"] text of
181181 Just rest ->
201201 let
202202 (moduleName, functionName) = parseSpecifier specifier
203203 in
204 Just $ TestsFor $ HaskellTest moduleName functionName
204 Just $ HaskellTest moduleName functionName
205205 Nothing ->
206206 Nothing
207207
208208 parseShellFunctionality text =
209209 case consumeWords ["shell", "command"] text of
210210 Just specifier ->
211 Just $ TestsFor $ ShellTest $ parseQuotedString specifier
211 let
212 (command, _) = parseQuotedString specifier
213 in
214 Just $ ShellTest command
212215 Nothing ->
213216 Nothing
214217
220223
221224 parseFuncDefn text =
222225 let
223 x = parseQuotedString text
224 -- XXX wow, so incomplete
225 in
226 FunctionalityDefinition text $ HaskellTest "GUH" ""
226 (name, rest) = parseQuotedString text
227 in
228 case consumeWords ["is", "implemented", "by"] rest of
229 Just funky ->
230 let
231 functionality = tryFunctionalities functionalities funky
232 in
233 FunctionalityDefinition text functionality
234 Nothing ->
235 error $ "bad functionality definition: " ++ text
236
227237
228238 parseQuotedString ('"':rest) =
229239 parseQuotedString' rest
231241 error $ "bad quoted string: " ++ str
232242
233243 parseQuotedString' ('"':rest) =
234 ""
244 ("", rest)
235245 parseQuotedString' (char:rest) =
236 (char:parseQuotedString' rest)
246 let
247 (next, remainder) = parseQuotedString' rest
248 in
249 (char:next, remainder)
237250
238251 consumeWords [] text =
239252 Just $ stripLeadingWhitespace text