@Test(expected=SoarException.class) public void testErrorOnUnclosedQuote() throws Exception { final ParserBuffer reader = reader(" \" words { "); parser.parseWord(reader); }
public String parseWord(ParserBuffer reader) throws SoarException, IOException { skipWhitespace(reader); final StringBuilder result = new StringBuilder(); int c = read(reader); if(c == -1) { return null; } if(startOfCommand == -1) { startOfCommand = reader.getCurrentOffset(); lineOfCommand = reader.getCurrentLine(); } if(c == '"') { while((c = read(reader)) != -1 && c != '"') { switch(c) { case '\\': c = parseEscapeSequence(reader); if(c == -1) { throw new SoarParserException("Unexpected end of file", startOfCommand); } default: result.append((char) c); } } if(c == -1) { throw new SoarParserException("Unexpected end of input. Unmatched quote.", startOfCommand); } } else if(c == '{') { int braces = 1; while(braces > 0 && (c = read(reader)) != -1) { switch(c) { case '}': braces--; if(braces > 0) { result.append((char) c); } break; case '{': braces++; default: result.append((char) c); } } if(braces > 0) { throw new SoarParserException("Unexpected end of input. Unmatched opening brace", startOfCommand); } } else { result.append((char) c); while((c = read(reader)) != -1 && !Character.isWhitespace(c)) { result.append((char) c); } if(c != -1) { unread(reader, c); } } return result.toString(); }
DefaultInterpreterParser { public String parseWord(ParserBuffer reader) throws SoarException, IOException { skipWhitespace(reader); final StringBuilder result = new StringBuilder(); int c = read(reader); if(c == -1) { return null; } if(startOfCommand == -1) { startOfCommand = reader.getCurrentOffset(); lineOfCommand = reader.getCurrentLine(); } if(c == '"') { while((c = read(reader)) != -1 && c != '"') { switch(c) { case '\\': c = parseEscapeSequence(reader); if(c == -1) { throw new SoarParserException("Unexpected end of file", startOfCommand); } default: result.append((char) c); } } if(c == -1) { throw new SoarParserException("Unexpected end of input. Unmatched quote.", startOfCommand); } } else if(c == '{') { int braces = 1; while(braces > 0 && (c = read(reader)) != -1) { switch(c) { case '}': braces--; if(braces > 0) { result.append((char) c); } break; case '{': braces++; default: result.append((char) c); } } if(braces > 0) { throw new SoarParserException("Unexpected end of input. Unmatched opening brace", startOfCommand); } } else { result.append((char) c); while((c = read(reader)) != -1 && !Character.isWhitespace(c)) { result.append((char) c); } if(c != -1) { unread(reader, c); } } return result.toString(); } }
DefaultInterpreterParser { public String parseWord(ParserBuffer reader) throws SoarException, IOException { skipWhitespace(reader); final StringBuilder result = new StringBuilder(); int c = read(reader); if(c == -1) { return null; } if(startOfCommand == -1) { startOfCommand = reader.getCurrentOffset(); lineOfCommand = reader.getCurrentLine(); } if(c == '"') { while((c = read(reader)) != -1 && c != '"') { switch(c) { case '\\': c = parseEscapeSequence(reader); if(c == -1) { throw new SoarParserException("Unexpected end of file", startOfCommand); } default: result.append((char) c); } } if(c == -1) { throw new SoarParserException("Unexpected end of input. Unmatched quote.", startOfCommand); } } else if(c == '{') { int braces = 1; while(braces > 0 && (c = read(reader)) != -1) { switch(c) { case '}': braces--; if(braces > 0) { result.append((char) c); } break; case '{': braces++; default: result.append((char) c); } } if(braces > 0) { throw new SoarParserException("Unexpected end of input. Unmatched opening brace", startOfCommand); } } else { result.append((char) c); while((c = read(reader)) != -1 && !Character.isWhitespace(c)) { result.append((char) c); } if(c != -1) { unread(reader, c); } } return result.toString(); }  }
DefaultInterpreterParser { public String parseWord(ParserBuffer reader) throws SoarException, IOException { skipWhitespace(reader); final StringBuilder result = new StringBuilder(); int c = read(reader); if(c == -1) { return null; } if(startOfCommand == -1) { startOfCommand = reader.getCurrentOffset(); lineOfCommand = reader.getCurrentLine(); } if(c == '"') { while((c = read(reader)) != -1 && c != '"') { switch(c) { case '\\': c = parseEscapeSequence(reader); if(c == -1) { throw new SoarParserException("Unexpected end of file", startOfCommand); } default: result.append((char) c); } } if(c == -1) { throw new SoarParserException("Unexpected end of input. Unmatched quote.", startOfCommand); } } else if(c == '{') { int braces = 1; while(braces > 0 && (c = read(reader)) != -1) { switch(c) { case '}': braces--; if(braces > 0) { result.append((char) c); } break; case '{': braces++; default: result.append((char) c); } } if(braces > 0) { throw new SoarParserException("Unexpected end of input. Unmatched opening brace", startOfCommand); } } else { result.append((char) c); while((c = read(reader)) != -1 && !Character.isWhitespace(c)) { result.append((char) c); } if(c != -1) { unread(reader, c); } } return result.toString(); }  ParsedCommand parseCommand(ParserBuffer reader); void skipWhitespace(ParserBuffer reader); void skipWhitespaceAndComments(ParserBuffer reader); String parseWord(ParserBuffer reader); }
DefaultInterpreterParser { public String parseWord(ParserBuffer reader) throws SoarException, IOException { skipWhitespace(reader); final StringBuilder result = new StringBuilder(); int c = read(reader); if(c == -1) { return null; } if(startOfCommand == -1) { startOfCommand = reader.getCurrentOffset(); lineOfCommand = reader.getCurrentLine(); } if(c == '"') { while((c = read(reader)) != -1 && c != '"') { switch(c) { case '\\': c = parseEscapeSequence(reader); if(c == -1) { throw new SoarParserException("Unexpected end of file", startOfCommand); } default: result.append((char) c); } } if(c == -1) { throw new SoarParserException("Unexpected end of input. Unmatched quote.", startOfCommand); } } else if(c == '{') { int braces = 1; while(braces > 0 && (c = read(reader)) != -1) { switch(c) { case '}': braces--; if(braces > 0) { result.append((char) c); } break; case '{': braces++; default: result.append((char) c); } } if(braces > 0) { throw new SoarParserException("Unexpected end of input. Unmatched opening brace", startOfCommand); } } else { result.append((char) c); while((c = read(reader)) != -1 && !Character.isWhitespace(c)) { result.append((char) c); } if(c != -1) { unread(reader, c); } } return result.toString(); }  ParsedCommand parseCommand(ParserBuffer reader); void skipWhitespace(ParserBuffer reader); void skipWhitespaceAndComments(ParserBuffer reader); String parseWord(ParserBuffer reader);  }