on master help sign in
Text.Lexer: use opt instead of (<|> Empty)
commit4772454395b08b614d51cf25032782d7a8f5acaa authorMichael Morgan <morgan.michael@me.com> dateSun 27 Aug 2017, 22:20 (9 years ago) parent2700cef
1 file changed+5−8
libs/contrib/Text/Lexer.idr+5−8
libs/contrib/Text/Lexer.idr+5−8
@@ -57,13 +57,13 @@ opt l = l <|> Empty
5757||| Recognise a sequence of at least one sub-lexers
5858export
5959some : Lexer -> Lexer
60−some l = l <+> (some l <|> Empty)
60+some l = l <+> opt (some l)
6161
6262||| Recognise a sequence of at zero or more sub-lexers. This is not
6363||| guaranteed to consume input
6464export
6565many : Lexer -> Recognise False
66−many l = some l <|> Empty
66+many l = opt (some l)
6767
6868||| Recognise the first matching lexer from a non-empty list.
6969export
@@ -76,11 +76,8 @@ choice (x :: xs@(_ :: _)) = x <|> choice xs
7676|||
7777||| Useful for defining comments.
7878export
79−manyTill : (l : Lexer)
80− -> (end : Lexer) -> Recognise False
81−manyTill l end = end
82− <|> (l <+> manyTill l end)
83− <|> Empty
79+manyTill : (l : Lexer) -> (end : Lexer) -> Recognise False
80+manyTill l end = end <|> opt (l <+> manyTill l end)
8481
8582||| Recognise any character
8683export
@@ -188,7 +185,7 @@ charLit = is '\'' <+> strChar <+> is '\''
188185||| Recognise an integer literal (possibly with a '-' prefix)
189186export
190187intLit : Lexer
191−intLit = (is '-' <|> Empty) <+> digits
188+intLit = opt (is '-') <+> digits
192189
193190||| A mapping from lexers to the tokens they produce.
194191||| This is a list of pairs `(Lexer, String -> tokenType)`