Skip to content

Commit

Permalink
Prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
nirname committed Sep 11, 2023
1 parent 2e99c99 commit f6e9444
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
42 changes: 23 additions & 19 deletions packages/mermaid/src/diagrams/railroad/railroadDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as configApi from '../../config.js';
import type { DiagramDB } from '../../diagram-api/types.js';

import { clear as commonClear } from '../../commonDb.js';
import { clear as commonClear } from '../common/commonDb.js';

const clear = (): void => {
commonClear();
Expand Down Expand Up @@ -160,30 +160,32 @@ const addZeroOrMany = (chunk: Chunk): Chunk => {
return new ZeroOrMany(chunk);
};
const addRuleOrChoice = (ID: string, chunk: Chunk) => {
if(rules[ID]) {
if (rules[ID]) {
const value = rules[ID];
const alternative = addChoice([value, chunk]);
rules[ID] = alternative;
} else {
rules[ID] = chunk;
}
}
};

const addSequence = (chunks: Chunk[]): Chunk => {
if (!Array.isArray(chunks)) {
console.error('Sequence`s chunks are not array', chunks);
}

if(configApi.getConfig().railroad?.compressed) {
chunks = chunks.map((chunk) => {
if(chunk instanceof Sequence) {
return chunk.chunks;
}
return chunk;
}).flat();
if (configApi.getConfig().railroad?.compressed) {
chunks = chunks
.map((chunk) => {
if (chunk instanceof Sequence) {
return chunk.chunks;
}
return chunk;
})
.flat();
}

if(chunks.length === 1) {
if (chunks.length === 1) {
return chunks[0];
} else {
return new Sequence(chunks);
Expand All @@ -195,16 +197,18 @@ const addChoice = (chunks: Chunk[]): Chunk => {
console.error('Alternative chunks are not array', chunks);
}

if(configApi.getConfig().railroad?.compressed) {
chunks = chunks.map((chunk) => {
if(chunk instanceof Choice) {
return chunk.chunks;
}
return chunk;
}).flat();
if (configApi.getConfig().railroad?.compressed) {
chunks = chunks
.map((chunk) => {
if (chunk instanceof Choice) {
return chunk.chunks;
}
return chunk;
})
.flat();
}

if(chunks.length === 1) {
if (chunks.length === 1) {
return chunks[0];
} else {
return new Choice(chunks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ prim
| '[' choice ']' { $$=yy.addZeroOrOne($choice); }
| '{' choice '}' { $$=yy.addZeroOrMany($choice); }
| '"' (QSTRING)?\[qstring_] '"' {
$$=yy.addTerm($qstring_, '"');
$$=yy.addTerm($qstring_, '"'); // TODO: add bunch of terminals instead of one?
}
| APOSTROPHE (STRING)?\[string_] APOSTROPHE {
$$=yy.addTerm($string_, "'");
Expand Down
1 change: 0 additions & 1 deletion packages/mermaid/src/schemas/config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,6 @@ $defs: # JSON Schema definition (maybe we should move these to a seperate file)
type: boolean
default: true


FontCalculator:
title: Font Calculator
description: |
Expand Down

0 comments on commit f6e9444

Please sign in to comment.