forked from mermaid-js/mermaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mermaid-js#4727 from Yokozuna59/add-info-langium-p…
…arser feat: add `@mermaid-js/parser` package and `info` langium parser
- Loading branch information
Showing
50 changed files
with
3,875 additions
and
2,826 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { generate } from 'langium-cli'; | ||
|
||
export async function generateLangium() { | ||
await generate({ file: `./packages/parser/langium-config.json` }); | ||
} |
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,9 @@ | ||
declare module 'langium-cli' { | ||
export interface GenerateOptions { | ||
file?: string; | ||
mode?: 'development' | 'production'; | ||
watch?: boolean; | ||
} | ||
|
||
export function generate(options: GenerateOptions): Promise<boolean>; | ||
} |
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 |
---|---|---|
|
@@ -6,3 +6,6 @@ cypress/plugins/index.js | |
coverage | ||
*.json | ||
node_modules | ||
|
||
# autogenereated by langium-cli | ||
generated/ |
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 |
---|---|---|
|
@@ -47,3 +47,6 @@ stats/ | |
demos/dev/** | ||
!/demos/dev/example.html | ||
!/demos/dev/reload.js | ||
|
||
# autogenereated by langium-cli | ||
generated/ |
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 |
---|---|---|
|
@@ -71,6 +71,7 @@ | |
"knut", | ||
"knutsveidqvist", | ||
"laganeckas", | ||
"langium", | ||
"linetype", | ||
"lintstagedrc", | ||
"logmsg", | ||
|
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
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 type { DiagramAST } from 'mermaid-parser'; | ||
|
||
import type { DiagramDB } from '../../diagram-api/types.js'; | ||
|
||
export function populateCommonDb(ast: DiagramAST, db: DiagramDB) { | ||
if (ast.accDescr) { | ||
db.setAccDescription?.(ast.accDescr); | ||
} | ||
if (ast.accTitle) { | ||
db.setAccTitle?.(ast.accTitle); | ||
} | ||
if (ast.title) { | ||
db.setDiagramTitle?.(ast.title); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,24 +1,31 @@ | ||
// @ts-ignore - jison doesn't export types | ||
import { parser } from './parser/info.jison'; | ||
import { db } from './infoDb.js'; | ||
|
||
describe('info diagram', () => { | ||
beforeEach(() => { | ||
parser.yy = db; | ||
parser.yy.clear(); | ||
}); | ||
import { parser } from './infoParser.js'; | ||
|
||
describe('info', () => { | ||
it('should handle an info definition', () => { | ||
const str = `info`; | ||
parser.parse(str); | ||
|
||
expect(db.getInfo()).toBeFalsy(); | ||
expect(() => { | ||
parser.parse(str); | ||
}).not.toThrow(); | ||
}); | ||
|
||
it('should handle an info definition with showInfo', () => { | ||
const str = `info showInfo`; | ||
parser.parse(str); | ||
expect(() => { | ||
parser.parse(str); | ||
}).not.toThrow(); | ||
}); | ||
|
||
it('should throw because of unsupported info grammar', () => { | ||
const str = `info unsupported`; | ||
expect(() => { | ||
parser.parse(str); | ||
}).toThrow('Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 characters.'); | ||
}); | ||
|
||
expect(db.getInfo()).toBeTruthy(); | ||
it('should throw because of unsupported info grammar', () => { | ||
const str = `info unsupported`; | ||
expect(() => { | ||
parser.parse(str); | ||
}).toThrow('Parsing failed: unexpected character: ->u<- at offset: 5, skipped 11 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 |
---|---|---|
@@ -1,23 +1,10 @@ | ||
import type { InfoFields, InfoDB } from './infoTypes.js'; | ||
import { version } from '../../../package.json'; | ||
|
||
export const DEFAULT_INFO_DB: InfoFields = { | ||
info: false, | ||
} as const; | ||
export const DEFAULT_INFO_DB: InfoFields = { version } as const; | ||
|
||
let info: boolean = DEFAULT_INFO_DB.info; | ||
|
||
export const setInfo = (toggle: boolean): void => { | ||
info = toggle; | ||
}; | ||
|
||
export const getInfo = (): boolean => info; | ||
|
||
const clear = (): void => { | ||
info = DEFAULT_INFO_DB.info; | ||
}; | ||
export const getVersion = (): string => DEFAULT_INFO_DB.version; | ||
|
||
export const db: InfoDB = { | ||
clear, | ||
setInfo, | ||
getInfo, | ||
getVersion, | ||
}; |
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,12 @@ | ||
import type { Info } from 'mermaid-parser'; | ||
import { parse } from 'mermaid-parser'; | ||
|
||
import { log } from '../../logger.js'; | ||
import type { ParserDefinition } from '../../diagram-api/types.js'; | ||
|
||
export const parser: ParserDefinition = { | ||
parse: (input: string): void => { | ||
const ast: Info = parse('info', input); | ||
log.debug(ast); | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import type { DiagramDB } from '../../diagram-api/types.js'; | ||
|
||
export interface InfoFields { | ||
info: boolean; | ||
version: string; | ||
} | ||
|
||
export interface InfoDB extends DiagramDB { | ||
clear: () => void; | ||
setInfo: (info: boolean) => void; | ||
getInfo: () => boolean; | ||
getVersion: () => string; | ||
} |
Oops, something went wrong.