-
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.
Refs #1
- Loading branch information
Showing
22 changed files
with
320 additions
and
8 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
apidom/packages/apidom-ast/src/nodes/yaml/YamlBlockScalar.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,51 @@ | ||
import stampit from 'stampit'; | ||
import { test } from 'ramda'; | ||
import { isString } from 'ramda-adjunct'; | ||
|
||
import YamlScalar from './YamlScalar'; | ||
|
||
enum BlockStyleIndicator { | ||
LITERAL = 'LITERAL', | ||
FOLDED = 'FOLDED', | ||
} | ||
|
||
enum BlockChompingIndicator { | ||
CLIP = 'CLIP', | ||
STRIP = 'STRIP', | ||
KEEP = 'KEEP', | ||
} | ||
|
||
interface YamlBlockScalar extends YamlScalar { | ||
readonly style: BlockStyleIndicator; | ||
readonly chomping: BlockChompingIndicator; | ||
} | ||
|
||
const YamlBlockScalar: stampit.Stamp<YamlBlockScalar> = stampit(YamlScalar, { | ||
statics: { | ||
type: 'blockScalar', | ||
}, | ||
props: { | ||
style: BlockStyleIndicator.LITERAL, | ||
chomping: BlockChompingIndicator.CLIP, | ||
}, | ||
methods: { | ||
get style(): BlockStyleIndicator { | ||
return isString(this.value) && test(/^|/, this.value) | ||
? BlockStyleIndicator.LITERAL | ||
: BlockStyleIndicator.FOLDED; | ||
}, | ||
get chomping(): BlockChompingIndicator { | ||
/* eslint-disable no-nested-ternary */ | ||
return !isString(this.value) | ||
? BlockChompingIndicator.CLIP | ||
: test(/^(>|\|)\+/, this.value) | ||
? BlockChompingIndicator.KEEP | ||
: test(/^(>|\|)-/, this.value) | ||
? BlockChompingIndicator.STRIP | ||
: BlockChompingIndicator.CLIP; | ||
/* eslint-enable */ | ||
}, | ||
}, | ||
}); | ||
|
||
export default YamlBlockScalar; |
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,21 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlNode from './YamlNode'; | ||
|
||
interface YamlComment extends YamlNode { | ||
value: string | null; | ||
} | ||
|
||
const YamlComment: stampit.Stamp<YamlComment> = stampit(YamlNode, { | ||
statics: { | ||
type: 'comment', | ||
}, | ||
props: { | ||
value: null, | ||
}, | ||
init({ value = null } = {}) { | ||
this.value = value; | ||
}, | ||
}); | ||
|
||
export default YamlComment; |
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,23 @@ | ||
import stampit from 'stampit'; | ||
import { head } from 'ramda'; | ||
|
||
import YamlNode from './YamlNode'; | ||
|
||
interface YamlDocument extends YamlNode { | ||
child: unknown | null; | ||
} | ||
|
||
const YamlDocument: stampit.Stamp<YamlDocument> = stampit(YamlNode, { | ||
statics: { | ||
type: 'document', | ||
}, | ||
methods: { | ||
// @ts-ignore | ||
get child(): unknown { | ||
// @ts-ignore | ||
return head(this.children); | ||
}, | ||
}, | ||
}); | ||
|
||
export default YamlDocument; |
13 changes: 13 additions & 0 deletions
13
apidom/packages/apidom-ast/src/nodes/yaml/YamlDoubleQuoteScalar.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,13 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlScalar from './YamlScalar'; | ||
|
||
type YamlDoubleQuoteScalar = YamlScalar; | ||
|
||
const YamlDoubleQuoteScalar: stampit.Stamp<YamlDoubleQuoteScalar> = stampit(YamlScalar, { | ||
statics: { | ||
type: 'doubleQuoteScalar', | ||
}, | ||
}); | ||
|
||
export default YamlDoubleQuoteScalar; |
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,23 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlNode from './YamlNode'; | ||
import YamlPair from './YamlPair'; | ||
import { isPair } from './predicates'; | ||
|
||
interface YamlMap extends YamlNode { | ||
readonly entries: Array<YamlPair>; | ||
} | ||
|
||
const YamlStream: stampit.Stamp<YamlMap> = stampit(YamlNode, { | ||
statics: { | ||
type: 'map', | ||
}, | ||
methods: { | ||
get entries(): Array<YamlPair> { | ||
// @ts-ignore | ||
return this.children.filter(isPair); | ||
}, | ||
}, | ||
}); | ||
|
||
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,18 @@ | ||
import stampit from 'stampit'; | ||
|
||
import Node from '../../Node'; | ||
|
||
interface YamlNode extends Node { | ||
tag: unknown | null; | ||
} | ||
|
||
const YamlNode: stampit.Stamp<YamlNode> = stampit(Node, { | ||
props: { | ||
tag: null, | ||
}, | ||
init({ tag = null } = {}) { | ||
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,31 @@ | ||
import stampit from 'stampit'; | ||
import { anyPass } from 'ramda'; | ||
|
||
import YamlNode from './YamlNode'; | ||
import { isScalar, isMap, isSeq } from './predicates'; | ||
import YamlScalar from './YamlScalar'; | ||
|
||
interface YamlPair extends YamlNode { | ||
readonly key: unknown; | ||
readonly value: unknown; | ||
} | ||
|
||
const YamlPair: stampit.Stamp<YamlPair> = stampit(YamlNode, { | ||
statics: { | ||
type: 'pair', | ||
}, | ||
methods: { | ||
// @ts-ignore | ||
get key(): YamlScalar { | ||
// @ts-ignore | ||
return this.children.find(isScalar); | ||
}, | ||
// @ts-ignore | ||
get value(): unknown { | ||
// @ts-ignore | ||
return this.children.find(anyPass([isMap, isSeq, isScalar])); | ||
}, | ||
}, | ||
}); | ||
|
||
export default YamlPair; |
13 changes: 13 additions & 0 deletions
13
apidom/packages/apidom-ast/src/nodes/yaml/YamlPlainScalar.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,13 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlScalar from './YamlScalar'; | ||
|
||
type YamlPlainScalar = YamlScalar; | ||
|
||
const YamlPlainScalar: stampit.Stamp<YamlPlainScalar> = stampit(YamlScalar, { | ||
statics: { | ||
type: 'plainScalar', | ||
}, | ||
}); | ||
|
||
export default YamlPlainScalar; |
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,21 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlNode from './YamlNode'; | ||
|
||
interface YamlScalar extends YamlNode { | ||
value: string | null; | ||
} | ||
|
||
const YamlScalar: stampit.Stamp<YamlScalar> = stampit(YamlNode, { | ||
statics: { | ||
type: 'scalar', | ||
}, | ||
props: { | ||
value: null, | ||
}, | ||
init({ value = null } = {}) { | ||
this.value = value; | ||
}, | ||
}); | ||
|
||
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,21 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlNode from './YamlNode'; | ||
|
||
interface YamlSeq extends YamlNode { | ||
readonly items: Array<unknown>; | ||
} | ||
|
||
const YamlSeq: stampit.Stamp<YamlSeq> = stampit(YamlNode, { | ||
statics: { | ||
type: 'seq', | ||
}, | ||
methods: { | ||
get items(): Array<unknown> { | ||
// @ts-ignore | ||
return this.children; | ||
}, | ||
}, | ||
}); | ||
|
||
export default YamlSeq; |
13 changes: 13 additions & 0 deletions
13
apidom/packages/apidom-ast/src/nodes/yaml/YamlSingleQuoteScalar.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,13 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlScalar from './YamlScalar'; | ||
|
||
type YamlSingleQuoteScalar = YamlScalar; | ||
|
||
const YamlSingleQuoteScalar: stampit.Stamp<YamlSingleQuoteScalar> = stampit(YamlScalar, { | ||
statics: { | ||
type: 'singleQuoteScalar', | ||
}, | ||
}); | ||
|
||
export default YamlSingleQuoteScalar; |
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,13 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlNode from './YamlNode'; | ||
|
||
type YamlStream = YamlNode; | ||
|
||
const YamlStream: stampit.Stamp<YamlStream> = stampit(YamlNode, { | ||
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,21 @@ | ||
import stampit from 'stampit'; | ||
|
||
import YamlNode from './YamlNode'; | ||
|
||
interface YamlTag extends YamlNode { | ||
value: string | null; | ||
} | ||
|
||
const YamlTag: stampit.Stamp<YamlTag> = stampit(YamlNode, { | ||
statics: { | ||
type: 'tag', | ||
}, | ||
props: { | ||
value: null, | ||
}, | ||
init({ value = null } = {}) { | ||
this.value = value; | ||
}, | ||
}); | ||
|
||
export default YamlTag; |
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 { anyPass } from 'ramda'; | ||
import { isNodeType } from '../../predicates'; | ||
|
||
export const isStream = isNodeType('stream'); | ||
|
||
export const isDocument = isNodeType('document'); | ||
|
||
export const isMap = isNodeType('map'); | ||
|
||
export const isSeq = isNodeType('seq'); | ||
|
||
export const isPair = isNodeType('pair'); | ||
|
||
export const isTag = isNodeType('tag'); | ||
|
||
export const isPlainScalar = isNodeType('plainScalar'); | ||
|
||
export const isSingleQuoteScalar = isNodeType('singleQuoteScalar'); | ||
|
||
export const isDoubleQuoteScalar = isNodeType('doubleQuoteScalar'); | ||
|
||
export const isBlockScalar = isNodeType('blockScalar'); | ||
|
||
export const isScalar = anyPass([ | ||
isPlainScalar, | ||
isSingleQuoteScalar, | ||
isDoubleQuoteScalar, | ||
isBlockScalar, | ||
]); |
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
Oops, something went wrong.