MCPcopy Create free account
hub / github.com/codemix/graph / stringTokensToLines

Function stringTokensToLines

packages/graph/src/Steps.ts:211–297  ·  view source on GitHub ↗
(
  tokens: readonly StepStringToken[],
  colorizers: StepTokenColorizers = defaultTokenColorizers,
)

Source from the content-addressed store, hash-verified

209export type StepTokenColorizers = typeof defaultTokenColorizers;
210
211function stringTokensToLines(
212 tokens: readonly StepStringToken[],
213 colorizers: StepTokenColorizers = defaultTokenColorizers,
214): readonly string[] {
215 let pc = 0;
216 const lines: string[] = [];
217 let segments: string[] = [];
218 for (const token of tokens) {
219 switch (token.kind) {
220 case "start": {
221 pc++;
222 segments.push(colorizers.start(`${pc}. `));
223 break;
224 }
225 case "name": {
226 segments.push(colorizers.name(token.value));
227 break;
228 }
229 case "keyword": {
230 segments.push(colorizers.keyword(token.value), " ");
231 break;
232 }
233 case "config": {
234 segments.push(
235 colorizers.punctuation("("),
236 stringifyStepConfig(token.value, colorizers),
237 colorizers.punctuation(")"),
238 " ",
239 );
240 break;
241 }
242 case "condition": {
243 segments.push(
244 colorizers.punctuation("["),
245 stringifyCondition(token.value, colorizers),
246 colorizers.punctuation("]"),
247 " ",
248 );
249 break;
250 }
251 case "steps": {
252 segments.push(colorizers.punctuation("{"));
253 lines.push(segments.join(""));
254 for (const line of stringTokensToLines(token.value, colorizers)) {
255 lines.push(` ${line}`);
256 }
257 segments = [" ", colorizers.punctuation("}"), " "];
258 break;
259 }
260 case "label": {
261 segments.push(colorizers.label(token.value), " ");
262 break;
263 }
264 case "aliases": {
265 segments.push(
266 colorizers.keyword("as"),
267 " ",
268 token.value.map((alias) => colorizers.aliases(alias)).join(colorizers.punctuation(", ")),

Callers 1

stringTokensToStringFunction · 0.85

Calls 6

stringifyStepConfigFunction · 0.85
stringifyConditionFunction · 0.85
valueMethod · 0.80
pushMethod · 0.45
nameMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected