Logo Search packages:      
Sourcecode: jaula version File versions

Value_Complex * JAULA::Parser::parseStream ( std::istream &  inpStream,
bool  comments_allowed = false,
bool  full_read = true 
) throw (Exception) [static]

Parses JSON data from a stream.

inpStream stream from where to read the data to parse.
comments_allowed flag that if it is true means that the input can contain comments that begin with the hash '#' symbol and ends with eoln (as in bash). If it is false, it means that no comments are allowed in the input and if present will be considered as a syntax error.
full_read flag that if it is true means that the parser must analyze the input stream until the end of file is although it already had got a full array or object from it. In this situation, as JSON specification expects just only one array or object per input, any further data that is not a space for the syntax (or a comment if comments are allowed) will launch a syntax error exception.
If this flag is false, the parser will stop once a full array or object is taken from the input and, on exit, the stream will point to the start of the remaining data.
a pointer to memory taken from the heap containing a complex value (array or object) with all the data from the stream parsed on individual / nested items.
Exception An exception will be thrown as soon as a lexical or syntax error is found analyzing the stream. The result of printing the exception through a stream is a human readable text explaining the error found and an approximation of the error line where occurred.
This method is the entry point for the JSON parser.
As this method returns a pointer to memory from the heap, it is up to the user to free it when it is no longer needed in order to avoid leaks.

Definition at line 72 of file jaula_parse.cc.

References JAULA::Exception::addOrigin(), JAULA::Parser::Value_Parser::parseValue(), and JAULA::Lexan::yylex().

      Lexan   lexer(inpStream, comments_allowed);

      unsigned int firstToken = lexer.yylex();
      std::auto_ptr<Value> pVal(Value_Parser::parseValue(lexer, firstToken));

      if (!dynamic_cast<Value_Complex const *>(pVal.get()))
        throw Syntax_Error("The first value taken from the input does not"
          " belong to a complex type (array or object)"
          , "analyzing input stream");

      if (full_read)
        if (lexer.yylex())
          std::ostringstream  errAct;
          errAct << "analyzing line "
            << lexer.lineno()
            << " from input stream.";
          throw Syntax_Error("The input stream contains more than one first"
            " level complex (array or object) value"
            , errAct.str());

      return dynamic_cast<Value_Complex *>(pVal.release());
    catch(Exception &ex)
      ex.addOrigin("Parser::parseStream(std::istream *, bool, bool)");
      throw ex;

Generated by  Doxygen 1.6.0   Back to index