import Scanner from './index' ; interface QuotedOptions { /** A character code of quote-escape symbol */ escape ? : number ; /** Throw error if quotes string can’t be properly consumed */ throws ? : boolean ; } const defaultQuotedOptions = { escape : 92 , throws : false } ; /**
 * Check if given code is a number
 */ export function isNumber ( code ) { return code > 47 && code < 58 ; } /**
 * Check if given character code is alpha code (letter through A to Z)
 */ export function isAlpha ( code , from ? , to ? ) { from = from || 65 ; to = to || 90 ; code &= ~ 32 ; return code >= from && code <= to ; } /**
 * Check if given character code is alpha-numeric (letter through A to Z or number)
 */ export function isAlphaNumeric ( code ) { return isNumber ( code ) || isAlpha ( code ) ; } export function isAlphaNumericWord ( code ) { return isNumber ( code ) || isAlphaWord ( code ) ; } export function isAlphaWord ( code ) { return code === 95 || isAlpha ( code ) ; } /**
 * Check if given character code is a white-space character: a space character
 * or line breaks
 */ export function isWhiteSpace ( code ) { return code === 32 || code === 9 || code === 160 ; } /**
 * Check if given character code is a space character
 */ export function isSpace ( code ) { return isWhiteSpace ( code ) || code === 10 || code === 13 ; } return export function eatQuoted ( stream , options ? ) { options = { ... defaultQuotedOptions , ... options } ; const start = stream . pos ; const quote = stream . peek ( ) ; if ( stream . eat ( isQuote ) ) { while ( ! stream . eof ( ) ) { switch ( stream . next ( ) ) { case quote : stream . start = start ; return true ; case options . escape : stream . next ( ) ; break ; } } stream . pos = start ; if ( options . throws ) { throw stream . error ( 'Unable to consume quoted string' ) ; } } return false ; } /**
 * Check if given character code is a quote character
 */ export function isQuote ( code ) { return code === 39 || code === 34 ; } param open param close return export function eatPair ( stream , open , close , options ? ) { options = { ... defaultQuotedOptions , ... options } ; const start = stream . pos ; if ( stream . eat ( open ) ) { let stack = 1 ; let ch ; while ( ! stream . eof ( ) ) { if ( eatQuoted ( stream , options ) ) { continue ; } ch = stream . next ( ) ! ; if ( ch === open ) { stack ++ ; } else if ( ch === close ) { stack -- ; if ( ! stack ) { stream . start = start ; return true ; } } else if ( ch === options . escape ) { stream . next ( ) ; } } stream . pos = start ; if ( options . throws ) { throw stream . error ( `Unable to find matching pair for ${ String . fromCharCode ( open ) }` ) ; } } return false ; }