Skip to content
Snippets Groups Projects
Commit 83ae6cc6 authored by marihachi's avatar marihachi
Browse files

update parser

parent d4e8a421
No related branches found
No related tags found
No related merge requests found
......@@ -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",
......
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment