package test.language;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

import compiler.language.conceptual.ConceptualException;
import compiler.language.conceptual.NameConflictException;
import compiler.language.conceptual.topLevel.ConceptualFile;
import compiler.language.conceptual.typeDefinition.ConceptualClass;
import compiler.language.parser.LanguageParser;
import compiler.language.translator.conceptual.ConceptualTranslator;

/*
 * Created on 30 Apr 2011
 */

/**
 * @author Anthony Bryant
 */
public class ConceptualTranslationTest
{

  public static void main(String[] args) throws NameConflictException, ConceptualException
  {
    if (args.length < 2)
    {
      System.err.println("Usage: java test.language.ConceptualTranslationTest <SourceFile> <ClasspathFolder>");
      System.exit(1);
    }

    File file = new File(args[0]);
    if (!file.isFile())
    {
      System.err.println("Could not find source file: " + file.getAbsolutePath());
      System.exit(1);
    }
    List<File> classpath = new LinkedList<File>();
    classpath.add(new File(args[1]));

    LanguageParser parser = new LanguageParser();

    ConceptualTranslator translator = new ConceptualTranslator(parser, classpath);

    ConceptualFile conceptualFile = translator.parseFile(file);

    if (conceptualFile != null)
    {
      System.out.println("Successfully parsed " + file.getAbsolutePath());
      System.out.println(conceptualFile);

      translator.translate();

      System.out.println("Successfully translated");
      System.out.println("Classes: ");
      for (ConceptualClass conceptualClass : conceptualFile.getClasses())
      {
        System.out.println("  " + conceptualClass.getName());
        System.out.println("  extends: " + conceptualClass.getBaseClass().getTypeInstance());
      }

    }
  }

}

@@ -91,16 +91,56 @@
 .List;%0A%0A
+import compiler.language.ast.ParseInfo;%0A
 import c
@@ -180,32 +180,32 @@
 ptualException;%0A
-
 import compiler.
@@ -648,58 +648,8 @@
 rgs)
- throws NameConflictException, ConceptualException
 %0A  %7B
@@ -1439,24 +1439,44 @@
 tualFile);%0A%0A
+      try%0A      %7B%0A  
       transl
@@ -1492,16 +1492,298 @@
 slate();
+%0A      %7D%0A      catch (NameConflictException e)%0A      %7B%0A        printConceptualException(e.getMessage(), e.getParseInfo());%0A        return;%0A      %7D%0A      catch (ConceptualException e)%0A      %7B%0A        printConceptualException(e.getMessage(), e.getParseInfo());%0A        return;%0A      %7D
 %0A%0A      
@@ -2126,10 +2126,1334 @@
  %7D%0A  %7D%0A%0A
+  private static void printConceptualException(String message, ParseInfo... parseInfos)%0A  %7B%0A    if (parseInfos == null %7C%7C parseInfos.length %3C 1)%0A    %7B%0A      System.err.println(message);%0A      return;%0A    %7D%0A    // make a String representation of the ParseInfos' character ranges%0A    StringBuffer buffer = new StringBuffer();%0A    for (int i = 0; i %3C parseInfos.length; i++)%0A    %7B%0A      String characterRange;%0A      int startLine = parseInfos%5Bi%5D.getStartLine();%0A      int endLine = parseInfos%5Bi%5D.getEndLine();%0A      if (startLine == endLine)%0A      %7B%0A        // line:start-end if it is all on one line%0A        characterRange = startLine + %22:%22;%0A        int startPos = parseInfos%5Bi%5D.getStartPos();%0A        int endPos = parseInfos%5Bi%5D.getEndPos();%0A        characterRange += startPos;%0A        if (startPos %3C endPos - 1)%0A        %7B%0A          characterRange += %22-%22 + (endPos - 1);%0A        %7D%0A      %7D%0A      else%0A      %7B%0A        // startLine-endLine if it spans multiple lines%0A        characterRange = startLine + %22-%22 + endLine;%0A      %7D%0A      buffer.append(characterRange);%0A      if (i != parseInfos.length - 1)%0A      %7B%0A        buffer.append(%22, %22);%0A      %7D%0A    %7D%0A    if (parseInfos.length == 1)%0A    %7B%0A      System.err.println(message + %22: %22 + buffer);%0A    %7D%0A    else%0A    %7B%0A      System.err.println(message + %22%5CnAt: %22 + buffer);%0A    %7D%0A  %7D%0A%0A
 %7D%0A

Improve error reporting by printing out ParseInfo