Skip to content

Commit

Permalink
feat: add CST to AST transformer for tree-sitter
Browse files Browse the repository at this point in the history
Refs #35
  • Loading branch information
char0n committed Jul 31, 2020
1 parent b33cff7 commit 9d3f03c
Show file tree
Hide file tree
Showing 25 changed files with 1,208 additions and 110 deletions.
367 changes: 295 additions & 72 deletions apidom/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apidom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
"@char0n/npm-audit": "gist:2964395223d7943c10396f59df9a8ea0",
"@commitlint/cli": "=9.1.2",
"@commitlint/config-conventional": "=8.3.4",
"@types/chai": "=4.2.12",
"@types/mocha": "=7.0.2",
"@typescript-eslint/eslint-plugin": "=3.0.2",
"@typescript-eslint/parser": "=3.0.2",
"apidom": "file:packages/apidom",
"apidom-ns-openapi3-1": "file:packages/apidom-ns-openapi3-1",
"apidom-parser-adapter-openapi3-1": "file:packages/apidom-parser-adapter-openapi3-1",
"babel-loader": "=8.1.0",
"chai": "=4.2.0",
"core-js": "=3.6.5",
"cross-env": "=7.0.2",
"eslint": "=7.1.0",
Expand Down
19 changes: 19 additions & 0 deletions apidom/packages/apidom-ast/src/ParseResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import stampit from 'stampit';

interface ParseResult {
type: 'parseResult';
errors: unknown[];
annotations: unknown[];
rootNode: unknown;
}

const ParseResult: stampit.Stamp<ParseResult> = stampit({
props: {
type: 'parseResult',
errors: [],
annotations: [],
rootNode: null,
},
});

export default ParseResult;
30 changes: 26 additions & 4 deletions apidom/packages/apidom-ast/src/Position.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
import stampit from 'stampit';

interface Point {
row: number | null;
column: number | null;
char: number | null;
}

interface Position {
row: number;
column: number;
type: 'position';
startPosition: Point | null;
endPosition: Point | null;
}

const Position: stampit.Stamp<Position> = stampit({
export const Point: stampit.Stamp<Point> = stampit({
props: {
type: 'point',
row: null,
column: null,
char: null,
},
init({ row = null, column = null }) {
init({ row = null, column = null, char = null } = {}) {
this.row = row;
this.column = column;
this.char = char;
},
});

const Position: stampit.Stamp<Position> = stampit({
props: {
type: 'position',
start: null,
end: null,
},
init({ start = null, end = null } = {}) {
this.start = start;
this.end = end;
},
});

Expand Down
27 changes: 15 additions & 12 deletions apidom/packages/apidom-ast/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
export { default as JsonDocument } from './nodes/JsonDocument';
export { default as JsonObject } from './nodes/JsonObject';
export { default as JsonProperty } from './nodes/JsonProperty';
export { default as JsonArray } from './nodes/JsonArray';
export { default as JsonValue } from './nodes/JsonValue';
export { default as JsonKey } from './nodes/JsonKey';
export { default as JsonComment } from './nodes/JsonComment';
export { default as JsonString } from './nodes/JsonString';
export { default as JsonNumber } from './nodes/JsonNumber';
export { default as JsonTrue } from './nodes/JsonTrue';
export { default as JsonFalse } from './nodes/JsonFalse';
export { default as JsonNull } from './nodes/JsonNull';
export { default as JsonDocument } from './nodes/json/JsonDocument';
export { default as JsonObject } from './nodes/json/JsonObject';
export { default as JsonProperty } from './nodes/json/JsonProperty';
export { default as JsonArray } from './nodes/json/JsonArray';
export { default as JsonValue } from './nodes/json/JsonValue';
export { default as JsonKey } from './nodes/json/JsonKey';
export { default as JsonComment } from './nodes/json/JsonComment';
export { default as JsonString } from './nodes/json/JsonString';
export { default as JsonNumber } from './nodes/json/JsonNumber';
export { default as JsonTrue } from './nodes/json/JsonTrue';
export { default as JsonFalse } from './nodes/json/JsonFalse';
export { default as JsonNull } from './nodes/json/JsonNull';
export { default as ParseResult } from './ParseResult';
export { default as Position } from './Position';
export { Point } from './Position';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import stampit from 'stampit';

import JsonNode from './traits/JsonNode';
import JsonComments from './traits/JsonComments';
import NodeType from '../node-type';
import NodeType from './node-type';
import JsonComment from './JsonComment';

type JsonArray = JsonNode & JsonComment;
Expand All @@ -11,8 +11,10 @@ const JsonArray: stampit.Stamp<JsonArray> = stampit(JsonNode, JsonComments, {
props: {
items: [],
},
init() {
init({ items = [], position = null } = {}) {
this.type = NodeType.Array;
this.items = items;
this.position = position;
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stampit from 'stampit';

import JsonValue from './JsonValue';
import NodeType from '../node-type';
import NodeType from './node-type';

type JsonComment = JsonValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import stampit from 'stampit';

import JsonNode from './traits/JsonNode';
import JsonComments from './traits/JsonComments';
import NodeType from '../node-type';
import NodeType from './node-type';

type JsonDocument = JsonNode & JsonComments;
interface JsonDocument extends JsonNode, JsonComments {
child: JsonNode | null;
}

const JsonDocument: stampit.Stamp<JsonDocument> = stampit(JsonNode, JsonComments, {
props: {
child: null,
},
init() {
init({ child = null, position = null } = {}) {
this.type = NodeType.Document;
this.child = child;
this.position = position;
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stampit from 'stampit';

import JsonValue from './JsonValue';
import NodeType from '../node-type';
import NodeType from './node-type';

type JsonFalse = JsonValue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stampit from 'stampit';

import JsonValue from './JsonValue';
import NodeType from '../node-type';
import NodeType from './node-type';

type JsonKey = JsonValue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stampit from 'stampit';

import JsonValue from './JsonValue';
import NodeType from '../node-type';
import NodeType from './node-type';

type JsonNull = JsonValue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stampit from 'stampit';

import JsonValue from './JsonValue';
import NodeType from '../node-type';
import NodeType from './node-type';

type JsonNumber = JsonValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import stampit from 'stampit';

import JsonNode from './traits/JsonNode';
import JsonComments from './traits/JsonComments';
import NodeType from '../node-type';
import NodeType from './node-type';

type JsonObject = JsonNode & JsonComments;
interface JsonObject extends JsonNode, JsonComments {
properties: unknown;
}

const JsonObject: stampit.Stamp<JsonObject> = stampit(JsonNode, JsonComments, {
props: {
properties: [],
},
init() {
init({ properties = null, position = null } = {}) {
this.type = NodeType.Object;
this.properties = properties;
this.position = position;
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stampit from 'stampit';

import JsonNode from './traits/JsonNode';
import NodeType from '../node-type';
import NodeType from './node-type';
import JsonKey from './JsonKey';
import JsonValue from './JsonValue';

Expand All @@ -15,8 +15,11 @@ const JsonProperty: stampit.Stamp<JsonProperty> = stampit(JsonNode, {
key: null,
value: null,
},
init() {
init({ key = null, value = null, position = null } = {}) {
this.type = NodeType.Property;
this.key = key;
this.value = value;
this.position = position;
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stampit from 'stampit';

import JsonValue from './JsonValue';
import NodeType from '../node-type';
import NodeType from './node-type';

type JsonString = JsonValue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stampit from 'stampit';

import JsonValue from './JsonValue';
import NodeType from '../node-type';
import NodeType from './node-type';

type JsonTrue = JsonValue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import stampit from 'stampit';

import JsonNode from './traits/JsonNode';
import NodeType from '../node-type';
import NodeType from './node-type';

interface JsonValue extends JsonNode {
type: NodeType.Value;
Expand All @@ -12,8 +12,10 @@ const JsonValue: stampit.Stamp<JsonValue> = stampit(JsonNode, {
props: {
value: null,
},
init() {
init({ value = null, position = null } = {}) {
this.type = NodeType.Value;
this.value = value;
this.position = position;
},
});

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import stampit from 'stampit';
import NodeType from '../../node-type';
import Position from '../../Position';
import NodeType from '../node-type';
import Position from '../../../Position';

interface JsonNode {
type: NodeType;
Expand Down
Loading

0 comments on commit 9d3f03c

Please sign in to comment.