Skip to content

Commit

Permalink
fix: fixed linting issues, refactoring some code along the way
Browse files Browse the repository at this point in the history
affects: @postdfm/dfm2ast
  • Loading branch information
spiltcoffee committed Mar 9, 2019
1 parent 5aac96e commit b158774
Show file tree
Hide file tree
Showing 20 changed files with 213 additions and 154 deletions.
153 changes: 0 additions & 153 deletions packages/@postdfm/dfm2ast/src/ast.ts

This file was deleted.

8 changes: 8 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/astNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ASTType } from "./astType";

export class ASTNode {
public astType: ASTType;
constructor(astType: ASTType) {
this.astType = astType;
}
}
14 changes: 14 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/astType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export enum ASTType {
String = "string",
HexString = "hexString",
Integer = "integer",
Double = "double",
Boolean = "boolean",
Qualified = "qualified",
Item = "item",
StringList = "stringList",
QualifiedList = "qualifiedList",
ItemList = "itemList",
Property = "property",
Object = "object"
}
39 changes: 39 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/formObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ASTNode } from "./astNode";
import { ASTType } from "./astType";
import { ObjectKind } from "./objectKind";
import { Property } from "./property";

export class FormObject extends ASTNode {
public kind: ObjectKind;
public name: string;
public type: string;
public order: number;
public properties: Property[];
public children: FormObject[];

constructor(
kind: ObjectKind,
name: string,
type: string,
order: number,
properties?: Property[],
children?: FormObject[]
) {
super(ASTType.Object);
this.kind = kind;
this.name = name;
this.type = type;

if (order) {
this.order = order;
}

if (properties) {
this.properties = properties;
}

if (children) {
this.children = children;
}
}
}
23 changes: 23 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export { ASTType } from "./astType";
export { ASTNode } from "./astNode";

export { Value } from "./value/value";
export { StringValue } from "./value/stringValue";
export { HexStringValue } from "./value/hexStringValue";
export { IntegerValue } from "./value/integerValue";
export { DoubleValue } from "./value/doubleValue";
export { BooleanValue } from "./value/booleanValue";
export { QualifiedValue } from "./value/qualifiedValue";

export { Item } from "./item";

export { List } from "./list/list";
export { QualifiedList } from "./list/qualifiedList";
export { StringList } from "./list/stringList";
export { ItemList } from "./list/itemList";

export { Property } from "./property";

export { ObjectKind } from "./objectKind";

export { FormObject } from "./formObject";
12 changes: 12 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ASTNode } from "./astNode";
import { ASTType } from "./astType";
import { Property } from "./property";

export class Item extends ASTNode {
public properties: Property[];

constructor(properties: Property[]) {
super(ASTType.Item);
this.properties = properties;
}
}
9 changes: 9 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/list/itemList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ASTType } from "../astType";
import { Item } from "../item";
import { List } from "./list";

export class ItemList extends List<Item> {
constructor(values: Item[]) {
super(ASTType.ItemList, values);
}
}
11 changes: 11 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/list/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ASTNode } from "../astNode";
import { ASTType } from "../astType";

export class List<T> extends ASTNode {
public values: T[];

constructor(astType: ASTType, values: T[]) {
super(astType);
this.values = values;
}
}
9 changes: 9 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/list/qualifiedList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ASTType } from "../astType";
import { QualifiedValue } from "../value/qualifiedValue";
import { List } from "./list";

export class QualifiedList extends List<QualifiedValue> {
constructor(values: QualifiedValue[]) {
super(ASTType.QualifiedList, values);
}
}
9 changes: 9 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/list/stringList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ASTType } from "../astType";
import { StringValue } from "../value/stringValue";
import { List } from "./list";

export class StringList extends List<StringValue> {
constructor(values: StringValue[]) {
super(ASTType.StringList, values);
}
}
5 changes: 5 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/objectKind.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum ObjectKind {
Object = "object",
Inline = "inline",
Inherited = "inherited"
}
15 changes: 15 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/property.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ASTNode } from "./astNode";
import { ASTType } from "./astType";
import { List } from "./list/list";
import { Value } from "./value/value";

export class Property extends ASTNode {
public name: string;
public value: Value<any> | List<any>;

constructor(name: string, value: Value<any> | List<any>) {
super(ASTType.Property);
this.name = name;
this.value = value;
}
}
8 changes: 8 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/value/booleanValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ASTType } from "../astType";
import { Value } from "./value";

export class BooleanValue extends Value<boolean> {
constructor(value: boolean) {
super(ASTType.Boolean, value);
}
}
8 changes: 8 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/value/doubleValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ASTType } from "../astType";
import { Value } from "./value";

export class DoubleValue extends Value<number> {
constructor(value: number) {
super(ASTType.Double, value);
}
}
8 changes: 8 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/value/hexStringValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ASTType } from "../astType";
import { Value } from "./value";

export class HexStringValue extends Value<string> {
constructor(value: string) {
super(ASTType.HexString, value);
}
}
8 changes: 8 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/value/integerValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ASTType } from "../astType";
import { Value } from "./value";

export class IntegerValue extends Value<number> {
constructor(value: number) {
super(ASTType.Integer, value);
}
}
8 changes: 8 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/value/qualifiedValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ASTType } from "../astType";
import { Value } from "./value";

export class QualifiedValue extends Value<string> {
constructor(value: string) {
super(ASTType.Qualified, value);
}
}
8 changes: 8 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/value/stringValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ASTType } from "../astType";
import { Value } from "./value";

export class StringValue extends Value<string> {
constructor(value: string) {
super(ASTType.String, value);
}
}
10 changes: 10 additions & 0 deletions packages/@postdfm/dfm2ast/src/ast/value/value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ASTNode } from "../astNode";
import { ASTType } from "../astType";

export class Value<T> extends ASTNode {
public value: T;
constructor(astType: ASTType, value: T) {
super(astType);
this.value = value;
}
}
2 changes: 1 addition & 1 deletion packages/@postdfm/dfm2ast/src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as nearley from "nearley";
import * as grammar from "./grammar";
import * as AST from "./ast";
import * as grammar from "./grammar";

export function parse(dfm: string): AST.FormObject {
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
Expand Down

0 comments on commit b158774

Please sign in to comment.