diff --git a/src/QodeEdit.h b/src/QodeEdit.h index cd5a6bb..e109341 100644 --- a/src/QodeEdit.h +++ b/src/QodeEdit.h @@ -12,19 +12,19 @@ class QodeEdit : public QObject public: enum Ruler { - NoRuler = 0x0, - LineRuler = 0x1, - BackgroundRuler = 0x2 + NoRuler = -1, + LineRuler, + BackgroundRuler }; // the order is important as it defined the presentation order of the margins enum Margin { InvalidMargin = -1, - BookmarkMargin = 0, // done - NumberMargin = 1, // done - FoldMargin = 2, - RevisionMargin = 3, // done - SpaceMargin = 4, // done + BookmarkMargin, + NumberMargin, + FoldMargin, + RevisionMargin, + SpaceMargin }; enum Rule { @@ -50,6 +50,7 @@ class QodeEdit : public QObject }; enum Style { + InvalidStyle = -1, NormalStyle, KeywordStyle, DataTypeStyle, diff --git a/src/syntax/SyntaxDocument.cpp b/src/syntax/SyntaxDocument.cpp index a1b8015..6f2e06b 100644 --- a/src/syntax/SyntaxDocument.cpp +++ b/src/syntax/SyntaxDocument.cpp @@ -7,32 +7,10 @@ #include #include -QHash initializedStyleMapping() -{ - QHash hash; - hash[ "alert" ] = QodeEdit::AlertStyle; - hash[ "base-n integer" ] = QodeEdit::BaseNStyle; - hash[ "character" ] = QodeEdit::CharStyle; - hash[ "string char" ] = QodeEdit::CharStyle; - hash[ "comment" ] = QodeEdit::CommentStyle; - hash[ "data type" ] = QodeEdit::DataTypeStyle; - hash[ "decimal/value" ] = QodeEdit::DecValStyle; - hash[ "error" ] = QodeEdit::ErrorStyle; - hash[ "floating point" ] = QodeEdit::FloatStyle; - hash[ "function" ] = QodeEdit::FunctionStyle; - hash[ "keyword" ] = QodeEdit::KeywordStyle; - hash[ "normal" ] = QodeEdit::NormalStyle; - hash[ "others" ] = QodeEdit::OthersStyle; - hash[ "region marker" ] = QodeEdit::RegionMarkerStyle; - hash[ "string" ] = QodeEdit::StringStyle; - return hash; -} - class Syntax::DocumentData : public QSharedData { public: static QString globalDefaultDeliminator; - static QHash globalStyleMapping; QString name; QString localizedName; @@ -95,7 +73,6 @@ class Syntax::DocumentData : public QSharedData }; QString Syntax::DocumentData::globalDefaultDeliminator( " \t.():!+,-<=>%&*/;?[]^{|}~\\" ); -QHash Syntax::DocumentData::globalStyleMapping( initializedStyleMapping() ); Syntax::Document::Document() diff --git a/src/syntax/SyntaxDocumentBuilder.cpp b/src/syntax/SyntaxDocumentBuilder.cpp index 88a7554..fbf49a5 100644 --- a/src/syntax/SyntaxDocumentBuilder.cpp +++ b/src/syntax/SyntaxDocumentBuilder.cpp @@ -27,7 +27,7 @@ class Syntax::DocumentBuilderData : public QSharedData // import external initial context rules if ( srcContextName.startsWith( "##" ) ) { srcSyntaxName = srcContextName.mid( 2 ); - srcContextName.clear(); // filled up later with document initialContext + srcContextName.clear(); // filled up later with document defaultContext } // import external contex rules else if ( srcContextName.contains( "##" ) ) { @@ -46,7 +46,7 @@ class Syntax::DocumentBuilderData : public QSharedData // get source context name if needed if ( rule.context().startsWith( "##" ) ) { - srcContextName = srcDocument.highlighting().initialContext(); + srcContextName = srcDocument.highlighting().defaultContext(); } // get source context diff --git a/src/syntax/SyntaxHighlighting.cpp b/src/syntax/SyntaxHighlighting.cpp index ffebc61..ac7ae86 100644 --- a/src/syntax/SyntaxHighlighting.cpp +++ b/src/syntax/SyntaxHighlighting.cpp @@ -3,8 +3,8 @@ class Syntax::HighlightingData : public QSharedData { public: - QString initialContext; - Syntax::Highlighting::Hash lists; + QString defaultContext; + Syntax::HashList lists; Syntax::Context::Hash contexts; Syntax::ItemData::Hash itemDatas; @@ -15,7 +15,7 @@ class Syntax::HighlightingData : public QSharedData HighlightingData( const Syntax::HighlightingData& other ) : QSharedData( other ), - SYNTAX_OTHER_INIT( initialContext ), + SYNTAX_OTHER_INIT( defaultContext ), SYNTAX_OTHER_INIT( lists ), SYNTAX_OTHER_INIT( contexts ), SYNTAX_OTHER_INIT( itemDatas ) @@ -40,8 +40,8 @@ Syntax::Highlighting::~Highlighting() { } -SYNTAX_IMPL_MEMBER( QString, initialContext, Highlighting ) -SYNTAX_IMPL_MEMBER( Syntax::Highlighting::Hash, lists, Highlighting ) +SYNTAX_IMPL_MEMBER( QString, defaultContext, Highlighting ) +SYNTAX_IMPL_MEMBER( Syntax::HashList, lists, Highlighting ) SYNTAX_IMPL_MEMBER( Syntax::Context::Hash, contexts, Highlighting ) SYNTAX_IMPL_MEMBER( Syntax::ItemData::Hash, itemDatas, Highlighting ) SYNTAX_IMPL_OPERATORS( Highlighting ) diff --git a/src/syntax/SyntaxHighlighting.h b/src/syntax/SyntaxHighlighting.h index 9b145d7..214450a 100644 --- a/src/syntax/SyntaxHighlighting.h +++ b/src/syntax/SyntaxHighlighting.h @@ -18,10 +18,8 @@ class Highlighting QExplicitlySharedDataPointer d; public: - typedef QHash Hash; // FIXME bad name better set Syntax::HashList typedef - - SYNTAX_DECL_MEMBER( QString, initialContext ); - SYNTAX_DECL_MEMBER( Syntax::Highlighting::Hash, lists ); + SYNTAX_DECL_MEMBER( QString, defaultContext ); + SYNTAX_DECL_MEMBER( Syntax::HashList, lists ); SYNTAX_DECL_MEMBER( Syntax::Context::Hash, contexts ); SYNTAX_DECL_MEMBER( Syntax::ItemData::Hash, itemDatas ); diff --git a/src/syntax/SyntaxList.h b/src/syntax/SyntaxList.h index 6c75bb4..d1ac0ce 100644 --- a/src/syntax/SyntaxList.h +++ b/src/syntax/SyntaxList.h @@ -2,11 +2,13 @@ #define SYNTAXLIST_H #include +#include #include namespace Syntax { typedef QSet List; +typedef QHash HashList; }; // Syntax diff --git a/src/syntax/SyntaxParser.cpp b/src/syntax/SyntaxParser.cpp index 52ea6b0..dbccf84 100644 --- a/src/syntax/SyntaxParser.cpp +++ b/src/syntax/SyntaxParser.cpp @@ -6,6 +6,29 @@ #include #include +QHash initializedStyleMapping() +{ + QHash hash; + hash[ "alert" ] = QodeEdit::AlertStyle; + hash[ "base-n integer" ] = QodeEdit::BaseNStyle; + hash[ "character" ] = QodeEdit::CharStyle; + hash[ "string char" ] = QodeEdit::CharStyle; + hash[ "comment" ] = QodeEdit::CommentStyle; + hash[ "data type" ] = QodeEdit::DataTypeStyle; + hash[ "decimal/value" ] = QodeEdit::DecValStyle; + hash[ "error" ] = QodeEdit::ErrorStyle; + hash[ "floating point" ] = QodeEdit::FloatStyle; + hash[ "function" ] = QodeEdit::FunctionStyle; + hash[ "keyword" ] = QodeEdit::KeywordStyle; + hash[ "normal" ] = QodeEdit::NormalStyle; + hash[ "others" ] = QodeEdit::OthersStyle; + hash[ "region marker" ] = QodeEdit::RegionMarkerStyle; + hash[ "string" ] = QodeEdit::StringStyle; + return hash; +} + +static QHash globalStyleMapping( initializedStyleMapping() ); + // ParserPrivate class Syntax::ParserPrivate { @@ -25,33 +48,33 @@ class Syntax::ParserPrivate { ParserPrivate( Syntax::Parser* _parser ) : ruleNames( Syntax::List() - << "anychar" // AnyChar - - << "detect2chars" // Detect2Chars - << "detectchar" // DetectChar - << "detectidentifier" // DetectIdentifier - << "detectspaces" // DetectSpaces - - << "float" // Float - - << "hlcchar" // HlCChar - << "hlchex" // HlCHex - << "hlcoct" // HlCOct - << "hlcstringchar" // HlCStringChar - - << "includerules" // IncludeRules - << "int" // Int - - << "keyword" // Keyword - - << "linecontinue" // LineContinue - - << "rangedetect" // RangeDetect - << "regexpr" // RegExpr - - << "stringdetect" // StringDetect - - << "worddetect" // WordDetect + << "anychar" // AnyChar + + << "detect2chars" // Detect2Chars + << "detectchar" // DetectChar + << "detectidentifier" // DetectIdentifier + << "detectspaces" // DetectSpaces + + << "float" // Float + + << "hlcchar" // HlCChar + << "hlchex" // HlCHex + << "hlcoct" // HlCOct + << "hlcstringchar" // HlCStringChar + + << "includerules" // IncludeRules + << "int" // Int + + << "keyword" // Keyword + + << "linecontinue" // LineContinue + + << "rangedetect" // RangeDetect + << "regexpr" // RegExpr + + << "stringdetect" // StringDetect + + << "worddetect" // WordDetect ), document( 0 ), parser( _parser ) @@ -288,8 +311,8 @@ bool Syntax::Parser::startElement( const QString& namespaceURI, const QString& l d->document->highlighting().contexts()[ context.name() ] = context; - if ( d->document->highlighting().initialContext().isEmpty() ) { - d->document->highlighting().initialContext() = context.name(); + if ( d->document->highlighting().defaultContext().isEmpty() ) { + d->document->highlighting().defaultContext() = context.name(); } Q_ASSERT( !context.name().isEmpty() ); @@ -385,10 +408,15 @@ bool Syntax::Parser::startElement( const QString& namespaceURI, const QString& l const QString name = atts.qName( i ); if ( QodeEdit::stringEquals( name, "name" ) ) { - itemData.name() = atts.value( i ); + itemData.name() = atts.value( i ).toLower(); } else if ( QodeEdit::stringEquals( name, "defStyleNum" ) ) { itemData.defStyleNum() = atts.value( i ); + + if ( QodeEdit::stringToStyle( itemData.defStyleNum() ) == -1 ) { + qWarning( "%s: Fixed invalid style to dsNormal in %s", Q_FUNC_INFO, qPrintable( d->document->name() ) ); + itemData.defStyleNum() = "dsNormal"; + } } else if ( QodeEdit::stringEquals( name, "spellChecking" ) ) { itemData.spellChecking() = QVariant( atts.value( i ) ).toBool();