Search in sources :

Example 1 with ParserError

use of abs.frontend.parser.ParserError in project abstools by abstools.

the class ASTBasedABSTestRunnerGeneratorTest method testGenerateTestRunner.

@Test
public final void testGenerateTestRunner() {
    final Model model;
    try {
        model = Main.parseString(ABS_UNIT + TEST_CODE, true);
    } catch (Exception e) {
        throw new IllegalStateException("Cannot parse test code", e);
    }
    ABSTestRunnerGenerator generator = new ASTBasedABSTestRunnerGenerator(model);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    PrintStream print = new PrintStream(stream);
    generator.generateTestRunner(print);
    String runner = stream.toString();
    try {
        Model result = Main.parseString(ABS_UNIT + TEST_CODE + runner, true);
        StringBuilder parseErrors = new StringBuilder();
        if (result.hasParserErrors()) {
            parseErrors.append("Syntactic errors: ");
            List<ParserError> es = result.getParserErrors();
            parseErrors.append(es.size());
            parseErrors.append("\n");
            for (ParserError e : es) {
                parseErrors.append(e.getHelpMessage());
                parseErrors.append("\n");
            }
        }
        assertFalse("Generated code must not have parse error: " + parseErrors, result.hasParserErrors());
        StringBuilder errors = new StringBuilder();
        if (result.hasErrors()) {
            SemanticConditionList el = result.getErrors();
            errors.append("Semantic errors: ");
            errors.append(el.getErrorCount());
            errors.append("\n");
            for (SemanticCondition error : el) {
                errors.append(error.getHelpMessage());
                errors.append("\n");
            }
        }
        assertFalse("Generated code must not have semantic error: " + errors, result.hasErrors());
        result.typeCheck();
        assertFalse("Generated code must not have type error", result.hasTypeErrors());
        assertThat("Has one module that has the name 'AbsUnit.TestRunner' and a main block", result.getModuleDecls(), hasItem(new ModuleMatcher()));
    } catch (Exception e) {
        fail("Cannot throw an exception ");
    }
}
Also used : PrintStream(java.io.PrintStream) ParserError(abs.frontend.parser.ParserError) SemanticCondition(abs.frontend.analyser.SemanticCondition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 2 with ParserError

use of abs.frontend.parser.ParserError in project abstools by abstools.

the class ModuleDecorator method hasModuleDeclErrors.

/**
 * Determines if a module declaration has any errors
 *
 * @param m
 *            the module declaration
 * @param nature
 *            the ABS nature
 * @return TRUE if the module declaration has errors, FALSE if not or m or
 *         nature is null
 */
public boolean hasModuleDeclErrors(ModuleDecl m, AbsNature nature) {
    synchronized (nature.modelLock) {
        if (m != null) {
            CompilationUnit cu = m.getCompilationUnit();
            EditorPosition pos = UtilityFunctions.getPosition(m);
            int startLine = pos.getLinestart();
            int endLine = pos.getLineend();
            List<ParserError> parserErrors = cu.getParserErrors();
            SemanticConditionList list = cu.getModel().getTypeErrors();
            if (checkParserErrorRange(startLine, endLine, parserErrors)) {
                return true;
            } else {
                return checkSemanticErrorRange(list, cu, startLine, endLine, nature);
            }
        }
        return false;
    }
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) EditorPosition(org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) ParserError(abs.frontend.parser.ParserError)

Example 3 with ParserError

use of abs.frontend.parser.ParserError in project abstools by abstools.

the class ParseException method getMessage.

private static String getMessage(List<ParserError> parseErrors) {
    StringBuffer result = new StringBuffer("Project contains parse errors: ");
    for (ParserError error : parseErrors) {
        // TODO: newline doesn't work ):
        result.append("\n");
        result.append(error.getFileName());
        result.append(':');
        result.append(error.getLine());
        result.append(':');
        result.append(error.getColumn());
        result.append(' ');
        result.append(error.getMessage());
    }
    return result.toString();
}
Also used : ParserError(abs.frontend.parser.ParserError)

Aggregations

ParserError (abs.frontend.parser.ParserError)3 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)2 SemanticCondition (abs.frontend.analyser.SemanticCondition)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 Model (abs.frontend.ast.Model)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 EditorPosition (org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition)1 Test (org.junit.Test)1