Compiler.Parse.Number

This module provides parsers for Gren numeric literals.

parser : Parser Context Error Outcome

Use this to parse numeric literals.

String.Parser.run parser Compiler.Parse.Context.empty source
type Outcome
= Integer Int
| FloatingPoint Float
| Hex Int

The parser tolerates different kind of numbers: integers, floats and hex-encoded integers.

type Error
= NotANumber
| LeadingZero
| ExpectedInt
| ExpectedHex

The kind of errors that can happen while parsing numbers.

errorToString : Error -> String

Returns a human-readable description of an Error.

Specialized parsers

zeroOrHigher : Parser Context Error Outcome

Like parser, but does not support negative numbers.

hexParser : error -> Parser Context error Int

A parser that only parses hex-encoded integers, like 0xAB.