since import { Foldable , Foldable1 } from 'fp-ts/lib/Foldable' ; import { Functor , Functor1 } from 'fp-ts/lib/Functor' ; import { HKT , Kind , URIS } from 'fp-ts/lib/HKT' ; import * as E from 'fp-ts/Either' ; import * as M from 'fp-ts/lib/Monoid' ; import * as O from 'fp-ts/lib/Option' ; import { pipe } from 'fp-ts/lib/pipeable' ; import * as C from './char' ; import * as P from './Parser' ; import * as S from './Stream' ; import * as PR from './ParseResult' ; category since export const string = s => P . expected ( P . ChainRec . chainRec < string , string , string > ( s , acc => pipe ( charAt ( 0 , acc ) , O . fold ( ( ) => P . of ( E . right ( s ) ) , c => pipe ( C . char ( c ) , P . chain ( ( ) => P . of ( E . left ( acc . slice ( 1 ) ) ) ) ) ) ) ) , JSON . stringify ( s ) ) ; category since export function oneOf < F extends URIS > ( F ) ; export function oneOf < F > ( F ) ; export function oneOf < F > ( F ) { return ss => F . reduce ( ss , P . fail ( ) , ( p , s ) => pipe ( p , P . alt ( ( ) => string ( s ) ) ) ) ; } category since export const fold = M . fold ( P . getMonoid ( M . monoidString ) ) ; category since export const maybe = P . maybe ( M . monoidString ) ; category since export const many = parser => maybe ( many1 ( parser ) ) ; category since export const many1 = parser => pipe ( P . many1 ( parser ) , P . map ( nea => nea . join ( '' ) ) ) ; const charAt = ( index , s ) => index >= 0 && index < s . length ? O . some ( s . charAt ( index ) ) : O . none ; category since export const spaces = C . many ( C . space ) ; category since export const spaces1 = C . many1 ( C . space ) ; category since export const notSpaces = C . many ( C . notSpace ) ; category since export const notSpaces1 = C . many1 ( C . notSpace ) ; const fromString = s => { const n = + s ; return isNaN ( n ) || s === '' ? O . none : O . some ( n ) ; } ; category since export const int = P . expected ( pipe ( fold ( [ maybe ( C . char ( '-' ) ) , C . many1 ( C . digit ) ] ) , P . map ( s => + s ) ) , 'an integer' ) ; category since export const float = P . expected ( pipe ( fold ( [ maybe ( C . char ( '-' ) ) , C . many ( C . digit ) , maybe ( fold ( [ C . char ( '.' ) , C . many1 ( C . digit ) ] ) ) ] ) , P . chain ( s => pipe ( fromString ( s ) , O . fold ( ( ) => P . fail ( ) , P . succeed ) ) ) ) , 'a float' ) ; category since export const doubleQuotedString = P . surroundedBy ( C . char ( '"' ) ) ( many ( P . either ( string ( '\\"' ) , ( ) => C . notChar ( '"' ) ) ) ) ; summary category since export function run ( string ) { return p => p ( S . stream ( string . split ( '' ) ) ) ; }