Skip to content
Snippets Groups Projects
Commit cd93cd0b authored by Jesper's avatar Jesper
Browse files

Add structured AST productions (ast-decl)

parent 0a642d2f
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,11 @@ Run `ng generate component component-name` to generate a new component. You can
## Build
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. For example:
ng build --prod --base-href "/doc/"
rsync -avz dist/ server:doc
## Running unit tests
......
++ Add thrown type descriptions.
++ Add structured production representation.
++ Make current member filter more noticeable.
++ Add class overview as default page.
++ Make the title be a link to the default page.
++ Add modifier information to non-attribute members (public, static, etc.).
-- Add structured production representation.
-- Add type hierarchy in type details.
-- Add direct subtypes.
-- Add declared-at info for types.
......@@ -73,14 +73,6 @@ export class AppComponent implements OnInit {
this.packageService.getPackages().then(packages => this.packages = packages);
}
declaredAt(member: Member): string {
if (member.doc) {
return `${member.doc.ragFile}:${member.doc.line}`;
} else {
return "";
}
}
filteredPackage(pkg: Package): boolean {
var filter = this.filter.toLowerCase();
for (var i = 0; i < pkg.groups.length; i++) {
......
......@@ -13,6 +13,7 @@ import { StringFilterPipe } from './string-filter.pipe';
import { SourceViewComponent } from './source-view/source-view.component';
import { EditorDirective } from './editor.directive';
import { DeclaredAtComponent } from './declared-at/declared-at.component';
import { AstDeclComponent } from './ast-decl/ast-decl.component';
@NgModule({
imports: [
......@@ -40,6 +41,7 @@ import { DeclaredAtComponent } from './declared-at/declared-at.component';
SourceViewComponent,
EditorDirective,
DeclaredAtComponent,
AstDeclComponent,
],
bootstrap: [ AppComponent ]
})
......
import {TypeRef} from '../type-ref';
export class AstComponent {
name: string;
type: TypeRef;
kind: string;
static fromJson(json: any): AstComponent {
var name: string = undefined;
if (json.n) {
name = json.n as string;
}
var kind = "regular";
if (json.k) {
kind = json.k;
}
return {
name: json.n as string,
type: TypeRef.fromJson(json.e),
kind: kind,
};
}
}
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AstDeclComponent } from './ast-decl.component';
describe('AstDeclComponent', () => {
let component: AstDeclComponent;
let fixture: ComponentFixture<AstDeclComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AstDeclComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AstDeclComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, Input } from '@angular/core';
import {Doc} from '../doc';
import {TypeRef} from '../type-ref';
import {AstDecl} from './ast-decl';
@Component({
selector: 'ast-decl',
styles: [`
.ast-decl {
font-weight: bold;
padding-left: 3em;
}
.ast-component {
padding-left: 4em;
}
`],
template: `
<p *ngIf="_decl">JastAdd production: <br>
<div class="ast-decl">{{_decl.name}}: <type-ref [type]="_decl.extends"></type-ref><!--
--><ng-container *ngIf="_decl.components"> ::= <!--
--><ng-container *ngFor="let comp of _decl.components"><!--
--><div class="ast-component"><!--
--><ng-container *ngIf="comp.kind == 'regular'"><!--
--><ng-container *ngIf="comp.name">{{comp.name}}:</ng-container><type-ref [type]="comp.type"></type-ref> <!--
--></ng-container><!--
--><ng-container *ngIf="comp.kind == 'list'"><!--
--><ng-container *ngIf="comp.name">{{comp.name}}:</ng-container><type-ref [type]="comp.type"></type-ref>* <!--
--></ng-container><!--
--><ng-container *ngIf="comp.kind == 'opt'"><!--
-->[<ng-container *ngIf="comp.name">{{comp.name}}:</ng-container><type-ref [type]="comp.type"></type-ref>] <!--
--></ng-container><!--
--><ng-container *ngIf="comp.kind == 'token'"><!--
-->&lt;<ng-container *ngIf="comp.name">{{comp.name}}:</ng-container><type-ref [type]="comp.type"></type-ref>&gt; <!--
--></ng-container><!--
--></div><!--
--></ng-container><!--
--></ng-container>
</div>
`,
})
export class AstDeclComponent {
private _decl: AstDecl;
constructor() { }
@Input()
set decl(decl: AstDecl) {
this._decl = decl;
}
}
import {TypeRef} from '../type-ref';
import {AstComponent} from './ast-component';
export class AstDecl {
name: string;
extends: TypeRef;
components?: AstComponent[];
static fromJson(json: any): AstDecl {
if (!json) {
return undefined;
}
var ext: TypeRef = undefined
if (json.e) {
ext = TypeRef.fromJson(json.e)
}
var components: AstComponent[] = undefined;
if (json.c) {
components = (json.c as any[]).map(c => AstComponent.fromJson(c));
}
return {
name: json.n as string,
extends: ext,
components: components,
};
}
}
import {AstDecl} from './ast-decl/ast-decl';
export class Doc {
ast: string;
astdecl: AstDecl;
ragFile: string;
line: number;
description: string;
apilevel: string;
params: string[]
paramDesc(name: string): string {
if (this.params) {
for (var i = 0; i < this.params.length; i++) {
var param = this.params[i];
var index = param.indexOf(' ');
if (index >= 0 && param.substring(0, index) === name) {
return ' : ' + param.substring(index + 1);
}
}
}
return '';
}
static fromJson(json: any): Doc {
var obj = Object.create(Doc.prototype);
return Object.assign(obj, json);
var astdecl: AstDecl = undefined;
if (json.astdecl) {
astdecl = AstDecl.fromJson(json.astdecl);
}
return {
ast: json.ast,
astdecl: astdecl,
ragFile: json.ragFile,
line: json.line,
description: json.description,
apilevel: json.apilevel,
params: json.params,
};
}
}
......@@ -9,9 +9,9 @@
<div *ngIf="type.doc">
<p [innerHTML]="type.doc.description">
<p *ngIf="type.doc.astdecl">JastAdd production: <b>{{type.doc.astdecl}}</b>
<p *ngIf="type.doc.astdecl"><ast-decl [decl]="type.doc.astdecl"></ast-decl>
<p *ngIf="type.doc && type.doc.ragFile"><declared-at [doc]="type.doc"></declared-at>
<p *ngIf="type.doc.ragFile"><declared-at [doc]="type.doc"></declared-at>
</div>
<div class="filter">
<input [(ngModel)]="filter" placeholder="Filter members...">
......
......@@ -47,13 +47,15 @@ export class TypeDetailsComponent implements OnInit {
});
}
declaredAt(doc: Doc): string {
return `${doc.ragFile}:${doc.line}`;
}
paramDesc(doc: Doc, name: string): string {
if (doc) {
return doc.paramDesc(name);
if (doc.params) {
for (var i = 0; i < doc.params.length; i++) {
var param = doc.params[i];
var index = param.indexOf(' ');
if (index >= 0 && param.substring(0, index) === name) {
return ' : ' + param.substring(index + 1);
}
}
}
return '';
}
......
......@@ -4,11 +4,11 @@ import {TypeRef} from './type-ref';
import {InheritedMembers} from './inherited-members';
export class Type {
id: string;
kind: string;
name: string;
pkg: string;
mods: string[];
id: string;
doc: Doc;
groups: { [id: string] : Member[]; };
args: TypeRef[]; // Type arguments.
......@@ -20,6 +20,10 @@ export class Type {
subtypes: TypeRef[];
static fromJson(json: any): Type {
var doc: Doc = undefined;
if (json.doc) {
doc = Doc.fromJson(json.doc);
}
var groups = {};
if (json.groups) {
for (var i = 0; i < json.groups.length; i++) {
......@@ -33,7 +37,7 @@ export class Type {
if (json.superclass) {
superclass = TypeRef.fromJson(json.superclass);
}
var superinterfaces: TypeRef[] = undefined;
var superinterfaces: TypeRef[] = [];
if (json.superinterfaces) {
superinterfaces = (json.superinterfaces as TypeRef[]).map(TypeRef.fromJson);
}
......@@ -60,16 +64,22 @@ export class Type {
if (json.subtypes) {
subtypes = (json.subtypes as any[]).map(arg => TypeRef.fromJson(arg));
}
return Object.assign({}, json, {
groups: groups,
return {
id: TypeRef.typeId(json.name, json.id),
kind: json.kind,
name: json.name,
pkg: json.pkg,
mods: json.mods as string[],
doc: doc,
groups: groups,
args: args,
superclass: superclass,
superinterfaces: superinterfaces,
inherited_methods: inherited_methods,
inherited_attributes: inherited_attributes,
inherited_fields: inherited_fields,
subtypes: subtypes,
});
};
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment