31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import type { Inline, Node, Segment, SourceRange, TokenRole } from '../contract'
|
|
|
|
/** 库规则共用的拼属性表文字的办法。 */
|
|
|
|
export function range(node: Node): SourceRange {
|
|
return { startIndex: node.startIndex, endIndex: node.endIndex }
|
|
}
|
|
|
|
export function plain(text: string): Segment {
|
|
return { text, role: 'plain' }
|
|
}
|
|
|
|
/** 说明词:N 个、未标注、展开……。 */
|
|
export function hint(text: string): Segment {
|
|
return { text, role: 'hint' }
|
|
}
|
|
|
|
/** 规则自己的用词里当关键字着色的:主键、外键、默认……。 */
|
|
export function word(text: string): Segment {
|
|
return { text, role: 'storage' }
|
|
}
|
|
|
|
/** 源码里的一个名字照抄,带源码下标(能跳到定义、高亮各处出现)。 */
|
|
export function name(node: Node, role: TokenRole): Segment {
|
|
return { text: node.text, role, offset: node.startIndex }
|
|
}
|
|
|
|
export function joined(parts: Inline[][], separator: Segment): Inline[] {
|
|
return parts.flatMap((part, i) => i > 0 ? [{ ...separator }, ...part] : part)
|
|
}
|