mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-25 07:25:13 +00:00
revert way to build peg
This commit is contained in:
parent
7cf838abda
commit
6eb76f1e80
4 changed files with 10 additions and 71 deletions
|
@ -7,8 +7,8 @@
|
|||
"scripts": {
|
||||
"build": "npm run tsc && npm run peg && npm run webpack",
|
||||
"build-dev": "npm run tsc && npm run peg-dev && npm run webpack-dev",
|
||||
"peg": "node ./built/build",
|
||||
"peg-dev": "node ./built/build trace",
|
||||
"peg": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules root,plain src/parser/core-parser.pegjs",
|
||||
"peg-dev": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules root,plain --trace src/parser/core-parser.pegjs",
|
||||
"tsc": "tsc",
|
||||
"webpack": "webpack --mode=production",
|
||||
"webpack-dev": "webpack --mode=development",
|
||||
|
|
25
src/build.ts
25
src/build.ts
|
@ -1,25 +0,0 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import path from 'path';
|
||||
import { generateCode } from './misc/generate-peg';
|
||||
|
||||
async function entryPoint() {
|
||||
// get arguments
|
||||
let trace = false;
|
||||
if (process.argv.some(i => i == 'trace')) {
|
||||
trace = true;
|
||||
}
|
||||
|
||||
const srcPath = path.join(__dirname, '../src/parser/core-parser.pegjs');
|
||||
const destPath = path.join(__dirname, '../built/parser/core-parser.js');
|
||||
|
||||
// generate a code from PEG
|
||||
const generatedCode = await generateCode(srcPath, trace);
|
||||
|
||||
// write the generated code
|
||||
await fs.writeFile(destPath, generatedCode, { encoding: 'utf8' });
|
||||
}
|
||||
entryPoint()
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
});
|
|
@ -1,32 +0,0 @@
|
|||
import { promises as fs } from 'fs';
|
||||
import peg from 'pegjs';
|
||||
|
||||
export async function generateParser(srcPath: string, trace?: boolean): Promise<peg.Parser>
|
||||
{
|
||||
// read the parser source
|
||||
const source = await fs.readFile(srcPath, 'utf8');
|
||||
|
||||
// generate a parser code
|
||||
const generatedCode = peg.generate(source, {
|
||||
allowedStartRules: ['root', 'all', 'inline'],
|
||||
trace: trace
|
||||
});
|
||||
|
||||
return generatedCode;
|
||||
}
|
||||
|
||||
export async function generateCode(srcPath: string, trace?: boolean): Promise<string>
|
||||
{
|
||||
// read the parser source
|
||||
const source = await fs.readFile(srcPath, 'utf8');
|
||||
|
||||
// generate a parser code
|
||||
const generatedCode = peg.generate(source, {
|
||||
allowedStartRules: ['root', 'all', 'inline'],
|
||||
output: 'source',
|
||||
format: 'commonjs',
|
||||
trace: trace
|
||||
});
|
||||
|
||||
return generatedCode;
|
||||
}
|
|
@ -4,23 +4,17 @@
|
|||
mergeText
|
||||
} = require('./parser-utils');
|
||||
|
||||
function applyParser(input, rule) {
|
||||
function applyParser(input, startRule) {
|
||||
let parseFunc = peg$parse;
|
||||
return parseFunc(input, rule ? { startRule : rule } : { });
|
||||
return parseFunc(input, startRule ? { startRule } : { });
|
||||
}
|
||||
}
|
||||
|
||||
root
|
||||
= ts:all*
|
||||
{
|
||||
return mergeText(ts);
|
||||
}
|
||||
= ts:(block / inline)* { return mergeText(ts); }
|
||||
|
||||
all
|
||||
= block / inline
|
||||
|
||||
// plain
|
||||
// =
|
||||
plain
|
||||
= ts:(text /*/ emoji*/)* { return mergeText(ts); }
|
||||
|
||||
block
|
||||
= title
|
||||
|
@ -30,8 +24,10 @@ block
|
|||
|
||||
inline
|
||||
= big
|
||||
/ c:. { return createTree('text', { text: c }); }
|
||||
/ text
|
||||
|
||||
text
|
||||
= c:. { return createTree('text', { text: c }); }
|
||||
|
||||
// block: title
|
||||
|
||||
|
|
Loading…
Reference in a new issue