-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugin now compatible with Npp older than 8.4.1
FIXED 1. Fixed bug in [Main](/JsonToolsNppPlugin/Main.cs#L360) (based on failure to read [SCI_GETTEXT documentation](https://www.scintilla.org/ScintillaDoc.html#SCI_GETTEXT)) that caused this plugin to be incompatible with versions of Notepad++ older than 8.4.1. ADDED 1. DSON emitter and UDL takes this plugin to the moon!
- Loading branch information
1 parent
a28eeeb
commit e2ffde3
Showing
14 changed files
with
325 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<NotepadPlus> | ||
<UserLang name="DSON" ext="dson" udlVersion="2.1"> | ||
<Settings> | ||
<Global caseIgnored="no" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" /> | ||
<Prefix Keywords1="yes" Keywords2="yes" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" /> | ||
</Settings> | ||
<KeywordLists> | ||
<Keywords name="Comments">00 01 02 03 04</Keywords> | ||
<Keywords name="Numbers, prefix1">+ -</Keywords> | ||
<Keywords name="Numbers, prefix2"></Keywords> | ||
<Keywords name="Numbers, extras1"></Keywords> | ||
<Keywords name="Numbers, extras2"></Keywords> | ||
<Keywords name="Numbers, suffix1"></Keywords> | ||
<Keywords name="Numbers, suffix2"></Keywords> | ||
<Keywords name="Numbers, range">VERY very</Keywords> | ||
<Keywords name="Operators1">, ? . !</Keywords> | ||
<Keywords name="Operators2"></Keywords> | ||
<Keywords name="Folders in code1, open"></Keywords> | ||
<Keywords name="Folders in code1, middle"></Keywords> | ||
<Keywords name="Folders in code1, close"></Keywords> | ||
<Keywords name="Folders in code2, open"></Keywords> | ||
<Keywords name="Folders in code2, middle"></Keywords> | ||
<Keywords name="Folders in code2, close"></Keywords> | ||
<Keywords name="Folders in comment, open"></Keywords> | ||
<Keywords name="Folders in comment, middle"></Keywords> | ||
<Keywords name="Folders in comment, close"></Keywords> | ||
<Keywords name="Keywords1">so and also many</Keywords> | ||
<Keywords name="Keywords2">such is wow</Keywords> | ||
<Keywords name="Keywords3">yes no</Keywords> | ||
<Keywords name="Keywords4">empty</Keywords> | ||
<Keywords name="Keywords5"></Keywords> | ||
<Keywords name="Keywords6"></Keywords> | ||
<Keywords name="Keywords7"></Keywords> | ||
<Keywords name="Keywords8"></Keywords> | ||
<Keywords name="Delimiters">00" 01\ 02" 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords> | ||
</KeywordLists> | ||
<Styles> | ||
<WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="LINE COMMENTS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="NUMBERS" fgColor="FF3737" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="KEYWORDS1" fgColor="00FF80" bgColor="FFFFFF" fontStyle="1" nesting="0" /> | ||
<WordsStyle name="KEYWORDS2" fgColor="FF00FF" bgColor="FFFFFF" fontStyle="1" nesting="0" /> | ||
<WordsStyle name="KEYWORDS3" fgColor="0000FF" bgColor="FFFFFF" fontStyle="1" nesting="0" /> | ||
<WordsStyle name="KEYWORDS4" fgColor="000000" bgColor="FFFFFF" fontStyle="1" nesting="0" /> | ||
<WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="OPERATORS" fgColor="008080" bgColor="FFFFFF" fontStyle="2" nesting="0" /> | ||
<WordsStyle name="FOLDER IN CODE1" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="DELIMITERS1" fgColor="808000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" /> | ||
</Styles> | ||
</UserLang> | ||
</NotepadPlus> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Text; | ||
|
||
namespace JSON_Tools.JSON_Tools | ||
{ | ||
class DsonDumpException : Exception | ||
{ | ||
public new string Message; | ||
|
||
public DsonDumpException(string message) | ||
{ | ||
Message = message; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// wow such data very readable<br></br> | ||
/// such docs at https://dogeon.xyz/ plz read | ||
/// </summary> | ||
class Dson | ||
{ | ||
public static string KeyValuePairDelims = ",.!?"; | ||
|
||
public static string[] ArrayPairDelims = new string[] { "and", "also" }; | ||
|
||
private static string FormatInteger(long val) | ||
{ | ||
if (val == long.MinValue) | ||
// converting to octal turns signed numbers into unsigned numbers | ||
// this can be reversed for every negative number except long.MinValue | ||
return "1000000000000000000000"; | ||
if (val < 0) | ||
return "-" + Convert.ToString(-val, 8); | ||
return Convert.ToString(val, 8); | ||
} | ||
|
||
/// <summary> | ||
/// plz stringify json as DSON<br></br> | ||
/// wow so amaze | ||
/// </summary> | ||
public static string Dump(JNode json) | ||
{ | ||
StringBuilder sb; | ||
switch (json.type) | ||
{ | ||
case Dtype.ARR: | ||
sb = new StringBuilder(); | ||
sb.Append("so "); | ||
JArray arr = (JArray)json; | ||
bool useAndDelim = true; | ||
for (int ii = 0; ii < arr.Length; ii++) | ||
{ | ||
sb.Append(Dump(arr[ii])); | ||
sb.Append(useAndDelim ? " and " : " also "); | ||
useAndDelim = !useAndDelim; | ||
} | ||
if (arr.Length > 0) | ||
{ | ||
// trim off the last delimiter if the array had items | ||
int lengthToRemove = useAndDelim ? 5 : 4; | ||
sb.Remove(sb.Length - lengthToRemove - 1, lengthToRemove); | ||
} | ||
sb.Append("many"); | ||
return sb.ToString(); | ||
case Dtype.OBJ: | ||
// {"a": 13.51e25, "b": true} becomes | ||
// such "a" is 15.63very31, "b" is yes wow | ||
sb = new StringBuilder(); | ||
sb.Append("such "); | ||
int delimIdx = 0; | ||
JObject obj = (JObject)json; | ||
foreach (string key in obj.children.Keys) | ||
{ | ||
JNode value = obj[key]; | ||
sb.Append($"\"{key}\" is "); | ||
sb.Append(Dump(value)); | ||
sb.Append(KeyValuePairDelims[delimIdx % 4] + " "); | ||
delimIdx++; | ||
} | ||
if (obj.Length > 0) | ||
sb.Remove(sb.Length - 2, 1); // remove the last delimter if there were items | ||
sb.Append("wow"); | ||
return sb.ToString(); | ||
case Dtype.BOOL: | ||
return (bool)json.value ? "yes" : "no"; | ||
case Dtype.NULL: | ||
return "empty"; | ||
case Dtype.INT: | ||
return FormatInteger((long)json.value); | ||
case Dtype.FLOAT: | ||
// floating point numbers are formatted | ||
// such that fractional part, exponent, and integer part are all octal | ||
string valstr = ((double)json.value).ToString(); | ||
if (valstr.EndsWith("y") || valstr.EndsWith("N")) | ||
// Infinity and NaN are not in the DSON specification | ||
throw new DsonDumpException($"{valstr} is fake number, can't understand. So silly, wow"); | ||
StringBuilder partSb = new StringBuilder(); | ||
sb = new StringBuilder(); | ||
long part; | ||
foreach (char c in valstr) | ||
{ | ||
if ('0' <= c && c <= '9' || c == '+' || c == '-') | ||
{ | ||
partSb.Append(c); | ||
} | ||
else | ||
{ | ||
part = Convert.ToInt64(partSb.ToString()); | ||
partSb = new StringBuilder(); | ||
sb.Append(FormatInteger(part)); | ||
if (c == '.') | ||
sb.Append("."); | ||
else if (c == 'e') | ||
sb.Append("very"); | ||
else if (c == 'E') | ||
sb.Append("VERY"); | ||
} | ||
} | ||
part = Convert.ToInt64(partSb.ToString()); | ||
sb.Append(FormatInteger(part)); | ||
return sb.ToString(); | ||
case Dtype.STR: | ||
return json.ToString(); | ||
default: throw new NotSupportedException(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.