-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make /textmate export more bundler-friendly
- Loading branch information
Showing
17 changed files
with
160 additions
and
145 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
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,57 @@ | ||
/****************************************************************************** | ||
* Copyright 2021 TypeFox GmbH | ||
* This program and the accompanying materials are made available under the | ||
* terms of the MIT License, which is available in the project root. | ||
******************************************************************************/ | ||
import { AstUtils, type Grammar, GrammarAST, GrammarUtils, stream } from 'langium'; | ||
import chalk from 'chalk'; | ||
|
||
//eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export function log(level: 'log' | 'warn' | 'error', options: { watch?: boolean }, message: string, ...args: any[]): void { | ||
if (options.watch) { | ||
console[level](getTime() + message, ...args); | ||
} else { | ||
console[level](message, ...args); | ||
} | ||
} | ||
|
||
let start = process.hrtime(); | ||
|
||
export function elapsedTime(): string { | ||
const elapsed = process.hrtime(start)[1] / 1000000; // divide by a million to get nano to milli | ||
start = process.hrtime(); // reset the timer | ||
return elapsed.toFixed(); | ||
} | ||
|
||
export function getTime(): string { | ||
const date = new Date(); | ||
return `[${chalk.gray(`${padZeroes(date.getHours())}:${padZeroes(date.getMinutes())}:${padZeroes(date.getSeconds())}`)}] `; | ||
} | ||
|
||
function padZeroes(i: number): string { | ||
return i.toString().padStart(2, '0'); | ||
} | ||
|
||
export function collectKeywords(grammar: Grammar): string[] { | ||
const keywords = new Set<string>(); | ||
const reachableRules = GrammarUtils.getAllReachableRules(grammar, false); | ||
|
||
for (const keyword of stream(reachableRules) | ||
.filter(GrammarAST.isParserRule) | ||
.flatMap(rule => AstUtils.streamAllContents(rule).filter(GrammarAST.isKeyword))) { | ||
keywords.add(keyword.value); | ||
} | ||
|
||
return Array.from(keywords).sort(); | ||
} | ||
|
||
export function collectTerminalRegexps(grammar: Grammar): Record<string, RegExp> { | ||
const result: Record<string, RegExp> = {}; | ||
const reachableRules = GrammarUtils.getAllReachableRules(grammar, false); | ||
for (const terminalRule of stream(reachableRules).filter(GrammarAST.isTerminalRule)) { | ||
const name = terminalRule.name; | ||
const regexp = GrammarUtils.terminalRegex(terminalRule); | ||
result[name] = regexp; | ||
} | ||
return result; | ||
} |
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,70 @@ | ||
/****************************************************************************** | ||
* Copyright 2021 TypeFox GmbH | ||
* This program and the accompanying materials are made available under the | ||
* terms of the MIT License, which is available in the project root. | ||
******************************************************************************/ | ||
import type { IParserConfig } from 'langium'; | ||
|
||
export interface Package { | ||
name: string | ||
version: string | ||
langium: LangiumConfig | ||
} | ||
|
||
export const RelativePath = Symbol('RelativePath'); | ||
|
||
export interface LangiumConfig { | ||
/** Relative path to the directory of the config */ | ||
[RelativePath]: string | ||
/** Name of the language project */ | ||
projectName: string | ||
/** Array of language configurations */ | ||
languages: LangiumLanguageConfig[] | ||
/** Main output directory for TypeScript code */ | ||
out?: string | ||
/** File extension for import statements of generated files */ | ||
importExtension?: string | ||
/** Mode used to generate optimized files for development or production environments */ | ||
mode?: 'development' | 'production'; | ||
/** Configure the chevrotain parser for all languages */ | ||
chevrotainParserConfig?: IParserConfig, | ||
/** The following option is meant to be used only by Langium itself */ | ||
langiumInternal?: boolean | ||
} | ||
|
||
export interface LangiumLanguageConfig { | ||
/** The identifier of your language as used in vscode */ | ||
id: string | ||
/** Path to the grammar file */ | ||
grammar: string | ||
/** File extensions with leading `.` */ | ||
fileExtensions?: string[] | ||
/** Enable case-insensitive keywords parsing */ | ||
caseInsensitive?: boolean | ||
/** Enable generating a TextMate syntax highlighting file */ | ||
textMate?: { | ||
/** Output path to syntax highlighting file */ | ||
out: string | ||
} | ||
/** Enable generating a Monarch syntax highlighting file */ | ||
monarch?: { | ||
/** Output path to syntax highlighting file */ | ||
out: string | ||
} | ||
/** Enable generating a Prism syntax highlighting file */ | ||
prism?: { | ||
/** Output path to syntax highlighting file */ | ||
out: string | ||
} | ||
/** Enable generating railroad syntax diagrams */ | ||
railroad?: { | ||
/** Output path for railroad diagrams */ | ||
out: string; | ||
/** Whether to print diagrams all into a single html file or in separate svg files */ | ||
mode?: 'html' | 'svg'; | ||
/** Path to a css file that will be included in the generated output files */ | ||
css?: string; | ||
} | ||
/** Configure the chevrotain parser for a single language */ | ||
chevrotainParserConfig?: IParserConfig | ||
} |
Oops, something went wrong.