blob: 6d7fe0482d60d04e5032323f644317fbdac30a4f [file] [log] [blame]
/**
* Copyright (c) 2008 - 2010 OptXware Research and Development LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Daniel Varro - Initial API and implementation
*/
/**
*
*/
package org.eclipse.viatra2.lpgparser.loader;
import org.apache.commons.lang.math.NumberUtils;
import org.eclipse.viatra2.lpgparser.VTCLParser;
/**
* Explanation generator class for the VTCL parser.
* @author Zoltan Ujhelyi
*
*/
public class ExplanationGenerator {
VTCLParser parser;
/**
* Initializes an explanation generator using a VTCL parser object.
* @param parser
*/
public ExplanationGenerator(VTCLParser parser) {
this.parser = parser;
}
/**
* Calculates an explanation about the parser error.
* @param tokenText
* @param leftToken
* @param rightToken
* @return the generated explanation
*/
public String calculateErrorExplanation(String tokenText, int leftToken, int rightToken) {
if (tokenText.contentEquals("\"VariableRefAST\"") || tokenText.contentEquals("\"VariableDefAST\"")) {
return calculateExplanationVariableRef(leftToken);
}
return "";
}
private String calculateExplanationVariableRef(int leftToken) {
String description = parser.getIToken(leftToken).toString();
if (NumberUtils.isNumber(description)) {
return VTCLMessages.ExplanationCode_INVALIDNUMBER;
}
if (!description.matches("[A-Z][?]*")) {
return VTCLMessages.ExplanationCode_REFSTARTCAPITAL;
}
return "";
}
}