Search in sources :

Example 1 with Lexer

use of csep.parser.Lexer in project coffeescript-eclipse by adamschmideg.

the class ParserTestBase method expect.

/**
	 * Parse and check for errors and warnings
	 * @param errorCount 1 means expect error(s)
	 * @param warningCount -1 means don't care about warnings
	 */
protected void expect(CharSequence input, int errorCount, int warningCount) {
    List<String> tokens = null;
    //Assert::assertEquals('warnings ' + resource.warnings, 0, resource.warnings.size)
    //Assert::assertEquals('errors ' + resource.errors, 0, resource.errors.size)
    EObject parseResult = null;
    EList<Diagnostic> errors = null;
    EList<Diagnostic> warnings = null;
    try {
        Lexer lexer = new Lexer(input);
        tokens = lexer.tokenizeToStrings();
        InputStream in = getAsStream("" + input);
        URI uri = URI.createURI("mytestmodel." + getCurrentFileExtension());
        XtextResource resource = doGetResource(in, uri);
        parseResult = getModel(resource);
        errors = resource.getErrors();
        warnings = resource.getWarnings();
        if (errorCount == 0)
            assertEquals("Errors: " + errors, 0, errors.size());
        else if (errorCount > 0)
            assertTrue("No errors", errors.size() > 0);
        if (warningCount >= 0) {
            assertEquals("Warnings: " + warnings, warningCount, warnings.size());
        }
    } catch (AssertionFailedError afe) {
        if (logger.isDebugEnabled()) {
            String debug = "" + this.getClass().getSimpleName() + " input: \n" + input + "\n";
            debug += "Tokens: " + tokens + "\n" + Helper.stringify(parseResult);
            for (Diagnostic d : errors) {
                debug += "\tError: " + d + "\n";
            }
            for (Diagnostic d : warnings) {
                debug += "\tWarning: " + d + "\n";
            }
            logger.debug(debug);
        }
        throw new AssertionError(afe);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : InputStream(java.io.InputStream) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) URI(org.eclipse.emf.common.util.URI) Lexer(csep.parser.Lexer) EObject(org.eclipse.emf.ecore.EObject) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

Lexer (csep.parser.Lexer)1 InputStream (java.io.InputStream)1 AssertionFailedError (junit.framework.AssertionFailedError)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1