text: /***************************************************************************
     Copyright 2015 Ufora Inc.
  
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
         http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
  ****************************************************************************/
  #ifndef JudgmentParser_hppml_
  #define JudgmentParser_hppml_
  
  #include "../../core/SimpleParse/SimpleParse.hppml"
  #include <string>
  
  class JudgmentOnResult;
  class JudgmentOnValue;
  class JudgmentOnValueTuple;
  class JudgmentOnType;
  class JudgmentOnTypeTuple;
  class Symbol;
  
  
  @type JudgmentParseError = std::string error, SimpleParseRange range {
  public:
  		JudgmentParseError(	std::string inError,
  							const SimpleParseNode& node)
  			{
  			error() = inError + ": " + node.toString();
  			range() = node.extent();
  			}
  		JudgmentParseError(	std::string inError,
  							const ImmutableTreeVector<SimpleParseNode>& nodes)
  			{
  			lassert(nodes.size());
  			error() = inError;
  			range() = SimpleParseRange(nodes[0].extent().start(),
  										nodes.back().extent().stop());
  			}
  		JudgmentParseError(	std::string inError,
  							const SimpleParseNode& nodeStart,
  							const SimpleParseNode& nodeEnd
  							)
  			{
  			error() = inError;
  			range() = SimpleParseRange(	nodeStart.extent().start(),
  										nodeEnd.extent().stop());
  			}
  		JudgmentParseError(	std::string inError,
  							const SimpleParsePosition& extent
  							)
  			{
  			error() = inError;
  			range() = SimpleParseRange(extent,extent);
  			}
  };
  
  class JudgmentParser {
  public:
  	//parse a SimpleParseNode to a given type or throw a JudgmentParseError
  	static JudgmentOnValue parseJOV(const SimpleParseNode& inNode);
  	static JudgmentOnValue parseJOVFromConcat(
  		const ImmutableTreeVector<SimpleParseNode>& inNode
  		);
  	static JudgmentOnResult parseJOR(const SimpleParseNode& node);
  
  	static JudgmentOnValueTuple parseJOVT(const SimpleParseNode& inNode);
  
  	//parse a term in a JOVT. may be named. if it has ..., then it's the
  	//"extras" field
  	static pair<JudgmentOnValue, Nullable<Symbol> > parseJOVTTerm(
  									const SimpleParseNode& inNode,
  									bool& outIsExtras
  									);
  };
  
  
  
  #endif
  
  