mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-11 17:17:42 +03:00
Markdown grammar improvements.
This commit is contained in:
@@ -42,6 +42,7 @@ struct EE_API SyntaxPattern {
|
||||
IsRootSelfInclude = 1 << 3,
|
||||
IsRangedMatch = 1 << 5,
|
||||
IsSourceInclude = 1 << 6,
|
||||
IsAutomaticallyAdded = 1 << 7,
|
||||
};
|
||||
|
||||
static SyntaxDefMap<SyntaxStyleType, std::string> SyntaxStyleTypeCache;
|
||||
@@ -108,6 +109,8 @@ struct EE_API SyntaxPattern {
|
||||
|
||||
inline bool isRangedMatch() const { return flags & Flags::IsRangedMatch; }
|
||||
|
||||
inline bool isAutomaticallyAdded() const { return flags & Flags::IsAutomaticallyAdded; }
|
||||
|
||||
inline bool isSimpleRangedMatch() const {
|
||||
return isRangedMatch() && !hasContentScope() && !hasSyntax();
|
||||
}
|
||||
|
||||
@@ -15,21 +15,52 @@ void addMarkdown() {
|
||||
{ "Markdown",
|
||||
{ "%.md$", "%.markdown$" },
|
||||
{
|
||||
{ { "\\." }, "normal" },
|
||||
{ { "```[%w \t%+%-#]+", "```" }, "function", dynSyntax },
|
||||
{ { "include", "#comments" }, "normal" },
|
||||
{ { "include", "#strings" }, "normal" },
|
||||
{ { "include", "#enumerations" }, "normal" },
|
||||
{ { "include", "#decorations" }, "normal" },
|
||||
{ { "include", "#headings" }, "normal" },
|
||||
{ { "include", "#links" }, "normal" },
|
||||
},
|
||||
{},
|
||||
"",
|
||||
{} } );
|
||||
|
||||
sd.addRepositories( {
|
||||
|
||||
{ "comments",
|
||||
{
|
||||
{ { "<!%-%-", "%-%->" }, "comment" },
|
||||
{ { "```", "```" }, "string" },
|
||||
{ { "``", "``" }, "string" },
|
||||
{ { "`", "`" }, "string" },
|
||||
{ { "~~", "~~", "\\" }, "type" },
|
||||
{ { "%-%-%-+" }, "comment" },
|
||||
{ { "%*%s+" }, "operator" },
|
||||
{ { "%*", "[%*\n]", "\\" }, "operator" },
|
||||
{ { "%s%_", "[%_\n]", "\\" }, "type" },
|
||||
{ { "^%_", "[%_\n]", "\\" }, "type" },
|
||||
{ { "^#.-\n" }, "keyword" },
|
||||
{ { "\n#.-\n" }, "keyword" },
|
||||
{ { "\n%_", "[%_\n]", "\\" }, "type" },
|
||||
} },
|
||||
|
||||
{ "strings",
|
||||
{
|
||||
{ { "```", "```" }, "string" },
|
||||
{ { "``", "(``|\n)" }, { "string" }, {}, "", SyntaxPatternMatchType::RegEx },
|
||||
{ { "`", "[`\n]" }, "string" },
|
||||
{ { "^%s*>+%s.*" }, "string" },
|
||||
} },
|
||||
|
||||
{ "enumerations",
|
||||
{
|
||||
{ { "^%s*%*%s" }, "number" },
|
||||
{ { "^%s*%-%s" }, "number" },
|
||||
{ { "^%s*%+%s" }, "number" },
|
||||
{ { "^%s*[0-9]+[%.%)]%s" }, "number" },
|
||||
{ { "%*%s+" }, "number" },
|
||||
} },
|
||||
|
||||
{ "headings",
|
||||
{
|
||||
{ { "^#.+\n" }, "keyword" },
|
||||
{ { "\n#.+\n" }, "keyword" },
|
||||
{ { "^=+\n" }, "keyword" },
|
||||
} },
|
||||
|
||||
{ "links",
|
||||
{
|
||||
{ { "%[!%[([^%]]-)%]%((https?://[%w_.~!*:@&+$/?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/"
|
||||
"?[%w_.~!*:@&+$/?%%#=-]*)%)%]%((https?://[%w_.~!*:@&+$/"
|
||||
"?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/?[%w_.~!*:@&+$/?%%#=-]*)%)" },
|
||||
@@ -43,16 +74,108 @@ void addMarkdown() {
|
||||
{ { "https?://[%w_.~!*:@&+$/?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/?[%w_.~!*:@&+$/"
|
||||
"?%%#=-]*" },
|
||||
"link" },
|
||||
} },
|
||||
|
||||
},
|
||||
{ "decorations_bold",
|
||||
{
|
||||
{ { "\\*\\*(?!\\*)", "(\\*\\*|\n)" },
|
||||
{ "type,bold", "type,bold", "type,bold" },
|
||||
{},
|
||||
"",
|
||||
SyntaxPatternMatchType::RegEx,
|
||||
{
|
||||
{ { "include", "$self" }, "type,bold" },
|
||||
} },
|
||||
{ { "__(?!_)", "(__|\n)" },
|
||||
{ "type,bold", "type,bold", "type,bold" },
|
||||
{},
|
||||
"",
|
||||
SyntaxPatternMatchType::RegEx,
|
||||
{
|
||||
{ { "include", "$self" }, "type,bold" },
|
||||
} },
|
||||
} },
|
||||
|
||||
},
|
||||
"",
|
||||
{}
|
||||
{ "decorations_italic",
|
||||
{
|
||||
{ { "%s%_%f[^_]", "[%_\n]" },
|
||||
{ "type,italic" },
|
||||
{},
|
||||
"",
|
||||
SyntaxPatternMatchType::LuaPattern,
|
||||
{
|
||||
{ { "include", "$self" },
|
||||
"type,italic",
|
||||
"",
|
||||
SyntaxPatternMatchType::LuaPattern },
|
||||
} },
|
||||
|
||||
} );
|
||||
{ { "^%_%f[^_]", "[%_\n]" },
|
||||
{ "type,italic" },
|
||||
{},
|
||||
"",
|
||||
SyntaxPatternMatchType::LuaPattern,
|
||||
{
|
||||
{ { "include", "$self" }, "type,italic" },
|
||||
} },
|
||||
|
||||
{ { "%s%*%f[^*]", "[%*\n]" },
|
||||
{ "type,italic" },
|
||||
{},
|
||||
"",
|
||||
SyntaxPatternMatchType::LuaPattern,
|
||||
{
|
||||
{ { "include", "$self" }, "type,italic" },
|
||||
} },
|
||||
|
||||
{ { "^%*%f[^*]", "[%*\n]" },
|
||||
{ "type,italic" },
|
||||
{},
|
||||
"",
|
||||
SyntaxPatternMatchType::LuaPattern,
|
||||
{
|
||||
{ { "include", "$self" }, "type,italic" },
|
||||
} },
|
||||
|
||||
{ { "\n%_%f[^_]", "[%_\n]" },
|
||||
{ "type,italic" },
|
||||
{},
|
||||
"",
|
||||
SyntaxPatternMatchType::LuaPattern,
|
||||
{
|
||||
{ { "include", "$self" }, "type,italic" },
|
||||
} },
|
||||
} },
|
||||
|
||||
{ "decorations_strikethrough",
|
||||
{
|
||||
{ { "~~~" }, "normal" },
|
||||
{ { "~~", "(~~|\n)" },
|
||||
{ "type,strikethrough" },
|
||||
{},
|
||||
"",
|
||||
SyntaxPatternMatchType::RegEx,
|
||||
{
|
||||
{ { "include", "$self" }, "type,strikethrough" },
|
||||
} },
|
||||
{ { "~", "(~|\n)" },
|
||||
{ "type,strikethrough" },
|
||||
{},
|
||||
"",
|
||||
SyntaxPatternMatchType::RegEx,
|
||||
{
|
||||
{ { "include", "$self" }, "type,strikethrough" },
|
||||
} },
|
||||
} },
|
||||
|
||||
{ "decorations",
|
||||
{
|
||||
{ { "include", "#decorations_bold" }, "normal" },
|
||||
{ { "include", "#decorations_italic" }, "normal" },
|
||||
{ { "include", "#decorations_strikethrough" }, "normal" },
|
||||
} },
|
||||
|
||||
} );
|
||||
sd.setFoldRangeType( FoldRangeType::Markdown );
|
||||
sd.setBlockComment( { "<!--", "-->" } );
|
||||
}
|
||||
|
||||
@@ -169,6 +169,7 @@ SyntaxDefinition::SyntaxDefinition(
|
||||
updatePatternsState( *this, mPatterns );
|
||||
mPatterns.emplace_back( SyntaxPattern{ { "%s+" }, "normal" } );
|
||||
mPatterns.emplace_back( SyntaxPattern{ { "%w+%f[%s]" }, "normal" } );
|
||||
mPatterns.back().flags |= SyntaxPattern::Flags::IsAutomaticallyAdded;
|
||||
}
|
||||
for ( const auto& symbol : mSymbolNames ) {
|
||||
mSymbolsHashes.insert(
|
||||
|
||||
@@ -716,6 +716,9 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Syntax
|
||||
innerPtrn->patterns[0][0] == '^' )
|
||||
continue;
|
||||
|
||||
if ( patternStack.size() > 1 && innerPtrn->isAutomaticallyAdded() )
|
||||
continue;
|
||||
|
||||
if ( std::find( triedPatterns.begin(), triedPatterns.end(), patternState ) !=
|
||||
triedPatterns.end() )
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user