module /** */ import { ParsingState } from "../state" ; import { ResultKind } from "../result" ; import { Parjser } from "../parjser" ; import { ParjserBase } from "../parser" ; param origRegexp export function regexp ( origRegexp ) { let flags = [ origRegexp . ignoreCase && "i" , origRegexp . multiline && "m" ] . filter ( x => x ) . join ( "" ) ; let regexp = new RegExp ( origRegexp . source , `${ flags }y` ) ; this . reason = `expecting input matching /${ origRegexp . source }/` ; return new class Regexp extends ParjserBase { type = "regexp" ; expecting = `expecting input matching '${ regexp . source }'` ; _apply ( ps ) { let { input , position } = ps ; regexp . lastIndex = position ; let match = regexp . exec ( input ) ; if ( ! match ) { ps . kind = ResultKind . SoftFail ; return ; } ps . position += match [ 0 ] . length ; ps . value = match . slice ( ) ; ps . kind = ResultKind . Ok ; } } ( ) ; }