🚧 Optimized HTTP language parser
This commit is contained in:
@@ -26,20 +26,20 @@ try {
|
||||
|
||||
// 运行 lezer-generator
|
||||
console.log('⚙️ building parser...');
|
||||
execSync('npx lezer-generator codeblock.grammar -o parser.js', {
|
||||
execSync('npx lezer-generator codeblock.grammar -o parser.ts --typeScript', {
|
||||
cwd: __dirname,
|
||||
stdio: 'inherit'
|
||||
});
|
||||
|
||||
// 检查生成的文件
|
||||
const parserFile = path.join(__dirname, 'parser.js');
|
||||
const termsFile = path.join(__dirname, 'parser.terms.js');
|
||||
const parserFile = path.join(__dirname, 'parser.ts');
|
||||
const termsFile = path.join(__dirname, 'parser.terms.ts');
|
||||
|
||||
if (fs.existsSync(parserFile) && fs.existsSync(termsFile)) {
|
||||
console.log('✅ parser file successfully generated!');
|
||||
console.log('📦 parser files:');
|
||||
console.log(' - parser.js');
|
||||
console.log(' - parser.terms.js');
|
||||
console.log(' - parser.ts');
|
||||
console.log(' - parser.terms.ts');
|
||||
} else {
|
||||
throw new Error('failed to generate parser');
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 提供多语言代码块支持
|
||||
*/
|
||||
|
||||
import { parser } from "./parser.js";
|
||||
import { parser } from "./parser";
|
||||
import { configureNesting } from "./nested-parser";
|
||||
|
||||
import {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { ExternalTokenizer } from "@lezer/lr";
|
||||
import { BlockContent } from "./parser.terms.js";
|
||||
import { BlockContent } from "./parser.terms";
|
||||
import { LANGUAGES } from "./languages";
|
||||
|
||||
const EOF = -1;
|
||||
|
||||
@@ -24,7 +24,7 @@ export {
|
||||
} from './nested-parser';
|
||||
|
||||
// 解析器术语
|
||||
export * from './parser.terms.js';
|
||||
export * from './parser.terms';
|
||||
|
||||
// 外部标记器
|
||||
export {
|
||||
@@ -34,4 +34,4 @@ export {
|
||||
// 解析器
|
||||
export {
|
||||
parser
|
||||
} from './parser.js';
|
||||
} from './parser';
|
||||
@@ -86,7 +86,7 @@ export class LanguageInfo {
|
||||
* 支持的语言列表
|
||||
*/
|
||||
export const LANGUAGES: LanguageInfo[] = [
|
||||
new LanguageInfo("text", "Plain Text", null),
|
||||
new LanguageInfo("text", "Text", null),
|
||||
new LanguageInfo("json", "JSON", jsonLanguage.parser, ["json"], {
|
||||
parser: "json",
|
||||
plugins: [babelPrettierPlugin, prettierPluginEstree]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { parseMixed } from "@lezer/common";
|
||||
import { BlockContent, BlockLanguage } from "./parser.terms.js";
|
||||
import { BlockContent, BlockLanguage } from "./parser.terms";
|
||||
import { languageMapping } from "./languages";
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user