since import { bimap , Either } from 'fp-ts/lib/Either' ; import { pipe } from 'fp-ts/lib/pipeable' ; import { Char } from './char' ; import { Parser } from './Parser' ; import { stream } from './Stream' ; const { codeFrameColumns } = require ( '@babel/code-frame' ) ; interface Location { readonly start : { readonly line : number ; readonly column : number ; } ; } const lineTerminatorRegex = /^\r\n$|^[\n\r]$/ ; const getLocation = ( source , cursor ) => { let line = 1 ; let column = 1 ; let i = 0 ; while ( i < cursor ) { i ++ ; const c = source . charAt ( i ) ; if ( lineTerminatorRegex . test ( c ) ) { line ++ ; column = 1 ; } else { column ++ ; } } return { start : { line , column } } ; } ; since export const run = ( p , source ) => pipe ( p ( stream ( source . split ( '' ) ) ) , bimap ( err => codeFrameColumns ( source , getLocation ( source , err . input . cursor ) , { message : 'Expected: ' + err . expected . join ( ', ' ) } ) , succ => succ . value ) ) ;