static ATerm parse(const unsigned char *inputString, unsigned int inputStringLength, const char *inputPath, const char *parseTableName){
	PT_ParseTree parseTree;
	InputString sglrInputString;
	
	ERR_resetErrorManager();
	
	sglrInputString = IS_allocateString(inputPath, inputString, inputStringLength);
	
	if(inputString == NULL){
		return ERR_SummaryToTerm(ERR_getManagerSummary());
	}
	
	if(!SGLR_isParseTableLoaded(parseTableName)){
		if(SG_AddParseTable(parseTableName) == NULL){
			return ERR_SummaryToTerm(ERR_getManagerSummary());
		}
	}
	
	parseTree = SGLR_parse(sglrInputString, parseTableName);
	
	if(parseTree == NULL){
		return ERR_SummaryToTerm(ERR_getManagerSummary());
	}
	
	return PT_ParseTreeToTerm(parseTree);
}
Exemplo n.º 2
0
ATerm pretty_print(int cid, ATerm input) 
{
  PT_ParseTree parsetree = NULL;
  BOX_Start box = NULL;
  PT_Tree result = NULL;

  ERR_resetErrorManager();

  parsetree = PT_ParseTreeFromTerm(ATBunpack(input));

  if (parsetree != NULL) {
    box = pandora(parsetree);
  }

  if (box != NULL) {
    result = toText(PT_ParseTreeFromTerm(BOX_StartToTerm(box)));
  }

  if (result != NULL) {
    PT_ParseTree presult = PT_makeValidParseTreeFromTree(result);
    ATerm value = ATBpack(PT_ParseTreeToTerm(presult));
    return ATmake("snd-value(pretty-printed(<term>))", value);
  }
  else {
    ERR_Summary summary = ERR_getManagerSummary();
    return ATmake("snd-value(pretty-print-error(<term>))", summary);
  }
}