Fix Gemini 2.5 Exp model name.

Added the syntax definition folding ranges configuration for the JSON definitions.
Cleaned up a little bit some languages, added folding ranges to several of them.
This commit is contained in:
Martín Lucas Golini
2025-04-06 15:43:55 -03:00
parent 62d3a41527
commit fbe748f757
17 changed files with 207 additions and 84 deletions

View File

@@ -127,7 +127,7 @@
"cheapest": true
},
{
"name": "gemini-2.0-pro-exp",
"name": "gemini-2.5-pro-preview-03-25",
"display_name": "Gemini 2.5 Pro Experimental",
"max_tokens": 1000000
}

View File

@@ -357,6 +357,10 @@ class EE_API String {
static int valueIndex( const std::string& val, const std::string& strings, int defValue = -1,
char delim = ';' );
static bool iequals( std::string_view str1, std::string_view str2 );
static bool iequals( String::View str1, String::View str2 );
/** Creates a random string using the dictionary characters. */
static std::string randString(
size_t len,

View File

@@ -18,7 +18,9 @@ class EE_API ParserMatcherManager {
SINGLETON_DECLARE_HEADERS( ParserMatcherManager );
public:
void registerBaseParsers();
void registerBaseParsers();
bool registeredBaseParsers() const;
void registerParser( std::string_view parserName, ParserMatcherFn fn );
@@ -29,6 +31,7 @@ class EE_API ParserMatcherManager {
protected:
UnorderedMap<std::size_t, ParserMatcherFn> mFns;
bool mRegisteredBaseParsers{ false };
};
class EE_API ParserMatcher : public PatternMatcher {

View File

@@ -1,10 +1,45 @@
#ifndef EE_UI_DOC_FOLDRANGETYPE_HPP
#define EE_UI_DOC_FOLDRANGETYPE_HPP
#include <eepp/core/string.hpp>
#include <string>
namespace EE { namespace UI { namespace Doc {
enum class FoldRangeType { Braces, Indentation, Tag, Markdown, Undefined };
struct FoldRangeTypeUtil {
static FoldRangeType fromString( const std::string& str ) {
if ( String::iequals( str, "braces" ) ) {
return FoldRangeType::Braces;
} else if ( String::iequals( str, "indentation" ) ) {
return FoldRangeType::Indentation;
} else if ( String::iequals( str, "tag" ) ) {
return FoldRangeType::Tag;
} else if ( String::iequals( str, "markdown" ) ) {
return FoldRangeType::Markdown;
}
return FoldRangeType::Undefined;
}
static std::string toString( FoldRangeType type ) {
switch ( type ) {
case FoldRangeType::Braces:
return "braces";
case FoldRangeType::Indentation:
return "indentation";
case FoldRangeType::Tag:
return "tag";
case FoldRangeType::Markdown:
return "markdown";
case FoldRangeType::Undefined:
default:
break;
}
return "";
}
};
}}} // namespace EE::UI::Doc
#endif // EE_UI_DOC_FOLDRANGETYPE_HPP

View File

@@ -2216,4 +2216,19 @@ size_t String::countLines( String::View text ) {
return count;
}
bool String::iequals( std::string_view str1, std::string_view str2 ) {
return str1.length() == str2.length() &&
std::equal( str1.begin(), str1.end(), str2.begin(), []( char c1, char c2 ) {
return std::tolower( c1 ) == std::tolower( c2 );
} );
}
bool String::iequals( String::View str1, String::View str2 ) {
return str1.length() == str2.length() &&
std::equal( str1.begin(), str1.end(), str2.begin(),
[]( String::StringBaseType c1, String::StringBaseType c2 ) {
return std::tolower( c1 ) == std::tolower( c2 );
} );
}
} // namespace EE

View File

@@ -873,6 +873,12 @@ void ParserMatcherManager::registerBaseParsers() {
return isNumberLiteralBase( stringSearch, stringStartOffset, matchList,
stringLength, true, true, true, true );
} );
mRegisteredBaseParsers = true;
}
bool ParserMatcherManager::registeredBaseParsers() const {
return mRegisteredBaseParsers;
}
void ParserMatcherManager::registerParser( std::string_view parserName, ParserMatcherFn fn ) {

View File

@@ -1,11 +1,9 @@
#include <eepp/system/parsermatcher.hpp>
#include <eepp/ui/doc/languages/c.hpp>
#include <eepp/ui/doc/syntaxdefinitionmanager.hpp>
namespace EE { namespace UI { namespace Doc { namespace Language {
void addC() {
ParserMatcherManager::instance()->registerBaseParsers();
auto& sd = SyntaxDefinitionManager::instance()->add(

View File

@@ -1,11 +1,9 @@
#include <eepp/system/parsermatcher.hpp>
#include <eepp/ui/doc/languages/cpp.hpp>
#include <eepp/ui/doc/syntaxdefinitionmanager.hpp>
namespace EE { namespace UI { namespace Doc { namespace Language {
void addCPP() {
ParserMatcherManager::instance()->registerBaseParsers();
auto& sd = SyntaxDefinitionManager::instance()->add(

View File

@@ -1,4 +1,3 @@
#include <eepp/system/parsermatcher.hpp>
#include <eepp/ui/doc/languages/javascript.hpp>
#include <eepp/ui/doc/syntaxdefinitionmanager.hpp>

View File

@@ -1,5 +1,6 @@
#include <eepp/core/memorymanager.hpp>
#include <eepp/core/string.hpp>
#include <eepp/system/parsermatcher.hpp>
#include <eepp/ui/doc/syntaxdefinition.hpp>
using namespace std::literals;
@@ -40,6 +41,12 @@ SyntaxDefinition::SyntaxDefinition( const std::string& languageName,
mLSPName( lspName.empty() ? String::toLower( mLanguageName ) : lspName ) {
mSymbols.reserve( mSymbolNames.size() );
if ( !mPatterns.empty() ) {
if ( !ParserMatcherManager::instance()->registeredBaseParsers() &&
std::any_of( mPatterns.begin(), mPatterns.end(), []( const SyntaxPattern& pattern ) {
return pattern.matchType == SyntaxPatternMatchType::Parser;
} ) )
ParserMatcherManager::instance()->registerBaseParsers();
if ( std::find_if( mPatterns.begin(), mPatterns.end(), []( const SyntaxPattern& pattern ) {
return !pattern.patterns.empty() &&
( ( ( pattern.matchType == SyntaxPatternMatchType::LuaPattern &&

View File

@@ -122,6 +122,20 @@ static json toJson( const SyntaxDefinition& def ) {
if ( !def.isVisible() )
j["visible"] = false;
if ( def.getFoldRangeType() != FoldRangeType::Undefined )
j["fold_range_type"] = FoldRangeTypeUtil::toString( def.getFoldRangeType() );
if ( !def.getFoldBraces().empty() ) {
j["fold_braces"] = json::array();
for ( const auto& fb : def.getFoldBraces() ) {
json braces;
braces["start"] = fb.first;
braces["end"] = fb.second;
j["fold_braces"].push_back( braces );
}
}
return j;
}
@@ -224,8 +238,7 @@ namespace EE { namespace UI { namespace Doc { namespace Language {
buf += ", \"\", SyntaxPatternMatchType::RegEx";
else if ( pattern.matchType == SyntaxPatternMatchType::Parser )
buf += ", \"\", SyntaxPatternMatchType::Parser";
}
else if ( pattern.matchType != SyntaxPatternMatchType::LuaPattern ){
} else if ( pattern.matchType != SyntaxPatternMatchType::LuaPattern ) {
if ( pattern.matchType == SyntaxPatternMatchType::RegEx )
buf += ", SyntaxPatternMatchType::RegEx";
else if ( pattern.matchType == SyntaxPatternMatchType::Parser )
@@ -251,9 +264,26 @@ namespace EE { namespace UI { namespace Doc { namespace Language {
buf += "\n}";
buf += ")";
if ( !def.isVisible() )
buf += ".setVisible( false )";
buf += ".setVisible( false )\n";
if ( def.getAutoCloseXMLTags() )
buf += ".setAutoCloseXMLTags( true )";
buf += ".setAutoCloseXMLTags( true )\n";
if ( def.getFoldRangeType() != FoldRangeType::Undefined ) {
buf += String::format( ".setFoldRangeType( \"%s\" )\n",
FoldRangeTypeUtil::toString( def.getFoldRangeType() ) );
}
if ( !def.getFoldBraces().empty() ) {
buf += ".setFoldBraces( { ";
for ( const auto& brace : def.getFoldBraces() ) {
buf += String::format(
"{ '%s', '%s' }",
String( static_cast<String::StringBaseType>( brace.first ) ).toUtf8(),
String( static_cast<String::StringBaseType>( brace.second ) ).toUtf8() );
}
buf += " } );";
}
buf += ";\n}\n";
buf += "\n}}}} // namespace EE::UI::Doc::Language\n";
return std::make_pair( std::move( header ), std::move( buf ) );
@@ -468,6 +498,27 @@ static SyntaxDefinition loadLanguage( const nlohmann::json& json ) {
def.setExtensionPriority( json["extension_priority"].get<bool>() );
if ( json.contains( "case_insensitive" ) && json["case_insensitive"].is_boolean() )
def.setCaseInsensitive( json["case_insensitive"].get<bool>() );
if ( json.contains( "fold_range_type" ) && json["fold_range_type"].is_string() ) {
def.setFoldRangeType(
FoldRangeTypeUtil::fromString( json["fold_range_type"].get<std::string>() ) );
}
if ( json.contains( "fold_braces" ) && json["fold_braces"].is_array() ) {
const auto& foldBraces = json["fold_braces"];
std::vector<std::pair<Int64, Int64>> folds;
for ( const auto& fold : foldBraces ) {
if ( fold.is_object() && fold.contains( "start" ) && fold.contains( "end" ) ) {
auto start = String::fromUtf8( fold.value( "start", "" ) );
auto end = String::fromUtf8( fold.value( "end", "" ) );
if ( !start.empty() && !end.empty() )
folds.emplace_back( start[0], end[0] );
}
}
def.setFoldBraces( folds );
}
} catch ( const json::exception& e ) {
Log::error( "SyntaxDefinition loadLanguage failed:\n%s", e.what() );
}

View File

@@ -5,7 +5,7 @@ namespace EE { namespace UI { namespace Doc { namespace Language {
void addBlade() {
SyntaxDefinitionManager::instance()->add(
auto& sd = SyntaxDefinitionManager::instance()->add(
{ "Blade",
{ "%.b$" },
@@ -42,6 +42,8 @@ void addBlade() {
{}
} );
sd.setFoldRangeType( FoldRangeType::Braces ).setFoldBraces( { { '{', '}' } } );
}
}}}} // namespace EE::UI::Doc::Language

View File

@@ -5,7 +5,7 @@ namespace EE { namespace UI { namespace Doc { namespace Language {
void addC3() {
SyntaxDefinitionManager::instance()->add(
auto& sd = SyntaxDefinitionManager::instance()->add(
{ "C3",
{ "%.c3$" },
@@ -213,6 +213,8 @@ void addC3() {
{}
} );
sd.setFoldRangeType( FoldRangeType::Braces ).setFoldBraces( { { '{', '}' } } );
}
}}}} // namespace EE::UI::Doc::Language

View File

@@ -5,7 +5,7 @@ namespace EE { namespace UI { namespace Doc { namespace Language {
void addCovScript() {
SyntaxDefinitionManager::instance()->add(
auto& sd = SyntaxDefinitionManager::instance()->add(
{ "CovScript",
{ "%.csc$", "%.csp$", "%.ecs$" },
@@ -47,6 +47,8 @@ void addCovScript() {
{ "^#!.*[ /]covscript", "^#!.*[ /]cs" }
} );
sd.setFoldRangeType( FoldRangeType::Indentation );
}
}}}} // namespace EE::UI::Doc::Language

View File

@@ -5,7 +5,7 @@ namespace EE { namespace UI { namespace Doc { namespace Language {
void addFlow9() {
SyntaxDefinitionManager::instance()->add(
auto& sd = SyntaxDefinitionManager::instance()->add(
{ "Flow9",
{ "%.flow$" },
@@ -35,6 +35,8 @@ void addFlow9() {
{}
} );
sd.setFoldRangeType( FoldRangeType::Braces ).setFoldBraces( { { '{', '}' } } );
}
}}}} // namespace EE::UI::Doc::Language

View File

@@ -1,11 +1,9 @@
#include <eepp/system/parsermatcher.hpp>
#include <eepp/ui/doc/languages/u.hpp>
#include <eepp/ui/doc/syntaxdefinitionmanager.hpp>
namespace EE { namespace UI { namespace Doc { namespace Language {
void addU() {
ParserMatcherManager::instance()->registerBaseParsers();
auto& sd = SyntaxDefinitionManager::instance()->add(

View File

@@ -5,79 +5,80 @@ namespace EE { namespace UI { namespace Doc { namespace Language {
void addV1() {
auto& sd =
SyntaxDefinitionManager::instance()
->add(
{ "V1",
{ "%.v1$" },
{
{ { "<%s*[sS][cC][rR][iI][pP][tT]%s+[tT][yY][pP][eE]%s*=%s*['\"]%a+/"
"[jJ][aA][vV][aA][sS][cC][rR][iI][pP][tT]['\"]%s*>",
"<%s*/[sS][cC][rR][iI][pP][tT]>" },
"function",
"JavaScript" },
{ { "<%s*[sS][cC][rR][iI][pP][tT]%s*>", "<%s*/%s*[sS][cC][rR][iI][pP][tT]>" },
"function",
"JavaScript" },
{ { "<%s*[sS][tT][yY][lL][eE][^>]*>", "<%s*/%s*[sS][tT][yY][lL][eE]%s*>" },
"function",
"CSS" },
{ { "<%?v?1?", "%?>" }, "function", "V1Core" },
{ { "<!%-%-", "%-%->" }, "comment" },
{ { "%f[^>][^<]", "%f[<]" }, "normal" },
{ { "\"", "\"", "\\" }, "string" },
{ { "'", "'", "\\" }, "string" },
{ { "0x[%da-fA-F]+" }, "number" },
{ { "-?%d+[%d%.]*f?" }, "number" },
{ { "-?%.?%d+f?" }, "number" },
{ { "%f[^<]![%a_][%w%_%-]*" }, "keyword2" },
{ { "%f[^<][%a_][%w%_%-]*" }, "function" },
{ { "%f[^<]/[%a_][%w%_%-]*" }, "function" },
{ { "[%a_][%w_]*" }, "keyword" },
{ { "[/<>=]" }, "operator" },
},
{},
"",
{ "^#!.*[ /]v1" } } )
.setAutoCloseXMLTags( true );
SyntaxDefinitionManager::instance()
->add( { "V1Core",
{},
->add( { "V1",
{ "%.v1$" },
{
{ { "<%?v?1?" }, "function" },
{ { "%?>", "<%?v?1?" }, "function", "HTML" },
{ { "//.-\n" }, "comment" },
{ { "/%*", "%*/" }, "comment" },
{ { "#.-\n" }, "comment" },
{ { "<%s*[sS][cC][rR][iI][pP][tT]%s+[tT][yY][pP][eE]%s*=%s*['\"]%a+/"
"[jJ][aA][vV][aA][sS][cC][rR][iI][pP][tT]['\"]%s*>",
"<%s*/[sS][cC][rR][iI][pP][tT]>" },
"function",
"JavaScript" },
{ { "<%s*[sS][cC][rR][iI][pP][tT]%s*>", "<%s*/%s*[sS][cC][rR][iI][pP][tT]>" },
"function",
"JavaScript" },
{ { "<%s*[sS][tT][yY][lL][eE][^>]*>", "<%s*/%s*[sS][tT][yY][lL][eE]%s*>" },
"function",
"CSS" },
{ { "<%?v?1?", "%?>" }, "function", "V1Core" },
{ { "<!%-%-", "%-%->" }, "comment" },
{ { "%f[^>][^<]", "%f[<]" }, "normal" },
{ { "\"", "\"", "\\" }, "string" },
{ { "'", "'", "\\" }, "string" },
{ { "%\\x[%da-fA-F]+" }, "number" },
{ { "-?%d+[%d%.eE]*" }, "number" },
{ { "-?%.?%d+" }, "number" },
{ { "[%.%+%-=/%*%^%%<>!~|&]" }, "operator" },
{ { "(if|for|while|foreach|switch)\\s*(?=\\()" },
{ "normal", "keyword", "keyword" },
"",
SyntaxPatternMatchType::RegEx },
{ { "[%a_][%w_]*%s*%f[(]" }, "function" },
{ { "[%a_][%w_]*" }, "symbol" },
{ { "0x[%da-fA-F]+" }, "number" },
{ { "-?%d+[%d%.]*f?" }, "number" },
{ { "-?%.?%d+f?" }, "number" },
{ { "%f[^<]![%a_][%w%_%-]*" }, "keyword2" },
{ { "%f[^<][%a_][%w%_%-]*" }, "function" },
{ { "%f[^<]/[%a_][%w%_%-]*" }, "function" },
{ { "[%a_][%w_]*" }, "keyword" },
{ { "[/<>=]" }, "operator" },
},
{
{ "return", "keyword" }, { "if", "keyword" }, { "else", "keyword" },
{ "as", "keyword" }, { "do", "keyword" }, { "for", "keyword" },
{ "foreach", "keyword" }, { "while", "keyword" }, { "switch", "keyword" },
{ "case", "keyword" }, { "continue", "keyword" }, { "default", "keyword" },
{ "break", "keyword" }, { "exit", "keyword" }, { "function", "keyword" },
{ "global", "keyword" }, { "const", "keyword" }, { "true", "literal" },
{ "false", "literal" }, { "null", "literal" },
},
"//",
{},
"v1" } )
.setVisible( false );
"",
{ "^#!.*[ /]v1" } } )
.setAutoCloseXMLTags( true );
auto& sd = SyntaxDefinitionManager::instance()
->add( { "V1Core",
{},
{
{ { "<%?v?1?" }, "function" },
{ { "%?>", "<%?v?1?" }, "function", "HTML" },
{ { "//.-\n" }, "comment" },
{ { "/%*", "%*/" }, "comment" },
{ { "#.-\n" }, "comment" },
{ { "\"", "\"", "\\" }, "string" },
{ { "'", "'", "\\" }, "string" },
{ { "%\\x[%da-fA-F]+" }, "number" },
{ { "-?%d+[%d%.eE]*" }, "number" },
{ { "-?%.?%d+" }, "number" },
{ { "[%.%+%-=/%*%^%%<>!~|&]" }, "operator" },
{ { "(if|for|while|foreach|switch)\\s*(?=\\()" },
{ "normal", "keyword", "keyword" },
"",
SyntaxPatternMatchType::RegEx },
{ { "[%a_][%w_]*%s*%f[(]" }, "function" },
{ { "[%a_][%w_]*" }, "symbol" },
},
{
{ "return", "keyword" }, { "if", "keyword" },
{ "else", "keyword" }, { "as", "keyword" },
{ "do", "keyword" }, { "for", "keyword" },
{ "foreach", "keyword" }, { "while", "keyword" },
{ "switch", "keyword" }, { "case", "keyword" },
{ "continue", "keyword" }, { "default", "keyword" },
{ "break", "keyword" }, { "exit", "keyword" },
{ "function", "keyword" }, { "global", "keyword" },
{ "const", "keyword" }, { "true", "literal" },
{ "false", "literal" }, { "null", "literal" },
},
"//",
{},
"v1" } )
.setVisible( false );
sd.setFoldRangeType( FoldRangeType::Braces ).setFoldBraces( { { '{', '}' } } );
}