update parser

This commit is contained in:
marihachi 2020-02-23 03:40:57 +09:00
parent d4e8a42128
commit 83ae6cc667
2 changed files with 22 additions and 9 deletions

View file

@ -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": "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",
"peg": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules rootParser,inlineParser,plainParser src/parser/core-parser.pegjs",
"peg-dev": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules rootParser,inlineParser,plainParser --trace src/parser/core-parser.pegjs",
"tsc": "tsc",
"webpack": "webpack --mode=production",
"webpack-dev": "webpack --mode=development",

View file

@ -10,12 +10,15 @@
}
}
root
rootParser
= ts:(block / inline)* { return mergeText(ts); }
plain
plainParser
= ts:(text /*/ emoji*/)* { return mergeText(ts); }
inlineParser
= ts:(inline)* { return mergeText(ts); }
block
= title
/ quote
@ -24,11 +27,13 @@ block
inline
= big
/ bold
/ text
text
= c:. { return createTree('text', { text: c }); }
// block: title
title
@ -52,7 +57,7 @@ titleB
quote
= lines:quote_line+
{
const children = applyParser(lines.join('\n'), 'root');
const children = applyParser(lines.join('\n'), 'rootParser');
return createTree('quote', { }, children);
}
@ -84,10 +89,17 @@ search_keyToken
// block: blockCode
blockCode
= BEGINLINE "```" NEWLINE lines: (!("```" ENDLINE) line:blockCode_line NEWLINE { return line; } )* "```" ENDLINE { return lines; }
= BEGINLINE "```" lang:CHAR* NEWLINE lines:blockCode_line* "```" ENDLINE
{
lang = lang.join('');
return createTree('blockCode', {
code: lines.join('\n'),
lang: lang.length > 0 ? lang : null,
});
}
blockCode_line
= (!"```" (block / inline))+
= !("```" ENDLINE) line:$(CHAR+) NEWLINE { return line; }
// inline: big
@ -110,9 +122,10 @@ bold_A
}
bold_B
= "__" content:(!"__" i:inline { return i; })+ "__"
= "__" content:(!"__" i:[a-zA-Z0-9 \t] { return i; })+ "__"
{
return createTree('bold', { }, mergeText(content));
const parsedContent = applyParser(content.join(''), 'inlineParser');
return createTree('bold', { }, parsedContent);
}