Module syntax. doesn't really do anything yet. well, it groups definitions
This commit is contained in:
parent
d3248be4d9
commit
ed103ed2cb
3 changed files with 77 additions and 50 deletions
|
|
@ -150,6 +150,8 @@ export class Parser {
|
|||
}
|
||||
}
|
||||
|
||||
private currentModule: string | undefined;
|
||||
|
||||
parse(): { definitions: Definition[], typeDefinitions: TypeDefinition[], classDefinitions: ClassDefinition[], instanceDeclarations: InstanceDeclaration[] } {
|
||||
const definitions: Definition[] = [];
|
||||
const typeDefinitions: TypeDefinition[] = [];
|
||||
|
|
@ -157,22 +159,41 @@ export class Parser {
|
|||
const instanceDeclarations: InstanceDeclaration[] = [];
|
||||
|
||||
while (this.current().kind !== 'eof') {
|
||||
// Module tags
|
||||
if (this.current().kind === 'at') {
|
||||
this.advance();
|
||||
if (this.current().kind === 'ident' && this.peek().kind !== 'equals' && this.peek().kind !== 'colon') {
|
||||
this.currentModule = (this.advance() as { value: string }).value;
|
||||
} else {
|
||||
this.currentModule = undefined;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.current().kind === 'type-ident') {
|
||||
let offset = 1;
|
||||
while (this.peek(offset).kind === 'ident') offset++;
|
||||
const after = this.peek(offset);
|
||||
|
||||
if (after.kind === 'open-brace') {
|
||||
classDefinitions.push(this.parseClassDefinition());
|
||||
const cd = this.parseClassDefinition();
|
||||
if (this.currentModule) cd.module = this.currentModule;
|
||||
classDefinitions.push(cd);
|
||||
} else if (after.kind === 'colon') {
|
||||
instanceDeclarations.push(this.parseInstanceDeclaration());
|
||||
const id = this.parseInstanceDeclaration();
|
||||
if (this.currentModule) id.module = this.currentModule;
|
||||
instanceDeclarations.push(id);
|
||||
} else {
|
||||
typeDefinitions.push(this.parseTypeDefinition());
|
||||
const td = this.parseTypeDefinition();
|
||||
if (this.currentModule) td.module = this.currentModule;
|
||||
typeDefinitions.push(td);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
definitions.push(this.parseDefinition());
|
||||
const def = this.parseDefinition();
|
||||
if (this.currentModule) def.module = this.currentModule;
|
||||
definitions.push(def);
|
||||
}
|
||||
|
||||
return { definitions, typeDefinitions, classDefinitions, instanceDeclarations };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue