/** Primitive to access the eatWS method of the input object */ Value eatWS(Value inputVal) { if (!inputVal.isRawPtr()) throw EvalError("invalid argument to eatWS"); auto input = (Input*)(void*)inputVal; input->eatWS(); return Value::zero; }
/** Parse a source string as an expression */ Tuple parseString(const char* str, const char* srcName) { auto input = new Input( str, srcName ); input->eatWS(); auto expr = parseExpr(input); input->eatWS(); if (!input->eof()) { throw ParseError(input, "unconsumed input remains"); } return expr; }
static bool eat( istream& is ) { while( is ) { eatWS( is ); if( is ) { int ch = is.peek(); if( ch == '/' ) { is.get(); int ch = is.peek(); if( ch == '/' ) { eatNL( is ); } else if( ch == '*' ) { while( true ) { is.get(); ch = is.peek(); if( ch == '*' ) { is.get(); ch = is.peek(); if( ch == '/' ) { is.get(); break; } else if( ch == -1 ) { is.get(); throw ParseError( "Parse Error: unterminated comment" ); } } else if( ch == -1 ) { is.get(); throw ParseError( "Parse Error: unterminated comment" ); } } } else { return true; } } else if( ch == -1 ) { is.get(); return false; } else { return true; } } else { return false; } } return false; }
/** Primitive to match a string and whitespace before it */ Value matchStrWS(Value inputVal, Value strVal) { eatWS(inputVal); return matchStr(inputVal, strVal); }