Variable intConst

int: Simple.Parser<number> = ...

Parse integers.

Remarks

Example

Behavior

By default it only parsers non-negative integers

    run(int("1"))    // => Ok(1)
run(int("1234")) // => Ok(1234)
run(int("-789")) // => Err(...)
run(int("0123")) // => Err(...)
run(int("1.34")) // => Err(...)
run(int("1e31")) // => Err(...)
run(int("123a")) // => Err(...)
run(int("0x1A")) // => Err(...)

If you want to handle a leading + or - you should do it with a custom parser like this:

    const myInt: Parser<number> = oneOf(
succeed((n: number) => n * -1)
.skip(symbol("-"))
.apply(int),
int
);

Note: If you want a parser for both Int and Float literals, check out number below. It will be faster than using oneOf to combining int and float yourself.