JSON Editing

Mar 23, 2013 at 5:52 PM
What can ScintillaNet do for JSON editing? I notice that it doesn't have a lexer associated with it but having limited understanding of lexers, I might guess because json doesn't actually have any keywords, that it has very little to parse.
Mar 23, 2013 at 8:14 PM
The cpp lexer should work fine. It may be a little liberal for Json's strict syntax.
Mar 23, 2013 at 8:46 PM
Basically, I'm modifying FlashDevelop that uses Scintilla (Which presumably is commonly known). My goal is to make sure that the syntax highlighting identifies invalid JSON. Like where braces aren't balanced and there are missing or too many commas. Is this something that Scintilla addresses? I'm still figuring out the scope of scintilla.
Mar 23, 2013 at 10:20 PM
Out of the box Scintilla and ScintillaNET support lexers--not parsers. A lexer is capable of identifying tokens like keywords or operator and is suitable for syntax highlighting. A parser on the other hand is capable of using the tokens identified by the lexer and can determine whether they constitute a valid syntax and is able to identifying missing braces or commas, to use your example. That type of capability is not available out of the box and you would need to incorporate that yourself.

To get syntax highlighting of JSON I would actually recommend the JavaScript lexer instead of the C++ lexer since JSON is a subset of JavaScript. In ScintillaNET you would enable it like this:
Scintilla.ConfigurationManager.Language = "js";
Mar 23, 2013 at 11:06 PM
FlashDevelop uses a different .Net wrapper than ScintillaNet but this is all a function of Scintilla. Jacob is correct, the lexer won't be much help to you. But there are plenty of Json parser/validators you should be able to leverage. It depends on how big the document is and if you want live instant reparsing when the user edits.
Mar 24, 2013 at 12:56 AM
Thanks for confirming that for me. I was beginning to suspect.
Mar 24, 2013 at 1:23 AM
Actually, would it be a reasonable expectation for Scintilla to provide a means of highlight sections specified to contain errors? I don't mean detect those errors but provide the means of highlighting those errors.
Mar 24, 2013 at 3:34 PM
Yes, scintilla does provide those means via a combination of indicators, hotspot styles, and calltips, although in the trunk version of ScintillaNET indicators aren't very easy to access. I do however access them to provide some errors, but those are all lexer errors, and I only use indicators currently. (strings hitting the end of the line without closing, invalid escape sequences in strings etc.) I think however, that FlashDevelop has it's own system internally to keep track of those errors and display them without you having to go directly to the underlying Scintilla control.