Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sfm-js
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TransFem.org
sfm-js
Commits
b6d4350a
Commit
b6d4350a
authored
5 years ago
by
marihachi
Browse files
Options
Downloads
Patches
Plain Diff
update core parser
parent
68e322b8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/parser/core-parser.pegjs
+141
-74
141 additions, 74 deletions
src/parser/core-parser.pegjs
with
141 additions
and
74 deletions
src/parser/core-parser.pegjs
+
141
−
74
View file @
b6d4350a
start = root
{
function buildList(head, others) {
return [ head, ...others ];
}
function createTree(type, props, children) {
props = props || { };
children = children || [ ];
children = !Array.isArray(children) ? [children] : children;
return {
node: { type, props },
children: children
};
}
}
// general
root
= block
/ inline
space
// plain
= [ \t]
// =
lineBreak
= "\n" / "\r\n" / "\r"
spacing
= space / lineBreak
// titile
block
= title
/ quote
/ search
/ blockCode
title_nestContent
inline
=
inline
=
big
titleA_char
= !(title_nestContent / lineBreak / "】") c:. { return c; }
titleA_text
// block: title
= t:$(titleA_char+) { return t; }
title
A_content
title
=
(
title
_nestContent / titleA_text)+
= title
A / titleB
titleA
titleA
= "【" titleA_content "】"
= "【" content:titleA_content "】"
{
return createTree('title', { }, content);
}
title
B
_c
har
title
A
_c
ontent
=
!(title_nestContent / lineBreak / "]") c:. { return c; }
=
(inline / titleA_text)+
titleB_text
titleA_text
= t:$(titleB_char+) { return t; }
= s:$(titleA_char+)
{
return createTree('text', { text: s });
}
title
B
_c
ontent
title
A
_c
har
=
(title_nestContent / titleB_text)+
=
!(inline / "】") c:CHAR { return c; }
titleB
titleB
= "[" titleB_content "]"
= "[" content: titleB_content "]"
{
return createTree('title', { }, content);
}
title
title
B_content
=
titleA
/ titleB
=
(inline
/ titleB
_text)+
// blockCode
titleB_text
= s:$(titleB_char+)
{
return createTree('text', { text: s });
}
blockCode
_char
titleB
_char
= !(line
Break
/ "
```
") c:
.
{ return c; }
= !(
in
line / "
]
") c:
CHAR
{ return c; }
blockCode_line
= t:$(blockCode_char*) lineBreak { return t; }
// block: quote
// (handle the line as quote block if got a char ">" of the line head.)
quote
= head:quote_line tail:(NEWLINE tree:quote_line { return tree; })*
{
const trees = [head, ...tail];
console.log(trees.map(tree => tree.children));//.flat();
return [head, ...tail].join('\n');
}
quote_line
= ">" content:quote_content &ENDLINE { return createTree('quote', { }, content); }
// TODO: allow nesting
quote_content
= quote_text
quote_text
= s:$(CHAR+) { return createTree('text', { text: s }); }
// block: search
search
= q:search_query sp:[ \t] key:search_keyToken &ENDLINE
{
return createTree('search', {
query: q,
content: [ q, sp, key ].join('')
});
}
search_query =
head:CHAR tail:(!([ \t] search_keyToken ENDLINE) c:CHAR { return c; })*
{
return head + tail.join('');
}
search_keyToken
= "検索" / "search"i
// block: blockCode
blockCode
blockCode
= "```"
lineBreak blockCode_line* "```"
= "```"
NEWLINE lines: (!("```" ENDLINE) line:blockCode_line NEWLINE { return line; } )* "```" &ENDLINE { return lines; }
// parts
// TODO: allow nesting
blockCode_line
= t:$(CHAR*) { return t; }
// plain
// = emoji
// / text
// block
// = title
// / quote
// / search
// / blockCode
// / mathBlock
// / center
// inline
// = big
// / bold
// / small
// / italic
// / strike
// / motion
// / spin
// / jump
// / flip
// / inlineCode
// / mathInline
// / mention
// / hashtag
// / url
// / link
// / plain
// root
// = block
// / inline
block
// inline: big
= title
/ blockCode
inline = "inline"
big
= "***" content:big_content "***"
{
return createTree('big', { }, content);
}
root
big_content
= block
= (big_text / inline)*
/ inline
big_text
= s:$(big_char+) { return createTree('text', { text: s }); }
big_char
= !("***") c:CHAR { return c; }
// Core rules
CHAR
= !NEWLINE c:. { return c; }
ENDLINE
= NEWLINE / EOF
NEWLINE
= "\r\n" / [\r\n]
EOF
= !.
// __ "whitespaces"
// = _+
// _ "whitespace"
// = [ \t]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment