/*
This file is part of JLoom
Copyright (C) 2006 Gereon Fassbender
Homepage: jloom.sourceforge.net
JLoom is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You can find a copy of the GNU General Public License along with this program
in a file called COPYING. Information can also be found at www.fsf.org or
www.gnu.org or write to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
created: 08.04.2006 Gereon Fassbender
$Revision$
$Date$
$Log$
*/
package net.gereon.jloom.commandline;
import java.io.IOException;
import java.util.Collection;
import net.gereon.jloom.core.TranslationContext;
import net.gereon.jloom.problems.TranslationProblem;
import net.gereon.jloom.util.JLoomTools;
public class Translate
{
static
{
// enable assertions
Translate.class.getClassLoader().setDefaultAssertionStatus(true);
}
private static void println(String text)
{
System.out.println(text);
}
private static void printTab(int size)
{
for (int i=1; i<=size; i++) {
System.out.print(" ");
}
}
public static void main(String[] args) throws IOException
{
println("JLoom " + JLoomTools.getVersion());
if (args.length != 1) {
println("");
println("usage: CMD <qualified-template-name>");
println("example: CMD com.packagename.Example");
println(" (translates the file ./com/packagename/Example.jloom)");
println("");
println("Note that CMD is the command you just used to get this help text,");
println("e.g. \"java -jar jloom-1.0.0.jar\".");
return;
}
TranslationContext tc = JLoomTools.translate(args[0]);
Collection<TranslationProblem> problems = tc.getProblems();
if (problems.size() > 0) {
TextInfo info = new TextInfo(tc.getInputText());
for (TranslationProblem p : problems) {
int start = p.getStart();
int line = info.getLineNumber(start);
int col = start - info.getLineStart(line);
println("");
println("line " + line + ": " + p.getMessage());
println(info.getLineString(line));
printTab(col - 1);
println("^");
}
}
}
}