diff --git a/src/internal/parser.pegjs b/src/internal/parser.pegjs
index 7cb949e..7abc8de 100644
--- a/src/internal/parser.pegjs
+++ b/src/internal/parser.pegjs
@@ -63,13 +63,13 @@
//
fullParser
- = nodes:(&. n:full { return n; })* { return mergeText(nodes); }
+ = nodes:(&. @full)* { return mergeText(nodes); }
plainParser
- = nodes:(&. n:plain { return n; })* { return mergeText(nodes); }
+ = nodes:(&. @plain)* { return mergeText(nodes); }
inlineParser
- = nodes:(&. n:inline { return n; })* { return mergeText(nodes); }
+ = nodes:(&. @inline)* { return mergeText(nodes); }
//
// syntax list
@@ -131,7 +131,7 @@ quote
= &(BEGIN ">") q:quoteInner LF? { return q; }
quoteInner
- = head:quoteMultiLine tails:quoteMultiLine+
+ = head:(quoteLine / quoteEmptyLine) tails:(quoteLine / quoteEmptyLine)+
{
const children = applyParser([head, ...tails].join('\n'), 'fullParser');
return QUOTE(children);
@@ -142,11 +142,8 @@ quoteInner
return QUOTE(children);
}
-quoteMultiLine
- = quoteLine / quoteEmptyLine
-
quoteLine
- = BEGIN ">" _? text:$(CHAR+) END { return text; }
+ = BEGIN ">" _? text:$CHAR+ END { return text; }
quoteEmptyLine
= BEGIN ">" _? END { return ''; }
@@ -198,7 +195,7 @@ mathBlockLine
// block: center
center
- = BEGIN "
" LF? content:(!(LF? "" END) i:inline { return i; })+ LF? "" END
+ = BEGIN "" LF? content:(!(LF? "" END) @inline)+ LF? "" END
{
return CENTER(mergeText(content));
}
@@ -210,14 +207,11 @@ center
// inline: emoji code
emojiCode
- = ":" name:emojiCodeName ":"
+ = ":" name:$[a-z0-9_+-]i+ ":"
{
return EMOJI_CODE(name);
}
-emojiCodeName
- = [a-z0-9_+-]i+ { return text(); }
-
// inline: unicode emoji
// NOTE: if the text matches one of the emojis, it will count the length of the emoji sequence and consume it.
@@ -230,7 +224,7 @@ unicodeEmoji
// inline: big
big
- = "***" content:(!"***" i:inline { return i; })+ "***"
+ = "***" content:(!"***" @inline)+ "***"
{
return FN('tada', { }, mergeText(content));
}
@@ -238,15 +232,15 @@ big
// inline: bold
bold
- = "**" content:(!"**" i:inline { return i; })+ "**"
+ = "**" content:(!"**" @inline)+ "**"
{
return BOLD(mergeText(content));
}
- / "" content:(!"" i:inline { return i; })+ ""
+ / "" content:(!"" @inline)+ ""
{
return BOLD(mergeText(content));
}
- / "__" content:$(!"__" c:([a-z0-9]i / _) { return c; })+ "__"
+ / "__" content:$(!"__" @([a-z0-9]i / _))+ "__"
{
const parsedContent = applyParser(content, 'inlineParser');
return BOLD(parsedContent);
@@ -255,7 +249,7 @@ bold
// inline: small
small
- = "" content:(!"" i:inline { return i; })+ ""
+ = "" content:(!"" @inline)+ ""
{
return SMALL(mergeText(content));
}
@@ -267,7 +261,7 @@ italic
/ italicAlt
italicTag
- = "" content:(!"" i:inline { return i; })+ ""
+ = "" content:(!"" @inline)+ ""
{
return ITALIC(mergeText(content));
}
@@ -287,11 +281,11 @@ italicAlt
// inline: strike
strike
- = "~~" content:(!("~" / LF) i:inline { return i; })+ "~~"
+ = "~~" content:(!("~" / LF) @inline)+ "~~"
{
return STRIKE(mergeText(content));
}
- / "" content:(!("" / LF) i:inline { return i; })+ ""
+ / "" content:(!("" / LF) @inline)+ ""
{
return STRIKE(mergeText(content));
}
@@ -299,7 +293,7 @@ strike
// inline: inlineCode
inlineCode
- = "`" content:$(![`´] c:CHAR { return c; })+ "`"
+ = "`" content:$(![`´] CHAR)+ "`"
{
return INLINE_CODE(content);
}
@@ -307,7 +301,7 @@ inlineCode
// inline: mathInline
mathInline
- = "\\(" content:$(!"\\)" c:CHAR { return c; })+ "\\)"
+ = "\\(" content:$(!"\\)" CHAR)+ "\\)"
{
return MATH_INLINE(content);
}
@@ -315,7 +309,7 @@ mathInline
// inline: mention
mention
- = "@" name:mentionName host:("@" host:mentionHost { return host; })?
+ = "@" name:mentionName host:("@" @mentionHost)?
{
return MENTION(name, host, text());
}
@@ -355,7 +349,8 @@ invalidHashtagContent
= [0-9]+
hashtagContentPart
- = hashtagBracketPair / hashtagChar
+ = hashtagBracketPair
+ / hashtagChar
hashtagBracketPair
= "(" hashtagContent* ")"
@@ -407,16 +402,13 @@ link
}
linkLabel
- = parts:linkLabelPart+
-{
- return parts;
-}
+ = linkLabelPart+
linkLabelPart
= url { return text(); /* text node */ }
/ link { return text(); /* text node */ }
/ mention { return text(); /* text node */ }
- / !"]" n:inline { return n; }
+ / !"]" @inline
linkUrl
= url { return text(); }
@@ -438,7 +430,7 @@ fnVer2
}
fnArgs
- = "." head:fnArg tails:("," arg:fnArg { return arg; })*
+ = "." head:fnArg tails:("," @fnArg)*
{
const args = { };
for (const pair of [head, ...tails]) {
@@ -458,7 +450,7 @@ fnArg
}
fnContentPart
- = !("]") i:inline { return i; }
+ = !("]") @inline
// inline: text