Search in sources :

Example 1 with MarkerList

use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.

the class NamedGenericType method checkCount.

private IType checkCount(MarkerList markers, ITypeParametric generic, String kind, IType type) {
    final int genericArity = generic.typeArity();
    if (genericArity <= 0) {
        markers.add(Markers.semanticError(this.position, "type.generic." + kind + ".not_generic", type));
        return type.atPosition(this.position);
    }
    if (genericArity != this.arguments.size()) {
        final Marker marker = Markers.semanticError(this.position, "type.generic." + kind + ".count_mismatch", type);
        marker.addInfo(Markers.getSemantic("type.generic.argument_count", this.arguments.size()));
        marker.addInfo(Markers.getSemantic("type.generic.parameter_count", genericArity));
        markers.add(marker);
    }
    return type.getConcreteType(typeParameter -> this.arguments.get(typeParameter.getIndex())).atPosition(this.position);
}
Also used : DataOutput(java.io.DataOutput) IContext(dyvilx.tools.compiler.ast.context.IContext) Package(dyvilx.tools.compiler.ast.structure.Package) Name(dyvil.lang.Name) ResolvedTypeVarType(dyvilx.tools.compiler.ast.type.typevar.ResolvedTypeVarType) IType(dyvilx.tools.compiler.ast.type.IType) IOException(java.io.IOException) Types(dyvilx.tools.compiler.ast.type.builtin.Types) PackageType(dyvilx.tools.compiler.ast.type.raw.PackageType) Marker(dyvilx.tools.parsing.marker.Marker) ITypeAlias(dyvilx.tools.compiler.ast.type.alias.ITypeAlias) ITypeParametric(dyvilx.tools.compiler.ast.generic.ITypeParametric) Markers(dyvilx.tools.compiler.util.Markers) SourcePosition(dyvil.source.position.SourcePosition) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) TypeList(dyvilx.tools.compiler.ast.type.TypeList) MarkerList(dyvilx.tools.parsing.marker.MarkerList) DataInput(java.io.DataInput) MatchList(dyvilx.tools.compiler.ast.method.MatchList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IUnresolvedType(dyvilx.tools.compiler.ast.type.raw.IUnresolvedType) Marker(dyvilx.tools.parsing.marker.Marker)

Example 2 with MarkerList

use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.

the class TypeAlias method ensureResolved.

// Phases
private void ensureResolved() {
    if (this.resolved) {
        return;
    }
    final MarkerList markers = this.enclosingHeader instanceof ISourceHeader ? ((ISourceHeader) this.enclosingHeader).getMarkers() : null;
    this.resolveTypes(markers, this.enclosingHeader.getContext());
}
Also used : MarkerList(dyvilx.tools.parsing.marker.MarkerList) ISourceHeader(dyvilx.tools.compiler.ast.header.ISourceHeader)

Example 3 with MarkerList

use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.

the class Colorizer method colorize.

public static String colorize(String text, REPLContext context) {
    final TextSource source = new TextSource(text);
    final TokenList tokens = new DyvilLexer(new MarkerList(Markers.INSTANCE), DyvilSymbols.INSTANCE).tokenize(text);
    // Split into lines
    final int lineCount = source.lineCount();
    final StringBuilder[] lines = new StringBuilder[lineCount];
    for (int i = 0; i < lineCount; i++) {
        lines[i] = new StringBuilder(source.line(i + 1));
    }
    // iterate, starting from the last token
    for (IToken token = tokens.last(); token != null && token.type() != Tokens.EOF; token = token.prev()) {
        final String color = tokenColor(token, context);
        if (color != null) {
            // insert ANSI color codes before and after the token
            final StringBuilder line = lines[token.startLine() - 1];
            line.insert(token.endColumn(), Console.ANSI_RESET);
            line.insert(token.startColumn(), color);
        }
    }
    // Merge back together
    final StringBuilder first = lines[0];
    for (int i = 1; i < lineCount; i++) {
        first.append('\n').append(lines[i]);
    }
    return first.toString();
}
Also used : MarkerList(dyvilx.tools.parsing.marker.MarkerList) DyvilLexer(dyvilx.tools.parsing.lexer.DyvilLexer) IToken(dyvilx.tools.parsing.token.IToken) TextSource(dyvil.source.TextSource) TokenList(dyvilx.tools.parsing.TokenList)

Example 4 with MarkerList

use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.

the class TryParserManager method tryParse.

public boolean tryParse(IParserManager pm, Parser parser, IToken token, int flags) {
    final TokenIterator tokens = pm.getTokens();
    final MarkerList markers = pm.getMarkers();
    this.reset(markers, tokens);
    // Have to rewind one token because the TryParserManager assumes the TokenIterator is at the beginning
    // (i.e. no tokens have been returned by next() yet)
    tokens.setNext(token);
    if (!this.parse(parser, markers, flags)) {
        // Reset to the next token and restore split tokens
        this.setNextAndReset(token);
        return false;
    }
    this.reset();
    tokens.setNext(tokens.lastReturned());
    return true;
}
Also used : MarkerList(dyvilx.tools.parsing.marker.MarkerList)

Example 5 with MarkerList

use of dyvilx.tools.parsing.marker.MarkerList in project Dyvil by Dyvil.

the class TryParserManager method parse.

public boolean parse(Parser parser, MarkerList markers, int flags) {
    this.parser = parser;
    this.hasSyntaxErrors = false;
    this.markers = new MarkerList(markers.getI18n());
    this.reportErrors = (flags & REPORT_ERRORS) != 0;
    IToken token = null;
    while (true) {
        if (this.reparse) {
            this.reparse = false;
        } else {
            token = this.tokens.next();
            if (token.type() == Tokens.EOF) {
                break;
            }
        }
        if (this.skip > 0) {
            this.skip--;
            continue;
        }
        if (this.parser == null) {
            if ((flags & EXIT_ON_ROOT) != 0) {
                return this.success(markers);
            }
            this.reportUnparsed(token);
            continue;
        }
        if (!this.reportErrors && this.parser.reportErrors()) {
            if (this.hasSyntaxErrors) {
                return this.success(markers);
            }
            this.reportErrors = true;
        }
        try {
            this.parser.parse(this, token);
        } catch (Exception ex) {
            this.reportError(token, ex);
            return this.success(markers);
        }
        if (this.hasSyntaxErrors && !this.reportErrors) {
            return this.success(markers);
        }
    }
    this.parseRemaining(token);
    this.reparse = false;
    return this.success(markers);
}
Also used : MarkerList(dyvilx.tools.parsing.marker.MarkerList) IToken(dyvilx.tools.parsing.token.IToken)

Aggregations

MarkerList (dyvilx.tools.parsing.marker.MarkerList)8 IContext (dyvilx.tools.compiler.ast.context.IContext)3 TokenList (dyvilx.tools.parsing.TokenList)3 DyvilLexer (dyvilx.tools.parsing.lexer.DyvilLexer)3 SourcePosition (dyvil.source.position.SourcePosition)2 IClass (dyvilx.tools.compiler.ast.classes.IClass)2 IValue (dyvilx.tools.compiler.ast.expression.IValue)2 IType (dyvilx.tools.compiler.ast.type.IType)2 Types (dyvilx.tools.compiler.ast.type.builtin.Types)2 Markers (dyvilx.tools.compiler.util.Markers)2 ParserManager (dyvilx.tools.parsing.ParserManager)2 Marker (dyvilx.tools.parsing.marker.Marker)2 IToken (dyvilx.tools.parsing.token.IToken)2 NonNull (dyvil.annotation.internal.NonNull)1 Name (dyvil.lang.Name)1 Modifiers (dyvil.reflect.Modifiers)1 LineSource (dyvil.source.LineSource)1 TextSource (dyvil.source.TextSource)1 IValueConsumer (dyvilx.tools.compiler.ast.consumer.IValueConsumer)1 WriteableExpression (dyvilx.tools.compiler.ast.expression.WriteableExpression)1