use of dyvilx.tools.compiler.ast.type.alias.TypeAlias 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");
}
}
use of dyvilx.tools.compiler.ast.type.alias.TypeAlias in project Dyvil by Dyvil.
the class SourceFileParser method parse.
@Override
public void parse(IParserManager pm, IToken token) {
final int type = token.type();
switch(this.mode) {
case SEPARATOR:
if (this.unit.classCount() > 0) {
// any classes -> only allow classes from here
this.mode = CLASS;
} else if (this.unit.importCount() > 0 || this.unit.typeAliasCount() > 0 || this.unit.operatorCount() > 0 || this.unit.getHeaderDeclaration() != null) {
// any imports, type aliases, operators or header declarations -> don't allow any package declarations
this.mode = IMPORT;
} else {
// nothing defined yet -> allow a package declaration
this.mode = PACKAGE;
}
if (!checkEnd(pm, type)) {
pm.report(token, "header.separator");
pm.reparse();
}
return;
case PACKAGE:
if (type == DyvilKeywords.PACKAGE) {
PackageDeclaration pack = new PackageDeclaration(token.raw());
this.unit.setPackageDeclaration(pack);
pm.pushParser(new PackageParser(pack));
this.mode = SEPARATOR;
return;
}
// Fallthrough
case IMPORT:
switch(type) {
case DyvilKeywords.IMPORT:
pm.pushParser(new ImportParser(this.importConsumer(token)));
this.mode = SEPARATOR;
return;
case DyvilKeywords.USING:
pm.pushParser(new ImportParser(this.importConsumer(token), KindedImport.USING_DECLARATION));
this.mode = SEPARATOR;
return;
case DyvilKeywords.OPERATOR:
pm.pushParser(new OperatorParser(this.unit, Operator.INFIX), true);
this.mode = SEPARATOR;
return;
case DyvilKeywords.PREFIX:
case DyvilKeywords.POSTFIX:
case DyvilKeywords.INFIX:
if (//
token.next().type() == DyvilKeywords.OPERATOR || token.next().type() == DyvilKeywords.POSTFIX && token.next().next().type() == DyvilKeywords.OPERATOR) {
pm.pushParser(new OperatorParser(this.unit), true);
this.mode = SEPARATOR;
return;
}
// parse as modifier (in 'case CLASS' via fallthrough)
break;
case DyvilKeywords.TYPE:
pm.pushParser(new TypeAliasParser(this.unit, new TypeAlias()));
this.mode = SEPARATOR;
return;
case DyvilKeywords.HEADER:
final IToken next = token.next();
if (!Tokens.isIdentifier(next.type())) {
this.attributes = new AttributeList();
pm.report(next, "header.declaration.identifier");
return;
}
pm.skip();
if (this.unit.getHeaderDeclaration() != null) {
this.attributes = new AttributeList();
pm.report(token, "header.declaration.duplicate");
this.mode = SEPARATOR;
return;
}
final HeaderDeclaration declaration = new HeaderDeclaration(this.unit, next.raw(), next.nameValue(), this.attributes);
this.unit.setHeaderDeclaration(declaration);
// reset
this.attributes = new AttributeList();
this.mode = SEPARATOR;
return;
}
// Fallthrough
case CLASS:
if (this.parseAttribute(pm, token)) {
return;
}
final int classType;
if ((classType = ModifierParser.parseClassTypeModifier(token, pm)) >= 0) {
if ((this.flags & NO_CLASSES) != 0) {
pm.report(token, "header.class");
}
this.attributes.addFlag(classType);
pm.pushParser(new ClassDeclarationParser(this.unit, this.attributes));
// reset
this.attributes = new AttributeList();
this.mode = SEPARATOR;
return;
}
}
if (!checkEnd(pm, type)) {
pm.report(Markers.syntaxError(token, "header.element.invalid", token.toString()));
}
}
use of dyvilx.tools.compiler.ast.type.alias.TypeAlias in project Dyvil by Dyvil.
the class HeaderContext method read.
@Override
public void read(DataInput in) throws IOException {
this.headerDeclaration = new HeaderDeclaration(this);
this.headerDeclaration.read(in);
this.name = this.headerDeclaration.getName();
// Import Declarations
int imports = in.readShort();
for (int i = 0; i < imports; i++) {
ImportDeclaration id = new ImportDeclaration(null);
id.read(in);
this.addImport(id);
}
int operators = in.readShort();
for (int i = 0; i < operators; i++) {
Operator op = Operator.read(in);
this.addOperator(op);
}
int typeAliases = in.readShort();
for (int i = 0; i < typeAliases; i++) {
TypeAlias ta = new TypeAlias();
ta.read(in);
this.addTypeAlias(ta);
}
}
Aggregations