Skip to content

Commit

Permalink
Added syntax settings for XML
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekazakov committed Jun 17, 2024
1 parent 46c5060 commit 4f7899c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"settings": "Markdown.json",
"filemask": "*.md, *.markdown"
},
{
"name": "XML",
"settings": "XML.json",
"filemask": "*.xml, *.plist"
},
{
"name": "YAML",
"settings": "YAML.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"lexer": "xml",
"wordlists": [],
"properties": {
},
"mapping": {
"SCE_H_DEFAULT": "default",
"SCE_H_TAG": "keyword",
"SCE_H_TAGUNKNOWN": "comment",
"SCE_H_ATTRIBUTE": "identifier",
"SCE_H_ATTRIBUTEUNKNOWN": "comment",
"SCE_H_NUMBER": "number",
"SCE_H_DOUBLESTRING": "string",
"SCE_H_SINGLESTRING": "string",
"SCE_H_OTHER": "operator",
"SCE_H_COMMENT": "comment",
"SCE_H_ENTITY": "identifier",
"SCE_H_TAGEND": "default",
"SCE_H_XMLSTART": "comment",
"SCE_H_XMLEND": "comment",
"SCE_H_CDATA": "string",
"SCE_H_QUESTION": "preprocessor",
"SCE_H_VALUE": "default",
"SCE_H_SGML_DEFAULT": "default",
"SCE_H_SGML_COMMAND": "preprocessor",
"SCE_H_SGML_1ST_PARAM": "preprocessor",
"SCE_H_SGML_DOUBLESTRING": "string",
"SCE_H_SGML_SIMPLESTRING": "string",
"SCE_H_SGML_ERROR": "comment",
"SCE_H_SGML_SPECIAL": "identifier",
"SCE_H_SGML_ENTITY": "identifier",
"SCE_H_SGML_COMMENT": "comment",
"SCE_H_SGML_BLOCK_DEFAULT": "default"
}
}
1 change: 1 addition & 0 deletions Source/Viewer/include/Viewer/Highlighting/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Document final : public Scintilla::IDocument
std::string_view m_Text;
std::vector<uint32_t> m_Lines;
std::vector<int> m_LineStates;
std::vector<int> m_LineLevels;
std::vector<char> m_Styles;
Sci_Position m_StylingPosition = 0;
};
Expand Down
26 changes: 15 additions & 11 deletions Source/Viewer/source/Highlighting/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace nc::viewer::hl {

static constexpr char g_CR = '\x0D';
static constexpr char g_LF = '\x0A';
static constexpr int g_BaseLevel = 0x400;

static constinit std::array<uint8_t, 256> g_UTF8Lengths = []() {
std::array<uint8_t, 256> lengths = {};
Expand Down Expand Up @@ -90,6 +91,7 @@ Document::Document(const std::string_view _text) : m_Text(_text), m_Styles(_text
}

m_LineStates.resize(m_Lines.size() + 1);
m_LineLevels.resize(m_Lines.size(), g_BaseLevel);
}

Document::~Document() = default;
Expand All @@ -109,32 +111,34 @@ bool Document::IsDBCSLeadByte(char) const noexcept
return false;
}

char Document::StyleAt(Sci_Position _position) const noexcept
char Document::StyleAt(const Sci_Position _position) const noexcept
{
if( _position < 0 || _position >= static_cast<long>(m_Text.length()) ) {
return 0;
}
return m_Styles[_position];
}

int Document::GetLevel(Sci_Position /*_line*/) const noexcept
int Document::GetLevel(const Sci_Position _line) const noexcept
{
abort();
return 0;
return _line >= 0 && static_cast<size_t>(_line) < m_LineLevels.size() ? m_LineLevels[_line] : g_BaseLevel;
}

int Document::SetLevel(Sci_Position /*_line*/, int /*_level*/) noexcept
int Document::SetLevel(const Sci_Position _line, const int _level) noexcept
{
abort();
return 0;
if( _line >= 0 && static_cast<size_t>(_line) < m_LineLevels.size() ) {
m_LineLevels[_line] = _level;
return _level;
}
return g_BaseLevel;
}

int Document::GetLineState(Sci_Position _line) const noexcept
int Document::GetLineState(const Sci_Position _line) const noexcept
{
return m_LineStates.at(_line);
}

int Document::SetLineState(Sci_Position _line, int _state) noexcept
int Document::SetLineState(const Sci_Position _line, const int _state) noexcept
{
return m_LineStates.at(_line) = _state;
}
Expand All @@ -145,9 +149,9 @@ int Document::GetLineIndentation(Sci_Position /*_line*/) noexcept
return 0;
}

Sci_Position Document::GetRelativePosition(Sci_Position _position, Sci_Position _offset) const noexcept
Sci_Position Document::GetRelativePosition(const Sci_Position _position, const Sci_Position _offset) const noexcept
{
return _position + _offset;
return _position + _offset; // TODO: is _offset in bytes or in code units?
}

int Document::GetCharacterAndWidth(Sci_Position _position, Sci_Position *_width) const noexcept
Expand Down

0 comments on commit 4f7899c

Please sign in to comment.