Search in sources :

Example 6 with Name

use of dyvil.lang.Name in project Dyvil by Dyvil.

the class Property method formatSetter.

private static void formatSetter(IMethod setter, String prefix, StringBuilder buffer) {
    final String indent = Formatting.getIndent("property.setter.indent", prefix);
    final IValue value = setter.getValue();
    final Name setterParameterName = setter.getParameters().get(0).getName();
    buffer.append('\n').append(indent);
    setter.getAttributes().toInlineString(indent, buffer);
    buffer.append("set");
    if (setterParameterName != Names.newValue) {
        Formatting.appendSeparator(buffer, "property.setter.parameter.open_paren", '(');
        buffer.append(setterParameterName);
        Formatting.appendSeparator(buffer, "property.setter.parameter.close_paren", ')');
    }
    if (value != null) {
        if (Util.formatStatementList(indent, buffer, value)) {
            return;
        }
        // Separator
        if (Formatting.getBoolean("property.setter.separator.space_before")) {
            buffer.append(' ');
        }
        buffer.append(':');
        if (Formatting.getBoolean("property.setter.separator.newline_after")) {
            buffer.append('\n').append(indent);
        } else if (Formatting.getBoolean("property.setter.separator.space_after")) {
            buffer.append(' ');
        }
        value.toString(indent, buffer);
    }
    if (Formatting.getBoolean("property.setter.semicolon")) {
        buffer.append(';');
    }
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) Name(dyvil.lang.Name)

Example 7 with Name

use of dyvil.lang.Name in project Dyvil by Dyvil.

the class OperatorElement method resolve.

protected void resolve(MarkerList markers, IContext context) {
    IOperator operator = IContext.resolveOperator(context, this.name, IOperator.INFIX);
    if (operator != null) {
        this.operator = operator;
        // Infix check
        checkPosition(markers, this.position, operator, IOperator.INFIX);
        return;
    }
    if (!Util.hasEq(this.name)) {
        // Unresolved operator, no =
        this.operator = Operator.DEFAULT;
        markers.add(Markers.semantic(this.position, "operator.unresolved", this.name));
        return;
    }
    // = at the end
    final Name removeEq = Util.removeEq(this.name);
    operator = IContext.resolveOperator(context, removeEq, IOperator.INFIX);
    if (operator == null) {
        this.operator = Operator.DEFAULT_RIGHT;
        return;
    }
    if (operator.getAssociativity() != IOperator.RIGHT) {
        this.operator = new Operator(removeEq, IOperator.RIGHT, operator.getPrecedence() - 1);
        return;
    }
    // No infix check required, the type is ID_INFIX_RIGHT
    this.operator = operator;
}
Also used : Name(dyvil.lang.Name)

Example 8 with Name

use of dyvil.lang.Name in project Dyvil by Dyvil.

the class ExpressionParser method parseInfixAccess.

private void parseInfixAccess(IParserManager pm, IToken token) {
    Name name = token.nameValue();
    if (name == null) {
        name = Name.from(token.stringValue());
    }
    this.parseInfixAccess(pm, token, name, false);
}
Also used : Name(dyvil.lang.Name)

Example 9 with Name

use of dyvil.lang.Name in project Dyvil by Dyvil.

the class PackageParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case PACKAGE:
            this.mode = NAME;
            if (type != DyvilKeywords.PACKAGE) {
                pm.report(token, "package.package");
                pm.reparse();
            }
            return;
        case NAME:
            if (Tokens.isIdentifier(type)) {
                final Name name = token.nameValue();
                this.buffer.append(name.qualified);
                this.mode = DOT;
                return;
            }
            pm.report(token, "package.identifier");
            return;
        case DOT:
            switch(type) {
                case BaseSymbols.SEMICOLON:
                    pm.reparse();
                // Fallthrough
                case Tokens.EOF:
                    this.packageDeclaration.setPackage(this.buffer.toString());
                    pm.popParser();
                    return;
                case BaseSymbols.DOT:
                    this.mode = NAME;
                    this.buffer.append('.');
                    return;
                default:
                    this.mode = NAME;
                    pm.report(token, "package.dot");
                    pm.reparse();
                    return;
            }
    }
}
Also used : Name(dyvil.lang.Name)

Example 10 with Name

use of dyvil.lang.Name in project Dyvil by Dyvil.

the class TypeAliasParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    int type = token.type();
    switch(this.mode) {
        case END:
            this.map.addTypeAlias(this.typeAlias);
            pm.popParser(true);
            return;
        case TYPE:
            this.mode = NAME;
            if (type != DyvilKeywords.TYPE) {
                pm.reparse();
                pm.report(token, "typealias.type");
            }
            return;
        case NAME:
            if (Tokens.isIdentifier(type)) {
                Name name = token.nameValue();
                this.typeAlias = new TypeAlias(name, token.raw());
                this.mode = TYPE_PARAMETERS;
                return;
            }
            pm.popParser();
            pm.report(token, "typealias.identifier");
            return;
        case TYPE_PARAMETERS:
            if (TypeParser.isGenericStart(token, type)) {
                this.mode = TYPE_PARAMETERS_END;
                pm.splitJump(token, 1);
                pm.pushParser(new TypeParameterListParser(this.typeAlias));
                return;
            }
        // Fallthrough
        case EQUAL:
            this.mode = END;
            pm.pushParser(new TypeParser(this.typeAlias));
            if (type != BaseSymbols.EQUALS) {
                pm.reparse();
                pm.report(token, "typealias.equals");
            }
            return;
        case TYPE_PARAMETERS_END:
            this.mode = EQUAL;
            if (TypeParser.isGenericEnd(token, type)) {
                pm.splitJump(token, 1);
                return;
            }
            pm.reparse();
            pm.report(token, "generic.close_angle");
    }
}
Also used : TypeParser(dyvilx.tools.compiler.parser.type.TypeParser) ITypeAlias(dyvilx.tools.compiler.ast.type.alias.ITypeAlias) TypeAlias(dyvilx.tools.compiler.ast.type.alias.TypeAlias) TypeParameterListParser(dyvilx.tools.compiler.parser.type.TypeParameterListParser) Name(dyvil.lang.Name)

Aggregations

Name (dyvil.lang.Name)33 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)4 CodeAnnotation (dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation)4 AnnotationParser (dyvilx.tools.compiler.parser.annotation.AnnotationParser)4 TypeParser (dyvilx.tools.compiler.parser.type.TypeParser)4 IClass (dyvilx.tools.compiler.ast.classes.IClass)3 IField (dyvilx.tools.compiler.ast.field.IField)3 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)3 IType (dyvilx.tools.compiler.ast.type.IType)3 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)2 Modifier (dyvilx.tools.compiler.ast.attribute.modifiers.Modifier)2 IValue (dyvilx.tools.compiler.ast.expression.IValue)2 IOperator (dyvilx.tools.compiler.ast.expression.operator.IOperator)2 IDataMember (dyvilx.tools.compiler.ast.field.IDataMember)2 IProperty (dyvilx.tools.compiler.ast.field.IProperty)2 IMethod (dyvilx.tools.compiler.ast.method.IMethod)2 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)2 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)2 NamedType (dyvilx.tools.compiler.ast.type.raw.NamedType)2 ExpressionParser (dyvilx.tools.compiler.parser.expression.ExpressionParser)2