{----
- String.hs - String parsing specialization of PosParse
----
- Author: Jesse Rudolph <jesse.rudolph@gmail.com>
- See LICENSE for licensing details
----------------------------------------------------------------- -}moduleLanguage.Noodle.Parsing.String(moduleLanguage.Noodle.Parsing.String,moduleLanguage.Noodle.Parsing.Positional)whereimportqualifiedLanguage.Noodle.Parsing.PositionalasP(getTok,getTokIf)importLanguage.Noodle.Parsing.Positionalhiding(getTok,getTokIf)-- we hide these to make it hard to break automatic position update{-- since the type of our tokens is known to be an instance of Show,
- we can make primative error messages a little more descriptive --}{-- INVARIANT: all parsers based on combinators and primative parsers,
- exported from CharParser should correctly update position automatically --}-- a specialization of the PosParser type that fills in the token type as ChartypeParserstres=PosParserstCharres-- parse one character and return it if it matches cchar::Char->ParserstCharcharc=satisfy(==c)<|>fail("expected "++showc)-- parse one character and return it if predicate succeedssatisfy::(Char->Bool)->ParserstCharsatisfyf=doc<-P.getTokIffcasecof'\n'->incLine_->incPosreturnc-- parse the first character in the listoneOf::[Char]->ParserstCharoneOf[]=error"violated invariant: 'oneOf []' is undefined"oneOfcs=choice(mapcharcs)-- parse string matching s and return itstring::String->ParserstStringstrings=mapM(char)s-- parse one of either a space, tab, newline, or carriage return, and return itwhiteChar::ParserstCharwhiteChar=char' '<|>char'\t'<|>char'\n'<|>char'\r'-- parse zero or more occurances of whiteCharwhiteSpace::ParserstStringwhiteSpace=manywhiteChar-- parse lowercase aphabetical charactersalphaLower::ParserstCharalphaLower=oneOf['a'..'z']-- parse uppercase alphabetical charactersalphaUpper::ParserstCharalphaUpper=oneOf['A'..'Z']-- parse numberical charactersdigit::ParserstChardigit=oneOf['0'..'9']