mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
+ enh: a little bit more advanced TOML Lexer
This commit is contained in:
parent
9d8c7bbe6c
commit
cf2ca6de9a
1069
oniguruma/doc/SYNTAX.md
Normal file
1069
oniguruma/doc/SYNTAX.md
Normal file
File diff suppressed because it is too large
Load Diff
49
sciXlexers/CharSetX.h
Normal file
49
sciXlexers/CharSetX.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#ifndef _CHARSETX_H_
|
||||
#define _CHARSETX_H_
|
||||
|
||||
#include "StyleContext.h"
|
||||
#include "CharacterSet.h"
|
||||
|
||||
// Functions for classifying characters
|
||||
|
||||
// *** Methods from "scintilla\lexlib\CharacterSet.h" ***
|
||||
//- IsASpace(int ch);
|
||||
//- IsASpaceOrTab(int ch);
|
||||
//- IsADigit(int ch);
|
||||
//- IsADigit(int ch, int base);
|
||||
//- IsASCII(int ch);
|
||||
//- IsLowerCase(int ch);
|
||||
//- IsUpperCase(int ch);
|
||||
//- IsUpperOrLowerCase(int ch);
|
||||
//- IsAlphaNumeric(int ch);
|
||||
|
||||
constexpr bool IsALetter(const int ch) noexcept {
|
||||
// 97 to 122 || 65 to 90
|
||||
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
|
||||
}
|
||||
|
||||
constexpr bool IsLineBreak(const int ch) noexcept {
|
||||
return ((ch == '\n') || (ch == '\r'));
|
||||
}
|
||||
|
||||
constexpr int IsNumHex(const Scintilla::StyleContext& sc) noexcept {
|
||||
return (sc.chNext == 'x') || (sc.chNext == 'X');
|
||||
}
|
||||
|
||||
constexpr int IsNumBinary(const Scintilla::StyleContext& sc) noexcept {
|
||||
return (sc.chNext == 'b') || (sc.chNext == 'B');
|
||||
}
|
||||
|
||||
|
||||
inline int IsNumOctal(const Scintilla::StyleContext& sc) {
|
||||
return Scintilla::IsADigit(sc.chNext) || (sc.chNext == 'o');
|
||||
}
|
||||
|
||||
inline bool IsAIdentifierChar(const int ch) {
|
||||
return (Scintilla::IsAlphaNumeric(ch) || ch == '_' || ch == '.');
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif //_CHARSETX_H_
|
||||
@ -26,7 +26,7 @@
|
||||
#include "LexAccessor.h"
|
||||
#include "Accessor.h"
|
||||
#include "StyleContext.h"
|
||||
#include "CharacterSet.h"
|
||||
#include "CharSetX.h"
|
||||
#include "LexerModule.h"
|
||||
#include "OptionSet.h"
|
||||
#include "DefaultLexer.h"
|
||||
@ -508,7 +508,7 @@ void SCI_METHOD LexerAHKL::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, i
|
||||
inCommand = true;
|
||||
}
|
||||
|
||||
// if ((OnlySpaces || isspace(sc.chPrev)) && sc.Match(';')) {
|
||||
// if ((OnlySpaces || IsASpace(sc.chPrev)) && sc.Match(';')) {
|
||||
|
||||
// sc.SetState(SCE_AHKL_STRINGCOMMENT);
|
||||
|
||||
@ -613,16 +613,17 @@ void SCI_METHOD LexerAHKL::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, i
|
||||
expLevel += 1;
|
||||
inExpression = true;
|
||||
|
||||
if (sc.Match(" % "))
|
||||
inCommand = false;
|
||||
if (sc.Match(" % ")) {
|
||||
inCommand = false;
|
||||
}
|
||||
|
||||
} else if (sc.ch == ']' || sc.ch == ')') {
|
||||
|
||||
expLevel -= 1, inCommand = false;
|
||||
|
||||
if (expLevel == 0)
|
||||
inExpression = false;
|
||||
|
||||
if (expLevel == 0) {
|
||||
inExpression = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Command continuation section
|
||||
@ -635,7 +636,7 @@ void SCI_METHOD LexerAHKL::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, i
|
||||
if (valIdentifier.Contains(sc.ch))
|
||||
validFunction = true;
|
||||
|
||||
if (isdigit(sc.ch & 0xFF))
|
||||
if (IsADigit(sc.ch))
|
||||
sc.SetState(SCE_AHKL_DECNUMBER);
|
||||
|
||||
else if (inCommand && sc.ch == '+')
|
||||
@ -699,14 +700,11 @@ void SCI_METHOD LexerAHKL::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, i
|
||||
|
||||
inHotstring = true;
|
||||
sc.SetState(SCE_AHKL_HOTSTRINGOPT);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!isspace(sc.ch))
|
||||
OnlySpaces = false;
|
||||
|
||||
if (!IsASpace((sc.ch))) {
|
||||
OnlySpaces = false;
|
||||
}
|
||||
}
|
||||
|
||||
sc.Complete();
|
||||
|
||||
@ -25,11 +25,12 @@
|
||||
#include "LexAccessor.h"
|
||||
#include "Accessor.h"
|
||||
#include "StyleContext.h"
|
||||
#include "CharacterSet.h"
|
||||
#include "CharSetX.h"
|
||||
#include "LexerModule.h"
|
||||
#include "OptionSet.h"
|
||||
#include "DefaultLexer.h"
|
||||
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
namespace {
|
||||
@ -48,34 +49,9 @@ namespace {
|
||||
|
||||
int GetDataTypeStyle(const int numType) {
|
||||
if (numType == DataType::Unknown) {
|
||||
return SCE_TOML_TYPEERROR;
|
||||
return SCE_TOML_PARSINGERROR;
|
||||
}
|
||||
return SCE_TOML_DATATYPE;
|
||||
}
|
||||
|
||||
inline bool IsLetter(const int ch) {
|
||||
// 97 to 122 || 65 to 90
|
||||
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
|
||||
}
|
||||
|
||||
inline bool IsAWordChar(const int ch) {
|
||||
return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.');
|
||||
}
|
||||
|
||||
inline int IsNumHex(const StyleContext& sc) {
|
||||
return (sc.chNext == 'x') || (sc.chNext == 'X');
|
||||
}
|
||||
|
||||
inline int IsNumBinary(const StyleContext& sc) {
|
||||
return (sc.chNext == 'b') || (sc.chNext == 'B');
|
||||
}
|
||||
|
||||
inline int IsNumOctal(const StyleContext& sc) {
|
||||
return IsADigit(sc.chNext) || sc.chNext == 'o';
|
||||
}
|
||||
|
||||
constexpr bool IsNewline(const int ch) noexcept {
|
||||
return (ch == '\n' || ch == '\r');
|
||||
return SCE_TOML_VALUE;
|
||||
}
|
||||
|
||||
inline bool IsFuncName(const char* str) {
|
||||
@ -88,34 +64,14 @@ namespace {
|
||||
"iterator",
|
||||
"converter"
|
||||
};
|
||||
|
||||
for (const char* id : identifiers) {
|
||||
if (strcmp(str, id) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//constexpr bool IsTripleLiteral(const int style) noexcept {
|
||||
// return style == SCE_TOML_TRIPLE || style == SCE_TOML_TRIPLEDOUBLE;
|
||||
//}
|
||||
//
|
||||
//constexpr bool IsLineComment(const int style) noexcept {
|
||||
// return style == SCE_TOML_COMMENTLINE || style == SCE_TOML_COMMENTLINEDOC;
|
||||
//}
|
||||
//
|
||||
//constexpr bool IsStreamComment(const int style) noexcept {
|
||||
// return style == SCE_TOML_COMMENT || style == SCE_TOML_COMMENTDOC;
|
||||
//}
|
||||
|
||||
|
||||
constexpr bool IsAssignChar(unsigned char ch) {
|
||||
return (ch == '=') || (ch == ':');
|
||||
}
|
||||
|
||||
|
||||
struct OptionsTOML {
|
||||
bool fold;
|
||||
bool foldCompact;
|
||||
@ -127,7 +83,7 @@ namespace {
|
||||
};
|
||||
|
||||
static const char* const tomlWordListDesc[] = {
|
||||
"Keywords",
|
||||
"TOML",
|
||||
nullptr
|
||||
};
|
||||
|
||||
@ -141,17 +97,16 @@ namespace {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
LexicalClass lexicalClasses[] = {
|
||||
// Lexer TOML SCLEX_TOML SCE_TOML_:
|
||||
0, "SCE_TOML_DEFAULT", "default", "White space",
|
||||
1, "SCE_TOML_COMMENT", "comment block", "Block comment",
|
||||
2, "SCE_TOML_KEY", "keyc", "Keyword",
|
||||
0, "SCE_TOML_DEFAULT", "default", "Default",
|
||||
1, "SCE_TOML_COMMENT", "comment", "Comment",
|
||||
2, "SCE_TOML_KEY", "key", "Key",
|
||||
3, "SCE_TOML_SECTION", "section", "Section",
|
||||
4, "SCE_TOML_ASSIGNMENT", "assignment", "Assignment",
|
||||
5, "SCE_TOML_DEFVAL", "default value", "Default Value",
|
||||
6, "SCE_TOML_DATATYPE", "datatype", "Datatype",
|
||||
7, "SCE_TOML_TYPEERROR", "type error", "Type Error",
|
||||
6, "SCE_TOML_VALUETYPE", "value type", "Value Type",
|
||||
7, "SCE_TOML_PARSINGERROR", "type error", "Type Error",
|
||||
};
|
||||
|
||||
} // end of namespace
|
||||
@ -163,9 +118,10 @@ class LexerTOML : public DefaultLexer {
|
||||
OptionSetTOML osTOML;
|
||||
|
||||
public:
|
||||
LexerTOML() :
|
||||
DefaultLexer(lexicalClasses, ELEMENTS(lexicalClasses)),
|
||||
setWord(CharacterSet::setAlphaNum, "_", 0x80, true) { }
|
||||
LexerTOML()
|
||||
: DefaultLexer(lexicalClasses, ELEMENTS(lexicalClasses))
|
||||
, setWord(CharacterSet::setAlphaNum, "_", 0x80, true)
|
||||
{ }
|
||||
|
||||
virtual ~LexerTOML() { }
|
||||
|
||||
@ -189,19 +145,13 @@ public:
|
||||
return osTOML.DescribeProperty(name);
|
||||
}
|
||||
|
||||
Sci_Position SCI_METHOD PropertySet(const char* key, const char* val) override;
|
||||
|
||||
const char* SCI_METHOD DescribeWordListSets() override {
|
||||
return osTOML.DescribeWordListSets();
|
||||
}
|
||||
|
||||
Sci_Position SCI_METHOD WordListSet(int n, const char* wl) override;
|
||||
|
||||
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument* pAccess) override;
|
||||
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument* pAccess) override;
|
||||
|
||||
void* SCI_METHOD PrivateCall(int, void*) override {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int SCI_METHOD LineEndTypesSupported() override {
|
||||
@ -215,8 +165,20 @@ public:
|
||||
static ILexer4* LexerFactoryTOML() {
|
||||
return new LexerTOML();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
Sci_Position SCI_METHOD PropertySet(const char* key, const char* val) override;
|
||||
|
||||
Sci_Position SCI_METHOD WordListSet(int n, const char* wl) override;
|
||||
|
||||
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument* pAccess) override;
|
||||
|
||||
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument* pAccess) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Sci_Position SCI_METHOD LexerTOML::PropertySet(const char* key, const char* val) {
|
||||
if (osTOML.PropertySet(&options, key, val)) {
|
||||
return 0;
|
||||
@ -225,8 +187,9 @@ Sci_Position SCI_METHOD LexerTOML::PropertySet(const char* key, const char* val)
|
||||
}
|
||||
|
||||
|
||||
Sci_Position SCI_METHOD LexerTOML::WordListSet(int n, const char* wl) {
|
||||
WordList* wordListN = 0;
|
||||
Sci_Position SCI_METHOD LexerTOML::WordListSet(int n, const char* wl)
|
||||
{
|
||||
WordList* wordListN = nullptr;
|
||||
|
||||
switch (n) {
|
||||
case 0:
|
||||
@ -245,100 +208,259 @@ Sci_Position SCI_METHOD LexerTOML::WordListSet(int n, const char* wl) {
|
||||
firstModification = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return firstModification;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
static inline bool AtEOL(Accessor& styler, Sci_PositionU i)
|
||||
{
|
||||
return (styler[i] == '\n') || ((styler[i] == '\r') && (styler.SafeGetCharAt(i + 1) != '\n'));
|
||||
constexpr bool IsCommentChar(const int ch) noexcept {
|
||||
//return (ch == '#') || (ch == ':');
|
||||
return (ch == '#');
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
constexpr bool IsAssignChar(const int ch) noexcept {
|
||||
//return (ch == '=') || (ch == ':');
|
||||
return (ch == '=');
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
inline bool IsAKeyChar(const int ch) {
|
||||
return (IsAlphaNumeric(ch) || ch == '_');
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
static int GetBracketLevel(StyleContext& sc)
|
||||
{
|
||||
Sci_Position const posCurrent = static_cast<Sci_Position>(sc.currentPos);
|
||||
|
||||
bool ignore = false;
|
||||
int iBracketLevel = -1;
|
||||
|
||||
Sci_Position i = 0;
|
||||
while ((--i + posCurrent) >= 0)
|
||||
{
|
||||
if (sc.GetRelative(i) == '"') {
|
||||
ignore = !ignore; // toggle string
|
||||
}
|
||||
else if (!ignore) {
|
||||
if (IsAssignChar(sc.GetRelative(i))) {
|
||||
break; // must be within assignment
|
||||
}
|
||||
else if (sc.GetRelative(i) == ']') {
|
||||
--iBracketLevel;
|
||||
}
|
||||
else if (sc.GetRelative(i) == '[') {
|
||||
++iBracketLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
return iBracketLevel;
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
void SCI_METHOD LexerTOML::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument* pAccess)
|
||||
{
|
||||
|
||||
Accessor styler(pAccess, nullptr);
|
||||
StyleContext sc(startPos, length, initStyle, styler);
|
||||
|
||||
bool inSectionDef = false;
|
||||
bool inMultiLnString = (sc.state == SCE_TOML_STRING);
|
||||
bool inMultiLnArrayDef = (sc.state == SCE_TOML_ARRAY);
|
||||
|
||||
for (; sc.More(); sc.Forward())
|
||||
{
|
||||
|
||||
// --------------------------------------------------
|
||||
// check if in the middle of a line continuation ...
|
||||
// --------------------------------------------------
|
||||
if (sc.atLineStart) {
|
||||
sc.SetState(SCE_TOML_DEFAULT);
|
||||
switch (sc.state)
|
||||
{
|
||||
case SCE_TOML_STRING:
|
||||
if (!inMultiLnString) {
|
||||
sc.SetState(SCE_TOML_PARSINGERROR);
|
||||
}
|
||||
break;
|
||||
case SCE_TOML_ARRAY:
|
||||
if (!inMultiLnArrayDef) {
|
||||
sc.SetState(SCE_TOML_PARSINGERROR);
|
||||
}
|
||||
break;
|
||||
case SCE_TOML_PARSINGERROR:
|
||||
// preserve error
|
||||
break;
|
||||
default:
|
||||
sc.SetState(SCE_TOML_DEFAULT); // reset
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (sc.state)
|
||||
|
||||
// -------------------------
|
||||
// current state independent
|
||||
// -------------------------
|
||||
if (IsLineBreak(sc.ch)) {
|
||||
continue; // eat line breaks
|
||||
}
|
||||
|
||||
if (sc.ch != SCE_TOML_PARSINGERROR)
|
||||
{
|
||||
if (IsCommentChar(sc.ch)) {
|
||||
if (inSectionDef) {
|
||||
sc.SetState(SCE_TOML_PARSINGERROR);
|
||||
}
|
||||
else if (inMultiLnString || inMultiLnArrayDef) {
|
||||
sc.ForwardSetState(sc.state); // ignore
|
||||
}
|
||||
else {
|
||||
sc.SetState(SCE_TOML_COMMENT);
|
||||
}
|
||||
}
|
||||
|
||||
} // SCE_TOML_PARSINGERROR
|
||||
|
||||
|
||||
// -------------------------
|
||||
// state dependent
|
||||
// -------------------------
|
||||
switch (sc.state)
|
||||
{
|
||||
case SCE_TOML_DEFAULT:
|
||||
{
|
||||
if (sc.ch == '#' || sc.ch == '!' || sc.ch == ';') {
|
||||
if (IsASpaceOrTab(sc.ch)) {
|
||||
// eat
|
||||
}
|
||||
else if (IsCommentChar(sc.ch)) {
|
||||
sc.SetState(SCE_TOML_COMMENT);
|
||||
}
|
||||
else if (sc.ch == '[') {
|
||||
sc.SetState(SCE_TOML_SECTION);
|
||||
inSectionDef = true;
|
||||
}
|
||||
else if (sc.ch == '@') {
|
||||
sc.SetState(SCE_TOML_DEFVAL);
|
||||
}
|
||||
else if (IsAssignChar(sc.ch)) {
|
||||
sc.SetState(SCE_TOML_ASSIGNMENT);
|
||||
}
|
||||
else if (IsLetter(sc.ch)) {
|
||||
else if (IsAKeyChar(sc.ch)) {
|
||||
sc.SetState(SCE_TOML_KEY);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_TOML_COMMENT:
|
||||
else {
|
||||
sc.SetState(SCE_TOML_PARSINGERROR);
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_TOML_KEY:
|
||||
if (!IsLetter(sc.ch)) {
|
||||
if (IsAssignChar(sc.ch)) {
|
||||
sc.SetState(SCE_TOML_ASSIGNMENT);
|
||||
}
|
||||
else {
|
||||
sc.SetState(SCE_TOML_DEFAULT);
|
||||
}
|
||||
}
|
||||
case SCE_TOML_COMMENT:
|
||||
// eat - rest of line is comment
|
||||
break;
|
||||
|
||||
case SCE_TOML_SECTION:
|
||||
if (sc.ch == ']') {
|
||||
sc.Forward();
|
||||
sc.SetState(SCE_TOML_DEFAULT);
|
||||
inSectionDef = false;
|
||||
}
|
||||
break;
|
||||
else if (IsCommentChar(sc.ch)) {
|
||||
if (!inSectionDef) {
|
||||
sc.SetState(SCE_TOML_COMMENT);
|
||||
}
|
||||
else {
|
||||
sc.SetState(SCE_TOML_PARSINGERROR);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_TOML_KEY:
|
||||
if (IsASpaceOrTab(sc.ch)) {
|
||||
sc.SetState(SCE_TOML_ASSIGNMENT); // end of key
|
||||
}
|
||||
else if (IsAssignChar(sc.ch)) {
|
||||
sc.SetState(SCE_TOML_ASSIGNMENT);
|
||||
}
|
||||
else if (!IsAKeyChar(sc.ch)) {
|
||||
sc.SetState(SCE_TOML_PARSINGERROR);
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_TOML_ASSIGNMENT:
|
||||
if (!IsAssignChar(sc.ch)) {
|
||||
sc.SetState(SCE_TOML_DEFVAL);
|
||||
if (IsAssignChar(sc.ch)) {
|
||||
sc.ForwardSetState(SCE_TOML_VALUE);
|
||||
// fall through case SCE_TOML_VALUE:
|
||||
}
|
||||
else if (IsASpaceOrTab(sc.ch)) {
|
||||
break; // OK
|
||||
}
|
||||
else {
|
||||
sc.SetState(SCE_TOML_PARSINGERROR);
|
||||
break;
|
||||
}
|
||||
// fall through
|
||||
|
||||
case SCE_TOML_VALUE:
|
||||
if (sc.ch == '[') {
|
||||
sc.SetState(SCE_TOML_ARRAY);
|
||||
inMultiLnArrayDef = true;
|
||||
}
|
||||
else if (sc.ch == ']') {
|
||||
sc.SetState(SCE_TOML_PARSINGERROR);
|
||||
}
|
||||
else if (sc.ch == '"') {
|
||||
sc.SetState(SCE_TOML_STRING);
|
||||
if (sc.Match(R"(""")")) {
|
||||
inMultiLnString = true;
|
||||
sc.Forward(2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_TOML_DEFVAL:
|
||||
case SCE_TOML_STRING:
|
||||
if (sc.ch == '\\') {
|
||||
sc.ForwardSetState(SCE_TOML_STRING);
|
||||
}
|
||||
else if (sc.ch == '"') {
|
||||
if (!inMultiLnString) {
|
||||
sc.ForwardSetState(SCE_TOML_VALUE);
|
||||
}
|
||||
else {
|
||||
// inMultiLnString
|
||||
if (sc.Match(R"(""")")) {
|
||||
sc.Forward(2);
|
||||
sc.ForwardSetState(SCE_TOML_VALUE);
|
||||
inMultiLnString = false;
|
||||
}
|
||||
else {
|
||||
sc.SetState(SCE_TOML_PARSINGERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_TOML_DATATYPE:
|
||||
case SCE_TOML_ARRAY:
|
||||
if (sc.ch == ']') {
|
||||
int const level = GetBracketLevel(sc);
|
||||
if (level == 0) {
|
||||
sc.ForwardSetState(SCE_TOML_VALUE);
|
||||
inMultiLnArrayDef = false;
|
||||
}
|
||||
else if (level < 0) {
|
||||
sc.SetState(SCE_TOML_PARSINGERROR);
|
||||
inMultiLnArrayDef = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SCE_TOML_TYPEERROR:
|
||||
case SCE_TOML_PARSINGERROR:
|
||||
// still parsing error until new line
|
||||
break;
|
||||
|
||||
default:
|
||||
sc.SetState(SCE_TOML_PARSINGERROR); // unknown
|
||||
break;
|
||||
}
|
||||
|
||||
if (sc.atLineEnd) {
|
||||
sc.SetState(SCE_TOML_DEFAULT);
|
||||
}
|
||||
//if (sc.atLineEnd) {
|
||||
// // ---
|
||||
//}
|
||||
|
||||
}
|
||||
sc.Complete();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
@ -348,7 +470,7 @@ void SCI_METHOD LexerTOML::Fold(Sci_PositionU startPos, Sci_Position length, int
|
||||
return;
|
||||
}
|
||||
|
||||
Accessor styler(pAccess, NULL);
|
||||
Accessor styler(pAccess, nullptr);
|
||||
|
||||
//const Sci_Position docLines = styler.GetLine(styler.Length());
|
||||
//const Sci_Position maxPos = startPos + length;
|
||||
@ -426,5 +548,9 @@ void SCI_METHOD LexerTOML::Fold(Sci_PositionU startPos, Sci_Position length, int
|
||||
styler.SetLevel(lineCurrent, lev | (flagsNext & ~SC_FOLDLEVELNUMBERMASK));
|
||||
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
LexerModule lmTOML(SCLEX_TOML, LexerTOML::LexerFactoryTOML, "toml", tomlWordListDesc);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
#ifndef SCIXLEXER_H
|
||||
#define SCIXLEXER_H
|
||||
#pragma once
|
||||
#ifndef _SCIXLEXER_H_
|
||||
#define _SCIXLEXER_H_
|
||||
|
||||
#define SCLEX_AHKL 200
|
||||
#define SCLEX_TOML 201
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// !!!!! ADD Lexer Linkage in: Notepad3\scintilla\src\Catalogue.cxx !!!!!
|
||||
// !!!!! ADD Lexer Linkage in: scintilla\src\Catalogue.cxx !!!!!
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define SCE_AHKL_NEUTRAL 0
|
||||
@ -43,12 +44,13 @@
|
||||
|
||||
#define SCE_TOML_DEFAULT 0
|
||||
#define SCE_TOML_COMMENT 1
|
||||
#define SCE_TOML_KEY 2
|
||||
#define SCE_TOML_SECTION 3
|
||||
#define SCE_TOML_SECTION 2
|
||||
#define SCE_TOML_KEY 3
|
||||
#define SCE_TOML_ASSIGNMENT 4
|
||||
#define SCE_TOML_DEFVAL 5
|
||||
#define SCE_TOML_DATATYPE 6
|
||||
#define SCE_TOML_TYPEERROR 7
|
||||
#define SCE_TOML_VALUE 5
|
||||
#define SCE_TOML_STRING 6
|
||||
#define SCE_TOML_ARRAY 7
|
||||
#define SCE_TOML_PARSINGERROR 8
|
||||
|
||||
|
||||
#endif
|
||||
#endif //_SCIXLEXER_H_
|
||||
|
||||
@ -326,6 +326,7 @@
|
||||
<ClInclude Include="..\oniguruma\src\regint.h" />
|
||||
<ClInclude Include="..\oniguruma\src\regparse.h" />
|
||||
<ClInclude Include="..\oniguruma\src\st.h" />
|
||||
<ClInclude Include="..\sciXlexers\CharSetX.h" />
|
||||
<ClInclude Include="..\sciXlexers\SciXLexer.h" />
|
||||
<ClInclude Include="include\ILexer.h" />
|
||||
<ClInclude Include="include\ILoader.h" />
|
||||
|
||||
@ -554,5 +554,8 @@
|
||||
<ClInclude Include="..\oniguruma\src\config.h">
|
||||
<Filter>oniguruma</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\sciXlexers\CharSetX.h">
|
||||
<Filter>sciXlexers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@ -325,7 +325,7 @@ template<class SI_CHAR, class SI_STRLESS, class SI_CONVERTER>
|
||||
class CSimpleIniTempl
|
||||
{
|
||||
public:
|
||||
typedef SI_CHAR SI_CHAR_T;
|
||||
using SI_CHAR_T = SI_CHAR;
|
||||
|
||||
/** key entry */
|
||||
struct Entry {
|
||||
@ -377,15 +377,15 @@ public:
|
||||
};
|
||||
|
||||
/** map keys to values */
|
||||
typedef std::multimap<Entry,const SI_CHAR *,typename Entry::KeyOrder> TKeyVal;
|
||||
using TKeyVal = std::multimap<Entry,const SI_CHAR *,typename Entry::KeyOrder>;
|
||||
|
||||
/** map sections to key/value map */
|
||||
typedef std::map<Entry,TKeyVal,typename Entry::KeyOrder> TSection;
|
||||
using TSection = std::map<Entry,TKeyVal,typename Entry::KeyOrder>;
|
||||
|
||||
/** set of dependent string pointers. Note that these pointers are
|
||||
dependent on memory owned by CSimpleIni.
|
||||
*/
|
||||
typedef std::list<Entry> TNamesDepend;
|
||||
using TNamesDepend = std::list<Entry>;
|
||||
|
||||
/** interface definition for the OutputWriter object to pass to Save()
|
||||
in order to output the INI file data.
|
||||
@ -895,8 +895,8 @@ public:
|
||||
const SI_CHAR * GetValue(
|
||||
const SI_CHAR * a_pSection,
|
||||
const SI_CHAR * a_pKey,
|
||||
const SI_CHAR * a_pDefault = NULL,
|
||||
bool * a_pHasMultiple = NULL
|
||||
const SI_CHAR * a_pDefault = nullptr,
|
||||
bool * a_pHasMultiple = nullptr
|
||||
) const;
|
||||
|
||||
/** Retrieve a numeric value for a specific key. If multiple keys are enabled
|
||||
@ -916,7 +916,7 @@ public:
|
||||
const SI_CHAR * a_pSection,
|
||||
const SI_CHAR * a_pKey,
|
||||
long a_nDefault = 0,
|
||||
bool * a_pHasMultiple = NULL
|
||||
bool * a_pHasMultiple = nullptr
|
||||
) const;
|
||||
|
||||
/** Retrieve a numeric value for a specific key. If multiple keys are enabled
|
||||
@ -936,7 +936,7 @@ public:
|
||||
const SI_CHAR * a_pSection,
|
||||
const SI_CHAR * a_pKey,
|
||||
double a_nDefault = 0,
|
||||
bool * a_pHasMultiple = NULL
|
||||
bool * a_pHasMultiple = nullptr
|
||||
) const;
|
||||
|
||||
/** Retrieve a boolean value for a specific key. If multiple keys are enabled
|
||||
@ -961,7 +961,7 @@ public:
|
||||
const SI_CHAR * a_pSection,
|
||||
const SI_CHAR * a_pKey,
|
||||
bool a_bDefault = false,
|
||||
bool * a_pHasMultiple = NULL
|
||||
bool * a_pHasMultiple = nullptr
|
||||
) const;
|
||||
|
||||
/** Add or update a section or value. This will always insert
|
||||
@ -1358,7 +1358,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadFile(
|
||||
)
|
||||
{
|
||||
strcpy_s(m_FilePathA, _countof(m_FilePathA), a_pszFile);
|
||||
FILE * fp = NULL;
|
||||
FILE * fp = nullptr;
|
||||
#if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
|
||||
fopen_s(&fp, a_pszFile, "rb");
|
||||
#else // !__STDC_WANT_SECURE_LIB__
|
||||
@ -1380,7 +1380,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadFile(
|
||||
)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FILE * fp = NULL;
|
||||
FILE * fp = nullptr;
|
||||
#if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
|
||||
_wfopen_s(&fp, a_pwszFile, L"rb");
|
||||
#else // !__STDC_WANT_SECURE_LIB__
|
||||
@ -1418,7 +1418,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadFile(
|
||||
}
|
||||
|
||||
// allocate and ensure NULL terminated
|
||||
char * pData = new(std::nothrow) char[lSize+1];
|
||||
auto * pData = new(std::nothrow) char[lSize+1];
|
||||
if (!pData) {
|
||||
return SI_NOMEM;
|
||||
}
|
||||
@ -1474,8 +1474,8 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadData(
|
||||
return SI_NOMEM;
|
||||
}
|
||||
|
||||
size_t const convCnt = (size_t)WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)a_pData + 1, (int)(a_uDataLen / sizeof(WCHAR) - 1),
|
||||
(LPSTR)pDataUTF16toUTF8, (int)(a_uDataLen * 3 + 1), NULL, NULL);
|
||||
auto const convCnt = (size_t)WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)a_pData + 1, (int)(a_uDataLen / sizeof(WCHAR) - 1),
|
||||
(LPSTR)pDataUTF16toUTF8, (int)(a_uDataLen * 3 + 1), nullptr, nullptr);
|
||||
if (convCnt == 0) {
|
||||
delete[] pDataUTF16toUTF8;
|
||||
return SI_FAIL;
|
||||
@ -1504,7 +1504,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadData(
|
||||
|
||||
// allocate memory for the data, ensure that there is a NULL
|
||||
// terminator wherever the converted data ends
|
||||
SI_CHAR * pData = new(std::nothrow) SI_CHAR[uLen+1];
|
||||
auto * pData = new(std::nothrow) SI_CHAR[uLen+1];
|
||||
if (!pData) {
|
||||
delete[] pDataUTF16toUTF8;
|
||||
return SI_NOMEM;
|
||||
@ -1861,7 +1861,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadMultiLineText(
|
||||
|
||||
// move this line down to the location that it should be if necessary
|
||||
if (pDataLine < pCurrLine) {
|
||||
size_t nLen = (size_t) (a_pData - pCurrLine);
|
||||
auto nLen = (size_t) (a_pData - pCurrLine);
|
||||
memmove(pDataLine, pCurrLine, nLen * sizeof(SI_CHAR));
|
||||
pDataLine[nLen] = '\0';
|
||||
}
|
||||
@ -1933,7 +1933,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::CopyString(
|
||||
for ( ; a_pString[uLen]; ++uLen) /*loop*/ ;
|
||||
}
|
||||
++uLen; // NULL character
|
||||
SI_CHAR * pCopy = new(std::nothrow) SI_CHAR[uLen];
|
||||
auto * pCopy = new(std::nothrow) SI_CHAR[uLen];
|
||||
if (!pCopy) {
|
||||
return SI_NOMEM;
|
||||
}
|
||||
@ -1983,7 +1983,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::AddEntry(
|
||||
}
|
||||
|
||||
typename TSection::value_type oEntry(oSection, TKeyVal());
|
||||
typedef typename TSection::iterator SectionIterator;
|
||||
using SectionIterator = typename TSection::iterator;
|
||||
std::pair<SectionIterator,bool> i = m_data.insert(oEntry);
|
||||
iSection = i.first;
|
||||
bInserted = true;
|
||||
@ -2176,7 +2176,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetDoubleValue(
|
||||
return a_nDefault;
|
||||
}
|
||||
|
||||
char * pszSuffix = NULL;
|
||||
char * pszSuffix = nullptr;
|
||||
double nValue = strtod(szValue, &pszSuffix);
|
||||
|
||||
// any invalid strings will return the default value
|
||||
@ -2235,6 +2235,8 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetBoolValue(
|
||||
switch (pszValue[0]) {
|
||||
case 't': case 'T': // true
|
||||
case 'y': case 'Y': // yes
|
||||
case '9': case '8': case '7': case '6': // != 0
|
||||
case '5': case '4': case '3': case '2': // != 0
|
||||
case '1': // 1 (one)
|
||||
return true;
|
||||
|
||||
@ -2415,7 +2417,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::SaveFile(
|
||||
bool a_bAddSignature
|
||||
) const
|
||||
{
|
||||
FILE * fp = NULL;
|
||||
FILE * fp = nullptr;
|
||||
#if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
|
||||
fopen_s(&fp, a_pszFile, "wb");
|
||||
#else // !__STDC_WANT_SECURE_LIB__
|
||||
@ -2436,7 +2438,7 @@ CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::SaveFile(
|
||||
) const
|
||||
{
|
||||
#ifdef _WIN32
|
||||
FILE * fp = NULL;
|
||||
FILE * fp = nullptr;
|
||||
#if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
|
||||
_wfopen_s(&fp, a_pwszFile, L"wb");
|
||||
#else // !__STDC_WANT_SECURE_LIB__
|
||||
@ -3455,10 +3457,10 @@ public:
|
||||
// TYPE DEFINITIONS
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
typedef CSimpleIniTempl<char,
|
||||
SI_NoCase<char>,SI_ConvertA<char> > CSimpleIniA;
|
||||
typedef CSimpleIniTempl<char,
|
||||
SI_Case<char>,SI_ConvertA<char> > CSimpleIniCaseA;
|
||||
using CSimpleIniA = CSimpleIniTempl<char,
|
||||
SI_NoCase<char>,SI_ConvertA<char> >;
|
||||
using CSimpleIniCaseA = CSimpleIniTempl<char,
|
||||
SI_Case<char>,SI_ConvertA<char> >;
|
||||
|
||||
#if defined(SI_CONVERT_ICU)
|
||||
typedef CSimpleIniTempl<UChar,
|
||||
@ -3466,10 +3468,10 @@ typedef CSimpleIniTempl<UChar,
|
||||
typedef CSimpleIniTempl<UChar,
|
||||
SI_Case<UChar>,SI_ConvertW<UChar> > CSimpleIniCaseW;
|
||||
#else
|
||||
typedef CSimpleIniTempl<wchar_t,
|
||||
SI_NoCase<wchar_t>,SI_ConvertW<wchar_t> > CSimpleIniW;
|
||||
typedef CSimpleIniTempl<wchar_t,
|
||||
SI_Case<wchar_t>,SI_ConvertW<wchar_t> > CSimpleIniCaseW;
|
||||
using CSimpleIniW = CSimpleIniTempl<wchar_t,
|
||||
SI_NoCase<wchar_t>,SI_ConvertW<wchar_t> >;
|
||||
using CSimpleIniCaseW = CSimpleIniTempl<wchar_t,
|
||||
SI_Case<wchar_t>,SI_ConvertW<wchar_t> >;
|
||||
#endif
|
||||
|
||||
#ifdef _UNICODE
|
||||
|
||||
14
src/Edit.c
14
src/Edit.c
@ -7023,7 +7023,7 @@ void EditHideNotMarkedLineRange(HWND hwnd, bool bHideLines)
|
||||
//
|
||||
// _HighlightIfBrace()
|
||||
//
|
||||
static bool _HighlightIfBrace(HWND hwnd, DocPos iPos)
|
||||
static bool _HighlightIfBrace(const HWND hwnd, const DocPos iPos)
|
||||
{
|
||||
UNUSED(hwnd);
|
||||
if (iPos < 0) {
|
||||
@ -7033,15 +7033,15 @@ static bool _HighlightIfBrace(HWND hwnd, DocPos iPos)
|
||||
return true;
|
||||
}
|
||||
|
||||
char c = SciCall_GetCharAt(iPos);
|
||||
char const c = SciCall_GetCharAt(iPos);
|
||||
|
||||
if (StrChrA(NP3_BRACES_TO_MATCH, c)) {
|
||||
DocPos iBrace2 = SciCall_BraceMatch(iPos);
|
||||
if (iBrace2 != -1) {
|
||||
DocPos col1 = SciCall_GetColumn(iPos);
|
||||
DocPos col2 = SciCall_GetColumn(iBrace2);
|
||||
DocPos const iBrace2 = SciCall_BraceMatch(iPos);
|
||||
if (iBrace2 != (DocPos)-1) {
|
||||
int const col1 = (int)SciCall_GetColumn(iPos);
|
||||
int const col2 = (int)SciCall_GetColumn(iBrace2);
|
||||
SciCall_BraceHighLight(iPos, iBrace2);
|
||||
SciCall_SetHighLightGuide(min_i((int)col1, (int)col2));
|
||||
SciCall_SetHighLightGuide(min_i(col1, col2));
|
||||
}
|
||||
else {
|
||||
SciCall_BraceBadLight(iPos);
|
||||
|
||||
@ -688,21 +688,25 @@ static bool _InsertLanguageMenu(HMENU hMenuBar)
|
||||
if (s_hmenuLanguage) { DestroyMenu(s_hmenuLanguage); }
|
||||
s_hmenuLanguage = CreatePopupMenu();
|
||||
|
||||
WCHAR wchMenuItemFmt[128] = L"%s";
|
||||
WCHAR wchMenuItemFmt[128] = { L'\0' };
|
||||
WCHAR wchMenuItemStrg[196] = { L'\0' };
|
||||
for (int lng = 0; lng < MuiLanguages_CountOf(); ++lng)
|
||||
{
|
||||
if (MUI_LanguageDLLs[lng].bHasDLL)
|
||||
{
|
||||
// GetLngString(MUI_LanguageDLLs[lng].rid, wchMenuItemFmt, COUNTOF(wchMenuItemFmt));
|
||||
bool found = false;
|
||||
for (int i = 0; i < COUNTOF(s_LanguageMenu); ++i) {
|
||||
if (MUI_LanguageDLLs[lng].LangId == s_LanguageMenu[i].LangID)
|
||||
{
|
||||
StringCchCopy(wchMenuItemFmt, COUNTOF(wchMenuItemFmt), s_LanguageMenu[i].MenuItem);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
StringCchCopy(wchMenuItemFmt, COUNTOF(wchMenuItemFmt), L"Lang-(Sub)\t\t\t[%s]");
|
||||
}
|
||||
StringCchPrintfW(wchMenuItemStrg, COUNTOF(wchMenuItemStrg), wchMenuItemFmt, MUI_LanguageDLLs[lng].szLocaleName);
|
||||
AppendMenu(s_hmenuLanguage, MF_ENABLED | MF_STRING, MUI_LanguageDLLs[lng].rid, wchMenuItemStrg);
|
||||
}
|
||||
|
||||
@ -14,10 +14,10 @@ SCLEX_TOML, IDS_LEX_TOML_CFG, L"TOML Config", L"toml", L"",
|
||||
{ {STYLE_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"", L"" },
|
||||
//{ {SCE_TOML_DEFAULT}, IDS_LEX_STR_63126, L"Default", L"", L"" },
|
||||
{ {SCE_TOML_COMMENT}, IDS_LEX_STR_63127, L"Comment", L"fore:#008000", L"" },
|
||||
{ {SCE_TOML_KEY}, IDS_LEX_STR_63128, L"Key", L"bold; fore:#5E8F60", L"" },
|
||||
{ {SCE_TOML_SECTION}, IDS_LEX_STR_63232, L"Section", L"bold; fore:#000000; back:#FF8040; eolfilled", L"" },
|
||||
{ {SCE_TOML_ASSIGNMENT}, IDS_LEX_STR_63233, L"Assignment", L"fore:#FFA500", L"" },
|
||||
{ {SCE_TOML_DEFVAL}, IDS_LEX_STR_63234, L"Default Value", L"fore:#00FF00", L"" },
|
||||
{ {SCE_TOML_DATATYPE}, IDS_LEX_STR_63234, L"Datatype", L"fore:#0000FF", L"" },
|
||||
{ {SCE_TOML_TYPEERROR}, IDS_LEX_STR_63234, L"Type Error", L"fore:#FF0000", L"" },
|
||||
{ {SCE_TOML_SECTION}, IDS_LEX_STR_63232, L"Section", L"bold; fore:#000000; back:#FFF1A8; eolfilled", L"" },
|
||||
{ {SCE_TOML_KEY}, IDS_LEX_STR_63348, L"Key", L"bold; fore:#5E608F", L"" },
|
||||
{ {SCE_TOML_ASSIGNMENT}, IDS_LEX_STR_63233, L"Assignment", L"bold; fore:#FF2020", L"" },
|
||||
{ {SCE_TOML_VALUE}, IDS_LEX_STR_63201, L"Value", L"fore:#202020", L"" },
|
||||
{ {SCE_TOML_STRING}, IDS_LEX_STR_63131, L"String", L"italic; fore:#800000", L"" },
|
||||
{ {SCE_TOML_PARSINGERROR}, IDS_LEX_STR_63252, L"Parsing Error", L"fore:#FFFF00; back:#A00000", L"" },
|
||||
EDITLEXER_SENTINEL } };
|
||||
|
||||
Loading…
Reference in New Issue
Block a user