예제 #1
0
파일: parser.cpp 프로젝트: maximecb/bjrn
/**
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;
}
예제 #2
0
파일: parser.cpp 프로젝트: maximecb/bjrn
/**
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;
}
예제 #3
0
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;
}
예제 #4
0
파일: parser.cpp 프로젝트: maximecb/bjrn
/**
Primitive to match a string and whitespace before it
*/
Value matchStrWS(Value inputVal, Value strVal)
{
    eatWS(inputVal);
    return matchStr(inputVal, strVal);
}