Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
Some small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pasnox committed Aug 16, 2012
1 parent bf314cd commit e333702
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 72 deletions.
17 changes: 9 additions & 8 deletions src/QodeEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -50,6 +50,7 @@ class QodeEdit : public QObject
};

enum Style {
InvalidStyle = -1,
NormalStyle,
KeywordStyle,
DataTypeStyle,
Expand Down
23 changes: 0 additions & 23 deletions src/syntax/SyntaxDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,10 @@
#include <QFileInfo>
#include <QDebug>

QHash<QString, QodeEdit::Style> initializedStyleMapping()
{
QHash<QString, QodeEdit::Style> 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<QString, QodeEdit::Style> globalStyleMapping;

QString name;
QString localizedName;
Expand Down Expand Up @@ -95,7 +73,6 @@ class Syntax::DocumentData : public QSharedData
};

QString Syntax::DocumentData::globalDefaultDeliminator( " \t.():!+,-<=>%&*/;?[]^{|}~\\" );
QHash<QString, QodeEdit::Style> Syntax::DocumentData::globalStyleMapping( initializedStyleMapping() );


Syntax::Document::Document()
Expand Down
4 changes: 2 additions & 2 deletions src/syntax/SyntaxDocumentBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( "##" ) ) {
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/syntax/SyntaxHighlighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 )
Expand All @@ -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 )
Expand Down
6 changes: 2 additions & 4 deletions src/syntax/SyntaxHighlighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ class Highlighting
QExplicitlySharedDataPointer<Syntax::HighlightingData> d;

public:
typedef QHash<QString, Syntax::List> 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 );

Expand Down
2 changes: 2 additions & 0 deletions src/syntax/SyntaxList.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#define SYNTAXLIST_H

#include <QSet>
#include <QHash>
#include <QString>

namespace Syntax {

typedef QSet<QString> List;
typedef QHash<QString, Syntax::List> HashList;

}; // Syntax

Expand Down
88 changes: 58 additions & 30 deletions src/syntax/SyntaxParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@
#include <QVariant>
#include <QDebug>

QHash<QString, QodeEdit::Style> initializedStyleMapping()
{
QHash<QString, QodeEdit::Style> 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<QString, QodeEdit::Style> globalStyleMapping( initializedStyleMapping() );

// ParserPrivate

class Syntax::ParserPrivate {
Expand All @@ -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 )
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e333702

Please sign in to comment.