-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AST): introduce YAML AST models and predicates
Refs #1
- Loading branch information
Showing
24 changed files
with
321 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import stampit from 'stampit'; | ||
|
||
import Node from '../../Node'; | ||
|
||
interface YamlAlias extends Node { | ||
type: 'alias'; | ||
content: string | null; | ||
} | ||
|
||
const YamlAlias: stampit.Stamp<YamlAlias> = stampit(Node, { | ||
statics: { | ||
type: 'alias', | ||
}, | ||
props: { | ||
content: null, | ||
}, | ||
init({ content = null } = {}) { | ||
this.content = content; | ||
}, | ||
}); | ||
|
||
export default YamlAlias; |
11 changes: 11 additions & 0 deletions
11
apidom/packages/apidom-ast/src/nodes/yaml/YamlCollection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlNode from './YamlNode'; | ||
|
||
interface YamlCollection extends YamlNode { | ||
readonly children: Array<unknown>; | ||
} | ||
|
||
const YamlCollection: stampit.Stamp<YamlCollection> = stampit(YamlNode, {}); | ||
|
||
export default YamlCollection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import stampit from 'stampit'; | ||
|
||
import Node from '../../Node'; | ||
|
||
interface YamlComment extends Node { | ||
type: 'comment'; | ||
content: string | null; | ||
} | ||
|
||
const YamlComment: stampit.Stamp<YamlComment> = stampit(Node, { | ||
statics: { | ||
type: 'comment', | ||
}, | ||
props: { | ||
content: null, | ||
}, | ||
init({ content = null } = {}) { | ||
this.content = content; | ||
}, | ||
}); | ||
|
||
export default YamlComment; |
39 changes: 39 additions & 0 deletions
39
apidom/packages/apidom-ast/src/nodes/yaml/YamlDirective.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import stampit from 'stampit'; | ||
import { mergeRight } from 'ramda'; | ||
|
||
import Node from '../../Node'; | ||
|
||
interface YamlDirectiveParameters { | ||
version: string | null; | ||
handle: string | null; | ||
prefix: string | null; | ||
} | ||
|
||
interface YamlDirective extends Node { | ||
type: 'directive'; | ||
name: string | null; | ||
parameters: YamlDirectiveParameters; | ||
} | ||
|
||
const YamlDirective: stampit.Stamp<YamlDirective> = stampit(Node, { | ||
statics: { | ||
type: 'directive', | ||
}, | ||
props: { | ||
name: null, | ||
parameters: null, | ||
}, | ||
init({ name = null, parameters = {} } = {}) { | ||
this.name = name; | ||
this.parameters = mergeRight( | ||
{ | ||
version: null, | ||
handle: null, | ||
prefix: null, | ||
}, | ||
parameters, | ||
); | ||
}, | ||
}); | ||
|
||
export default YamlDirective; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import stampit from 'stampit'; | ||
|
||
import Node from '../../Node'; | ||
|
||
interface YamlDocument extends Node { | ||
type: 'document'; | ||
} | ||
|
||
const YamlDocument: stampit.Stamp<YamlDocument> = stampit(Node, { | ||
statics: { | ||
type: 'document', | ||
}, | ||
}); | ||
|
||
export default YamlDocument; |
14 changes: 14 additions & 0 deletions
14
apidom/packages/apidom-ast/src/nodes/yaml/YamlKeyValuePair.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import stampit from 'stampit'; | ||
import YamlNode from './YamlNode'; | ||
|
||
interface YamlKeyValuePair extends YamlNode { | ||
type: 'keyValuePair'; | ||
} | ||
|
||
const YamlKeyValuePair: stampit.Stamp<YamlKeyValuePair> = stampit(YamlNode, { | ||
statics: { | ||
type: 'keyValuePair', | ||
}, | ||
}); | ||
|
||
export default YamlKeyValuePair; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import stampit from 'stampit'; | ||
import { isArray } from 'ramda-adjunct'; | ||
|
||
import YamlCollection from './YamlCollection'; | ||
import { isKeyValuePair } from './predicates'; | ||
import YamlKeyValuePair from './YamlKeyValuePair'; | ||
|
||
interface YamlMapping extends YamlCollection { | ||
type: 'mapping'; | ||
readonly content: Array<YamlKeyValuePair>; | ||
} | ||
|
||
const YamlMapping: stampit.Stamp<YamlMapping> = stampit(YamlCollection, { | ||
statics: { | ||
type: 'mapping', | ||
}, | ||
methods: { | ||
get content(): Array<YamlKeyValuePair> { | ||
return isArray(this.children) ? this.children.filter(isKeyValuePair) : []; | ||
}, | ||
}, | ||
}); | ||
|
||
export default YamlMapping; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import stampit from 'stampit'; | ||
|
||
import Node from '../../Node'; | ||
|
||
interface YamlNode extends Node { | ||
content: unknown | null; | ||
anchor: unknown | null; | ||
tag: unknown | null; | ||
} | ||
|
||
const YamlNode: stampit.Stamp<YamlNode> = stampit(Node, { | ||
props: { | ||
content: null, | ||
anchor: null, | ||
tag: null, | ||
}, | ||
init({ content = null, anchor = null, tag = null } = {}) { | ||
this.content = content; | ||
this.anchor = anchor; | ||
this.tag = tag; | ||
}, | ||
}); | ||
|
||
export default YamlNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlNode from './YamlNode'; | ||
|
||
interface YamlScalar extends YamlNode { | ||
type: 'scalar'; | ||
content: string | null; | ||
} | ||
|
||
const YamlScalar: stampit.Stamp<YamlScalar> = stampit(YamlNode, { | ||
statics: { | ||
type: 'scalar', | ||
}, | ||
}); | ||
|
||
export default YamlScalar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import stampit from 'stampit'; | ||
import { anyPass } from 'ramda'; | ||
import { isArray } from 'ramda-adjunct'; | ||
|
||
import YamlCollection from './YamlCollection'; | ||
import YamlMapping from './YamlMapping'; | ||
import YamlScalar from './YamlScalar'; | ||
import YamlAlias from './YamlAlias'; | ||
import { isMapping, isScalar, isSequence, isAlias } from './predicates'; | ||
|
||
interface YamlSequence extends YamlCollection { | ||
type: 'sequence'; | ||
readonly content: Array<YamlSequence | YamlMapping | YamlScalar | YamlAlias>; | ||
} | ||
|
||
const YamlSequence: stampit.Stamp<YamlSequence> = stampit(YamlCollection, { | ||
statics: { | ||
type: 'sequence', | ||
}, | ||
methods: { | ||
get content(): Array<YamlSequence | YamlMapping | YamlScalar | YamlAlias> { | ||
return isArray(this.children) | ||
? this.children.filter(anyPass([isSequence, isMapping, isScalar, isAlias])) | ||
: []; | ||
}, | ||
}, | ||
}); | ||
|
||
export default YamlSequence; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import stampit from 'stampit'; | ||
|
||
import Node from '../../Node'; | ||
import YamlDocument from './YamlDocument'; | ||
|
||
interface YamlStream extends Node { | ||
type: 'stream'; | ||
children: Array<YamlDocument>; | ||
} | ||
|
||
const YamlStream: stampit.Stamp<YamlStream> = stampit(Node, { | ||
statics: { | ||
type: 'stream', | ||
}, | ||
}); | ||
|
||
export default YamlStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import stampit from 'stampit'; | ||
|
||
import Node from '../../Node'; | ||
|
||
enum YamlNodeKind { | ||
Scalar = 'Scalar', | ||
Sequence = 'Sequence', | ||
Mapping = 'Mapping', | ||
} | ||
|
||
interface YamlTag { | ||
type: 'tag'; | ||
name: string | null; | ||
kind: YamlNodeKind | null; | ||
} | ||
|
||
const YamlTag: stampit.Stamp<YamlTag> = stampit(Node, { | ||
statics: { | ||
type: 'tag', | ||
}, | ||
props: { | ||
name: null, | ||
kind: null, | ||
}, | ||
init({ name = null, kind = null } = {}) { | ||
this.name = name; | ||
this.kind = kind; | ||
}, | ||
}); | ||
|
||
export default YamlTag; |
Oops, something went wrong.