|
From: <dal...@us...> - 2014-12-20 18:07:14
|
Revision: 23797
http://sourceforge.net/p/jedit/svn/23797
Author: daleanson
Date: 2014-12-20 18:07:04 +0000 (Sat, 20 Dec 2014)
Log Message:
-----------
Added initial version of JSON sidekick.
Modified Paths:
--------------
plugins/XML/trunk/XML.props
plugins/XML/trunk/build.xml
plugins/XML/trunk/docs/CHANGES.txt
plugins/XML/trunk/docs/users-guide.xml
plugins/XML/trunk/services.xml
Added Paths:
-----------
plugins/XML/trunk/sidekick/json/
plugins/XML/trunk/sidekick/json/JsonParser.java
plugins/XML/trunk/sidekick/json/JsonSideKickParsedData.java
plugins/XML/trunk/sidekick/json/parser/
plugins/XML/trunk/sidekick/json/parser/JSON.g4
plugins/XML/trunk/sidekick/json/parser/JSON.tokens
plugins/XML/trunk/sidekick/json/parser/JSONBaseListener.java
plugins/XML/trunk/sidekick/json/parser/JSONLexer.java
plugins/XML/trunk/sidekick/json/parser/JSONLexer.tokens
plugins/XML/trunk/sidekick/json/parser/JSONListener.java
plugins/XML/trunk/sidekick/json/parser/JSONNode.java
plugins/XML/trunk/sidekick/json/parser/JSONParser.java
plugins/XML/trunk/sidekick/json/parser/JSONSideKickListener.java
plugins/XML/trunk/sidekick/json/parser/ParseException.java
plugins/XML/trunk/sidekick/json/parser/SideKickErrorListener.java
plugins/XML/trunk/sidekick/json/parser/SideKickPosition.java
plugins/XML/trunk/sidekick/json/test.json
Modified: plugins/XML/trunk/XML.props
===================================================================
--- plugins/XML/trunk/XML.props 2014-12-20 16:50:39 UTC (rev 23796)
+++ plugins/XML/trunk/XML.props 2014-12-20 18:07:04 UTC (rev 23797)
@@ -3,10 +3,10 @@
plugin.xml.XmlPlugin.activate=defer
plugin.xml.XmlPlugin.name=XML
plugin.xml.XmlPlugin.author=Slava Pestov, Dale Anson, Alan Ezust, Rob McKinnon, Martin Raspe, Jakub Roztocil, Eric Le Lay
-plugin.xml.XmlPlugin.version=2.8.8
+plugin.xml.XmlPlugin.version=2.9.0
plugin.xml.XmlPlugin.docs=index.html
-plugin.xml.XmlPlugin.depend.0=jdk 1.6
+plugin.xml.XmlPlugin.depend.0=jdk 1.7
plugin.xml.XmlPlugin.depend.1=jedit 05.00.01.00
plugin.xml.XmlPlugin.depend.2=plugin xerces.XercesPlugin 2.9.1
plugin.xml.XmlPlugin.depend.3=plugin errorlist.ErrorListPlugin 1.9
@@ -16,6 +16,7 @@
plugin.xml.XmlPlugin.depend.7=plugin eclipseicons.EclipseIconsPlugin 1.0
plugin.xml.XmlPlugin.depend.8=optional plugin gatchan.jedit.hyperlinks.HyperlinksPlugin 1.1.0
plugin.xml.XmlPlugin.depend.9=optional plugin templates.TemplatesPlugin 4.1.2
+plugin.xml.XmlPlugin.depend.10=plugin antlr.AntlrPlugin 4.4
plugin.xml.XmlPlugin.jars=jing.jar relaxngDatatype.jar trang.jar
@@ -147,6 +148,8 @@
mode.maven.sidekick.parser=xml
mode.css.sidekick.parser=css
mode.jedit-actions.sidekick.parser=xml
+sidekick.parser.json.label=json
+mode.json.sidekick.parser=json
# specialized tag classes. Mostly, these provide a different icon set for the
# nodes of these file modes.The naming convention is xml.xmltag.modename, where
Modified: plugins/XML/trunk/build.xml
===================================================================
--- plugins/XML/trunk/build.xml 2014-12-20 16:50:39 UTC (rev 23796)
+++ plugins/XML/trunk/build.xml 2014-12-20 18:07:04 UTC (rev 23797)
@@ -101,6 +101,8 @@
<pathelement location="${jedit.plugins.dir}/EclipseIcons.jar"/>
<pathelement location="${jedit.plugins.dir}/Hyperlinks.jar"/>
<pathelement location="${jedit.plugins.dir}/Templates.jar"/>
+ <pathelement location="${jedit.plugins.dir}/velocity-1.5.jar"/>
+ <pathelement location="${jedit.plugins.dir}/antlr-4.4-complete.jar"/>
<pathelement location="."/>
</path>
Modified: plugins/XML/trunk/docs/CHANGES.txt
===================================================================
--- plugins/XML/trunk/docs/CHANGES.txt 2014-12-20 16:50:39 UTC (rev 23796)
+++ plugins/XML/trunk/docs/CHANGES.txt 2014-12-20 18:07:04 UTC (rev 23797)
@@ -1,6 +1,11 @@
:encoding=UTF-8:maxLineLen=80:wrap=hard:folding=indent:noTabs=true:tabSize=4:
XML Plugin Change log
+ Version 2.9.0 jEdit 5.0, Java 1.6, XercesPlugin 2.9.1, ErrorList 1.9,
+ SideKick 1.3, BeautyPlugin 0.7.0, CommonControls 1.5, EclipseIcons 1.0,
+ Hyperlinks 1.1.0 (Optional), Templates 4.1.2 (Optional), AntlrPlugin 4.4
+ Added new sidekick for json files.
+
Version 2.8.8 Requires jEdit 5.0, Java 1.6, XercesPlugin 2.9.1, ErrorList 1.9, SideKick 1.3, BeautyPlugin 0.7.0, CommonControls 1.5, EclipseIcons 1.0, Hyperlinks 1.1.0 (Optional), and Templates 4.1.2 (Optional)
plugin patch #147: Convert ascii entities (Character References) into
chars in Entities to Characters action (Jarek Czekalski)
Modified: plugins/XML/trunk/docs/users-guide.xml
===================================================================
--- plugins/XML/trunk/docs/users-guide.xml 2014-12-20 16:50:39 UTC (rev 23796)
+++ plugins/XML/trunk/docs/users-guide.xml 2014-12-20 18:07:04 UTC (rev 23797)
@@ -44,12 +44,12 @@
</para>
<para> The XML plugin makes jEdit one of the most advanced free Website editing tools available.
- It combines parsers for XML, HTML, JSP, Sidekick, and CSS files. Here are its features: </para>
+ It combines parsers for XML, HTML, JSP, JSON, Sidekick, and CSS files. Here are its features: </para>
<itemizedlist>
<listitem><para>On-the-fly validation of XML files with DTD, XSD, or RNG schemas. </para></listitem>
<listitem><para>Tag, attribute, and entity completion popups for XML, HTML and CSS</para></listitem>
- <listitem><para>Display of the element tree in a dockable window, for XML, HTML, JavaScript, JSP, and CSS</para></listitem>
+ <listitem><para>Display of the element tree in a dockable window, for XML, HTML, JavaScript, JSP, JSON, and CSS</para></listitem>
<listitem><para>Matching tag highlighting</para></listitem>
<listitem><para>One click insertion of tags and entities</para></listitem>
<listitem><para>Graphical form to edit tags and attributes</para></listitem>
Modified: plugins/XML/trunk/services.xml
===================================================================
--- plugins/XML/trunk/services.xml 2014-12-20 16:50:39 UTC (rev 23796)
+++ plugins/XML/trunk/services.xml 2014-12-20 18:07:04 UTC (rev 23797)
@@ -19,6 +19,9 @@
<SERVICE CLASS="sidekick.SideKickParser" NAME="ecmascript">
new sidekick.ecmascript.EcmaScriptSideKickParser();
</SERVICE>
+ <SERVICE CLASS="sidekick.SideKickParser" NAME="json">
+ new sidekick.json.JsonParser();
+ </SERVICE>
<SERVICE CLASS="beauty.beautifiers.Beautifier" NAME="xml:XmlIndenter">
new xml.indent.XmlBeautifier();
</SERVICE>
Added: plugins/XML/trunk/sidekick/json/JsonParser.java
===================================================================
--- plugins/XML/trunk/sidekick/json/JsonParser.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/JsonParser.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,149 @@
+/*
+Copyright (c) 2014, Dale Anson
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+* Neither the name of the <ORGANIZATION> nor the names of its contributors
+may be used to endorse or promote products derived from this software without
+specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+package sidekick.json;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.*;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import org.gjt.sp.jedit.Buffer;
+import org.gjt.sp.jedit.View;
+
+import sidekick.json.parser.*;
+
+import org.antlr.v4.runtime.*;
+import org.antlr.v4.runtime.tree.*;
+
+import sidekick.SideKickParsedData;
+import sidekick.SideKickParser;
+import sidekick.util.*;
+
+import errorlist.DefaultErrorSource;
+import errorlist.ErrorSource;
+
+public class JsonParser extends SideKickParser {
+
+ private static final String NAME = "json";
+ private View currentView = null;
+ public static boolean showAll = false;
+
+ public JsonParser() {
+ super( NAME );
+ }
+
+ /**
+ * Parse the current buffer in the current view.
+ * TODO: is this used anymore?
+ */
+ public void parse() {
+ if ( currentView != null ) {
+ parse( currentView.getBuffer(), null );
+ }
+ }
+
+ /**
+ * Parse the contents of the given buffer.
+ * @param buffer the buffer to parse
+ * @param errorSource where to send any error messages
+ * @return data for the tree
+ */
+ public SideKickParsedData parse( Buffer buffer, DefaultErrorSource errorSource ) {
+ Reader input = null;
+ String filename = buffer.getPath();
+ SideKickParsedData parsedData = new JsonSideKickParsedData( filename );
+ DefaultMutableTreeNode root = parsedData.root;
+ SideKickErrorListener errorListener = null;
+ try {
+ if ( buffer.getLength() <= 0 ) {
+ return parsedData;
+ }
+ // set up the parser to read the buffer
+ String contents = buffer.getText( 0, buffer.getLength() );
+ input = new StringReader( contents );
+ ANTLRInputStream antlrInput = new ANTLRInputStream( input );
+ JSONLexer lexer = new JSONLexer( antlrInput );
+ CommonTokenStream tokens = new CommonTokenStream( lexer );
+ JSONParser jsonParser = new JSONParser( tokens );
+
+ // add an error listener to the parser to capture any errors
+ jsonParser.removeErrorListeners();
+ errorListener = new SideKickErrorListener();
+ jsonParser.addErrorListener( errorListener );
+
+ // parse the buffer contents
+ ParseTree tree = jsonParser.json();
+ ParseTreeWalker walker = new ParseTreeWalker();
+ JSONSideKickListener listener = new JSONSideKickListener();
+ walker.walk( listener, tree );
+
+ // build the tree
+ JSONNode parserRoot = listener.getRoot();
+ parserRoot.setStartPosition(ElementUtil.createStartPosition(buffer, parserRoot));
+ parserRoot.setEndPosition(ElementUtil.createEndPosition(buffer, parserRoot));
+ DefaultMutableTreeNode jsonNode = new DefaultMutableTreeNode(parserRoot);
+ root.add( jsonNode );
+ addChildren(jsonNode, buffer);
+ } catch ( Exception e ) {
+ e.printStackTrace();
+ } finally {
+ handleErrors( buffer, errorSource, errorListener.getErrors() );
+ }
+ return parsedData;
+ }
+
+ private void addChildren( DefaultMutableTreeNode node, Buffer buffer ) {
+ JSONNode parent = ( JSONNode ) node.getUserObject();
+ Collection<JSONNode> children = parent.getChildren();
+ if ( children != null && children.size() > 0 ) {
+ // add the children as tree nodes
+ for ( JSONNode child : children ) {
+ child.setStartPosition( ElementUtil.createStartPosition( buffer, child ) );
+ child.setEndPosition( ElementUtil.createEndPosition( buffer, child ) );
+
+ // create a tree node for the child and recursively add the childs children
+ DefaultMutableTreeNode childNode = new DefaultMutableTreeNode( child );
+ node.add( childNode );
+ addChildren( childNode, buffer );
+ }
+ }
+ }
+
+ /* the parser accumulates errors as it parses. This method passed them all
+ to the ErrorList plugin. */
+ private void handleErrors( Buffer buffer, DefaultErrorSource errorSource, List<ParseException> errors ) {
+ if ( errors == null || errors.isEmpty() ) {
+ return;
+ }
+ for ( ParseException pe : errors ) {
+ errorSource.addError( ErrorSource.ERROR, buffer.getPath(), pe.getLineNumber(), pe.getColumn(), pe.getColumn() + pe.getLength(), pe.getMessage() );
+ }
+ }
+
+}
Added: plugins/XML/trunk/sidekick/json/JsonSideKickParsedData.java
===================================================================
--- plugins/XML/trunk/sidekick/json/JsonSideKickParsedData.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/JsonSideKickParsedData.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,18 @@
+
+package sidekick.json;
+
+// Imports
+import sidekick.SideKickParsedData;
+
+/**
+ * Stores a buffer structure tree.
+ */
+public class JsonSideKickParsedData extends SideKickParsedData {
+ /**
+ * @param fileName The file name being parsed, used as the root of the
+ * tree.
+ */
+ public JsonSideKickParsedData( String fileName ) {
+ super( fileName );
+ }
+}
Added: plugins/XML/trunk/sidekick/json/parser/JSON.g4
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/JSON.g4 (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/JSON.g4 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,61 @@
+/** Taken from "The Definitive ANTLR 4 Reference" by Terence Parr */
+
+// Derived from http://json.org
+
+// To regenerate the antlr files (lexer, parser, tokens, etc) run the
+// AntlrSideKickPlugin and use the "Generate files" action with this file being
+// the active file in the view.
+
+grammar JSON;
+
+@header {
+ package sidekick.json.parser;
+}
+
+json: object
+ | array
+ ;
+
+object
+ : LBRACE pair (',' pair)* RBRACE
+ | LBRACE RBRACE // empty object
+ ;
+
+pair: STRING ':' value ;
+
+array
+ : LSQUARE value (',' value)* RSQUARE
+ | LSQUARE RSQUARE // empty array
+ ;
+
+value
+ : STRING
+ | NUMBER
+ | object // recursion
+ | array // recursion
+ ;
+
+STRING : '"' (ESC | ~["\\])* '"' ;
+
+fragment ESC : '\\' (["\\/bfnrt] | UNICODE) ;
+fragment UNICODE : 'u' HEX HEX HEX HEX ;
+fragment HEX : [0-9a-fA-F] ;
+
+NUMBER
+ : '-'? INT '.' [0-9]+ EXP? // 1.35, 1.35E-9, 0.3, -4.5
+ | '-'? INT EXP // 1e10 -3e4
+ | '-'? INT // -3, 45
+ | 'true'
+ | 'false'
+ | 'null'
+ ;
+
+fragment INT : '0' | [1-9] [0-9]* ; // no leading zeros
+fragment EXP : [Ee] [+\-]? INT ; // \- since - means "range" inside [...]
+
+WS : [ \t\n\r]+ -> skip ;
+
+LBRACE : '{' ;
+RBRACE : '}' ;
+LSQUARE : '[' ;
+RSQUARE : ']' ;
Added: plugins/XML/trunk/sidekick/json/parser/JSON.tokens
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/JSON.tokens (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/JSON.tokens 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,15 @@
+WS=5
+LSQUARE=8
+RBRACE=7
+RSQUARE=9
+T__1=1
+T__0=2
+LBRACE=6
+STRING=3
+NUMBER=4
+'}'=7
+':'=2
+'['=8
+','=1
+'{'=6
+']'=9
Added: plugins/XML/trunk/sidekick/json/parser/JSONBaseListener.java
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/JSONBaseListener.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/JSONBaseListener.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,102 @@
+// Generated from /home/danson/src/jedit/plugins/XML/sidekick/json/parser/JSON.g4 by ANTLR 4.4
+
+ package sidekick.json.parser;
+
+
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.misc.NotNull;
+import org.antlr.v4.runtime.tree.ErrorNode;
+import org.antlr.v4.runtime.tree.TerminalNode;
+
+/**
+ * This class provides an empty implementation of {@link JSONListener},
+ * which can be extended to create a listener which only needs to handle a subset
+ * of the available methods.
+ */
+public class JSONBaseListener implements JSONListener {
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void enterPair(@NotNull JSONParser.PairContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void exitPair(@NotNull JSONParser.PairContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void enterJson(@NotNull JSONParser.JsonContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void exitJson(@NotNull JSONParser.JsonContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void enterValue(@NotNull JSONParser.ValueContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void exitValue(@NotNull JSONParser.ValueContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void enterObject(@NotNull JSONParser.ObjectContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void exitObject(@NotNull JSONParser.ObjectContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void enterArray(@NotNull JSONParser.ArrayContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void exitArray(@NotNull JSONParser.ArrayContext ctx) { }
+
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void enterEveryRule(@NotNull ParserRuleContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void exitEveryRule(@NotNull ParserRuleContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void visitTerminal(@NotNull TerminalNode node) { }
+ /**
+ * {@inheritDoc}
+ *
+ * <p>The default implementation does nothing.</p>
+ */
+ @Override public void visitErrorNode(@NotNull ErrorNode node) { }
+}
\ No newline at end of file
Added: plugins/XML/trunk/sidekick/json/parser/JSONLexer.java
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/JSONLexer.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/JSONLexer.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,103 @@
+// Generated from /home/danson/src/jedit/plugins/XML/sidekick/json/parser/JSON.g4 by ANTLR 4.4
+
+ package sidekick.json.parser;
+
+import org.antlr.v4.runtime.Lexer;
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.Token;
+import org.antlr.v4.runtime.TokenStream;
+import org.antlr.v4.runtime.*;
+import org.antlr.v4.runtime.atn.*;
+import org.antlr.v4.runtime.dfa.DFA;
+import org.antlr.v4.runtime.misc.*;
+
+@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
+public class JSONLexer extends Lexer {
+ static { RuntimeMetaData.checkVersion("4.4", RuntimeMetaData.VERSION); }
+
+ protected static final DFA[] _decisionToDFA;
+ protected static final PredictionContextCache _sharedContextCache =
+ new PredictionContextCache();
+ public static final int
+ T__1=1, T__0=2, STRING=3, NUMBER=4, WS=5, LBRACE=6, RBRACE=7, LSQUARE=8,
+ RSQUARE=9;
+ public static String[] modeNames = {
+ "DEFAULT_MODE"
+ };
+
+ public static final String[] tokenNames = {
+ "'\\u0000'", "'\\u0001'", "'\\u0002'", "'\\u0003'", "'\\u0004'", "'\\u0005'",
+ "'\\u0006'", "'\\u0007'", "'\b'", "'\t'"
+ };
+ public static final String[] ruleNames = {
+ "T__1", "T__0", "STRING", "ESC", "UNICODE", "HEX", "NUMBER", "INT", "EXP",
+ "WS", "LBRACE", "RBRACE", "LSQUARE", "RSQUARE"
+ };
+
+
+ public JSONLexer(CharStream input) {
+ super(input);
+ _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
+ }
+
+ @Override
+ public String getGrammarFileName() { return "JSON.g4"; }
+
+ @Override
+ public String[] getTokenNames() { return tokenNames; }
+
+ @Override
+ public String[] getRuleNames() { return ruleNames; }
+
+ @Override
+ public String getSerializedATN() { return _serializedATN; }
+
+ @Override
+ public String[] getModeNames() { return modeNames; }
+
+ @Override
+ public ATN getATN() { return _ATN; }
+
+ public static final String _serializedATN =
+ "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\2\13\177\b\1\4\2\t"+
+ "\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+
+ "\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\3\2\3\2\3\3\3\3\3\4\3\4\3\4"+
+ "\7\4\'\n\4\f\4\16\4*\13\4\3\4\3\4\3\5\3\5\3\5\5\5\61\n\5\3\6\3\6\3\6\3"+
+ "\6\3\6\3\6\3\7\3\7\3\b\5\b<\n\b\3\b\3\b\3\b\6\bA\n\b\r\b\16\bB\3\b\5\b"+
+ "F\n\b\3\b\5\bI\n\b\3\b\3\b\3\b\3\b\5\bO\n\b\3\b\3\b\3\b\3\b\3\b\3\b\3"+
+ "\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\5\b_\n\b\3\t\3\t\3\t\7\td\n\t\f\t\16\t"+
+ "g\13\t\5\ti\n\t\3\n\3\n\5\nm\n\n\3\n\3\n\3\13\6\13r\n\13\r\13\16\13s\3"+
+ "\13\3\13\3\f\3\f\3\r\3\r\3\16\3\16\3\17\3\17\2\2\20\3\3\5\4\7\5\t\2\13"+
+ "\2\r\2\17\6\21\2\23\2\25\7\27\b\31\t\33\n\35\13\3\2\n\4\2$$^^\n\2$$\61"+
+ "\61^^ddhhppttvv\5\2\62;CHch\3\2\62;\3\2\63;\4\2GGgg\4\2--//\5\2\13\f\17"+
+ "\17\"\"\u008a\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\17\3\2\2\2\2\25\3"+
+ "\2\2\2\2\27\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2\3\37\3\2\2"+
+ "\2\5!\3\2\2\2\7#\3\2\2\2\t-\3\2\2\2\13\62\3\2\2\2\r8\3\2\2\2\17^\3\2\2"+
+ "\2\21h\3\2\2\2\23j\3\2\2\2\25q\3\2\2\2\27w\3\2\2\2\31y\3\2\2\2\33{\3\2"+
+ "\2\2\35}\3\2\2\2\37 \7.\2\2 \4\3\2\2\2!\"\7<\2\2\"\6\3\2\2\2#(\7$\2\2"+
+ "$\'\5\t\5\2%\'\n\2\2\2&$\3\2\2\2&%\3\2\2\2\'*\3\2\2\2(&\3\2\2\2()\3\2"+
+ "\2\2)+\3\2\2\2*(\3\2\2\2+,\7$\2\2,\b\3\2\2\2-\60\7^\2\2.\61\t\3\2\2/\61"+
+ "\5\13\6\2\60.\3\2\2\2\60/\3\2\2\2\61\n\3\2\2\2\62\63\7w\2\2\63\64\5\r"+
+ "\7\2\64\65\5\r\7\2\65\66\5\r\7\2\66\67\5\r\7\2\67\f\3\2\2\289\t\4\2\2"+
+ "9\16\3\2\2\2:<\7/\2\2;:\3\2\2\2;<\3\2\2\2<=\3\2\2\2=>\5\21\t\2>@\7\60"+
+ "\2\2?A\t\5\2\2@?\3\2\2\2AB\3\2\2\2B@\3\2\2\2BC\3\2\2\2CE\3\2\2\2DF\5\23"+
+ "\n\2ED\3\2\2\2EF\3\2\2\2F_\3\2\2\2GI\7/\2\2HG\3\2\2\2HI\3\2\2\2IJ\3\2"+
+ "\2\2JK\5\21\t\2KL\5\23\n\2L_\3\2\2\2MO\7/\2\2NM\3\2\2\2NO\3\2\2\2OP\3"+
+ "\2\2\2P_\5\21\t\2QR\7v\2\2RS\7t\2\2ST\7w\2\2T_\7g\2\2UV\7h\2\2VW\7c\2"+
+ "\2WX\7n\2\2XY\7u\2\2Y_\7g\2\2Z[\7p\2\2[\\\7w\2\2\\]\7n\2\2]_\7n\2\2^;"+
+ "\3\2\2\2^H\3\2\2\2^N\3\2\2\2^Q\3\2\2\2^U\3\2\2\2^Z\3\2\2\2_\20\3\2\2\2"+
+ "`i\7\62\2\2ae\t\6\2\2bd\t\5\2\2cb\3\2\2\2dg\3\2\2\2ec\3\2\2\2ef\3\2\2"+
+ "\2fi\3\2\2\2ge\3\2\2\2h`\3\2\2\2ha\3\2\2\2i\22\3\2\2\2jl\t\7\2\2km\t\b"+
+ "\2\2lk\3\2\2\2lm\3\2\2\2mn\3\2\2\2no\5\21\t\2o\24\3\2\2\2pr\t\t\2\2qp"+
+ "\3\2\2\2rs\3\2\2\2sq\3\2\2\2st\3\2\2\2tu\3\2\2\2uv\b\13\2\2v\26\3\2\2"+
+ "\2wx\7}\2\2x\30\3\2\2\2yz\7\177\2\2z\32\3\2\2\2{|\7]\2\2|\34\3\2\2\2}"+
+ "~\7_\2\2~\36\3\2\2\2\20\2&(\60;BEHN^ehls\3\b\2\2";
+ public static final ATN _ATN =
+ new ATNDeserializer().deserialize(_serializedATN.toCharArray());
+ static {
+ _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
+ for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
+ _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
+ }
+ }
+}
\ No newline at end of file
Added: plugins/XML/trunk/sidekick/json/parser/JSONLexer.tokens
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/JSONLexer.tokens (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/JSONLexer.tokens 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,15 @@
+WS=5
+LSQUARE=8
+RBRACE=7
+RSQUARE=9
+T__1=1
+T__0=2
+LBRACE=6
+STRING=3
+NUMBER=4
+'}'=7
+':'=2
+'['=8
+','=1
+'{'=6
+']'=9
Added: plugins/XML/trunk/sidekick/json/parser/JSONListener.java
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/JSONListener.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/JSONListener.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,63 @@
+// Generated from /home/danson/src/jedit/plugins/XML/sidekick/json/parser/JSON.g4 by ANTLR 4.4
+
+ package sidekick.json.parser;
+
+import org.antlr.v4.runtime.misc.NotNull;
+import org.antlr.v4.runtime.tree.ParseTreeListener;
+
+/**
+ * This interface defines a complete listener for a parse tree produced by
+ * {@link JSONParser}.
+ */
+public interface JSONListener extends ParseTreeListener {
+ /**
+ * Enter a parse tree produced by {@link JSONParser#pair}.
+ * @param ctx the parse tree
+ */
+ void enterPair(@NotNull JSONParser.PairContext ctx);
+ /**
+ * Exit a parse tree produced by {@link JSONParser#pair}.
+ * @param ctx the parse tree
+ */
+ void exitPair(@NotNull JSONParser.PairContext ctx);
+ /**
+ * Enter a parse tree produced by {@link JSONParser#json}.
+ * @param ctx the parse tree
+ */
+ void enterJson(@NotNull JSONParser.JsonContext ctx);
+ /**
+ * Exit a parse tree produced by {@link JSONParser#json}.
+ * @param ctx the parse tree
+ */
+ void exitJson(@NotNull JSONParser.JsonContext ctx);
+ /**
+ * Enter a parse tree produced by {@link JSONParser#value}.
+ * @param ctx the parse tree
+ */
+ void enterValue(@NotNull JSONParser.ValueContext ctx);
+ /**
+ * Exit a parse tree produced by {@link JSONParser#value}.
+ * @param ctx the parse tree
+ */
+ void exitValue(@NotNull JSONParser.ValueContext ctx);
+ /**
+ * Enter a parse tree produced by {@link JSONParser#object}.
+ * @param ctx the parse tree
+ */
+ void enterObject(@NotNull JSONParser.ObjectContext ctx);
+ /**
+ * Exit a parse tree produced by {@link JSONParser#object}.
+ * @param ctx the parse tree
+ */
+ void exitObject(@NotNull JSONParser.ObjectContext ctx);
+ /**
+ * Enter a parse tree produced by {@link JSONParser#array}.
+ * @param ctx the parse tree
+ */
+ void enterArray(@NotNull JSONParser.ArrayContext ctx);
+ /**
+ * Exit a parse tree produced by {@link JSONParser#array}.
+ * @param ctx the parse tree
+ */
+ void exitArray(@NotNull JSONParser.ArrayContext ctx);
+}
\ No newline at end of file
Added: plugins/XML/trunk/sidekick/json/parser/JSONNode.java
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/JSONNode.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/JSONNode.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,118 @@
+package sidekick.json.parser;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.text.Position;
+import sidekick.Asset;
+import sidekick.util.Location;
+import sidekick.util.SideKickElement;
+
+public class JSONNode extends Asset implements Comparable, SideKickElement {
+
+ private boolean isArray = false;
+ private Icon icon = null;
+ private Set<JSONNode> children = null;
+ private Location startLocation = new Location();
+ private Location endLocation = new Location();
+ private Position startPosition = new Position() {
+ public int getOffset() {
+ return 0;
+ }
+ };
+ private Position endPosition = new Position() {
+ public int getOffset() {
+ return 0;
+ }
+ };
+
+ public JSONNode() {
+ super("");
+ }
+
+ public JSONNode(String name) {
+ super(name);
+ }
+
+ public void setIsArray(boolean b) {
+ isArray = b;
+ }
+
+ public boolean isArray() {
+ return isArray;
+ }
+
+ public void addChild(JSONNode child) {
+ if (child == null) {
+ return;
+ }
+ if (children == null) {
+ children = new TreeSet<JSONNode>();
+ }
+ children.add(child);
+ }
+
+ public Set<JSONNode> getChildren() {
+ return children;
+ }
+
+ public void setStartLocation(Location start) {
+ startLocation = start;
+ }
+
+ public Location getStartLocation() {
+ return startLocation;
+ }
+
+ public void setEndLocation(Location end) {
+ endLocation = end;
+ }
+
+ public Location getEndLocation() {
+ return endLocation;
+ }
+
+ public Position getStartPosition() {
+ return startPosition;
+ }
+
+ public void setStartPosition(Position p) {
+ startPosition = p;
+ start = p;
+ }
+
+ public Position getEndPosition() {
+ return endPosition;
+ }
+
+ public void setEndPosition( Position p ) {
+ endPosition = p;
+ end = p;
+ }
+
+ public void setIcon(ImageIcon icon) {
+ this.icon = icon;
+ }
+
+ public Icon getIcon() {
+ return icon;
+ }
+
+ public String toString() {
+ return name;
+ }
+
+ public String getShortString() {
+ return name;
+ }
+
+ public String getLongString() {
+ return name + ": " + getStartLocation() + ":" + getEndLocation();
+ }
+
+ public int compareTo(Object o) {
+ return toString().compareToIgnoreCase(o.toString());
+ }
+}
Added: plugins/XML/trunk/sidekick/json/parser/JSONParser.java
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/JSONParser.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/JSONParser.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,385 @@
+// Generated from /home/danson/src/jedit/plugins/XML/sidekick/json/parser/JSON.g4 by ANTLR 4.4
+
+ package sidekick.json.parser;
+
+import org.antlr.v4.runtime.atn.*;
+import org.antlr.v4.runtime.dfa.DFA;
+import org.antlr.v4.runtime.*;
+import org.antlr.v4.runtime.misc.*;
+import org.antlr.v4.runtime.tree.*;
+import java.util.List;
+import java.util.Iterator;
+import java.util.ArrayList;
+
+@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
+public class JSONParser extends Parser {
+ static { RuntimeMetaData.checkVersion("4.4", RuntimeMetaData.VERSION); }
+
+ protected static final DFA[] _decisionToDFA;
+ protected static final PredictionContextCache _sharedContextCache =
+ new PredictionContextCache();
+ public static final int
+ T__1=1, T__0=2, STRING=3, NUMBER=4, WS=5, LBRACE=6, RBRACE=7, LSQUARE=8,
+ RSQUARE=9;
+ public static final String[] tokenNames = {
+ "<INVALID>", "','", "':'", "STRING", "NUMBER", "WS", "'{'", "'}'", "'['",
+ "']'"
+ };
+ public static final int
+ RULE_json = 0, RULE_object = 1, RULE_pair = 2, RULE_array = 3, RULE_value = 4;
+ public static final String[] ruleNames = {
+ "json", "object", "pair", "array", "value"
+ };
+
+ @Override
+ public String getGrammarFileName() { return "JSON.g4"; }
+
+ @Override
+ public String[] getTokenNames() { return tokenNames; }
+
+ @Override
+ public String[] getRuleNames() { return ruleNames; }
+
+ @Override
+ public String getSerializedATN() { return _serializedATN; }
+
+ @Override
+ public ATN getATN() { return _ATN; }
+
+ public JSONParser(TokenStream input) {
+ super(input);
+ _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
+ }
+ public static class JsonContext extends ParserRuleContext {
+ public ObjectContext object() {
+ return getRuleContext(ObjectContext.class,0);
+ }
+ public ArrayContext array() {
+ return getRuleContext(ArrayContext.class,0);
+ }
+ public JsonContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_json; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof JSONListener ) ((JSONListener)listener).enterJson(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof JSONListener ) ((JSONListener)listener).exitJson(this);
+ }
+ }
+
+ public final JsonContext json() throws RecognitionException {
+ JsonContext _localctx = new JsonContext(_ctx, getState());
+ enterRule(_localctx, 0, RULE_json);
+ try {
+ setState(12);
+ switch (_input.LA(1)) {
+ case LBRACE:
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(10); object();
+ }
+ break;
+ case LSQUARE:
+ enterOuterAlt(_localctx, 2);
+ {
+ setState(11); array();
+ }
+ break;
+ default:
+ throw new NoViableAltException(this);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class ObjectContext extends ParserRuleContext {
+ public TerminalNode LBRACE() { return getToken(JSONParser.LBRACE, 0); }
+ public List<PairContext> pair() {
+ return getRuleContexts(PairContext.class);
+ }
+ public TerminalNode RBRACE() { return getToken(JSONParser.RBRACE, 0); }
+ public PairContext pair(int i) {
+ return getRuleContext(PairContext.class,i);
+ }
+ public ObjectContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_object; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof JSONListener ) ((JSONListener)listener).enterObject(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof JSONListener ) ((JSONListener)listener).exitObject(this);
+ }
+ }
+
+ public final ObjectContext object() throws RecognitionException {
+ ObjectContext _localctx = new ObjectContext(_ctx, getState());
+ enterRule(_localctx, 2, RULE_object);
+ int _la;
+ try {
+ setState(27);
+ switch ( getInterpreter().adaptivePredict(_input,2,_ctx) ) {
+ case 1:
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(14); match(LBRACE);
+ setState(15); pair();
+ setState(20);
+ _errHandler.sync(this);
+ _la = _input.LA(1);
+ while (_la==T__1) {
+ {
+ {
+ setState(16); match(T__1);
+ setState(17); pair();
+ }
+ }
+ setState(22);
+ _errHandler.sync(this);
+ _la = _input.LA(1);
+ }
+ setState(23); match(RBRACE);
+ }
+ break;
+ case 2:
+ enterOuterAlt(_localctx, 2);
+ {
+ setState(25); match(LBRACE);
+ setState(26); match(RBRACE);
+ }
+ break;
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class PairContext extends ParserRuleContext {
+ public ValueContext value() {
+ return getRuleContext(ValueContext.class,0);
+ }
+ public TerminalNode STRING() { return getToken(JSONParser.STRING, 0); }
+ public PairContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_pair; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof JSONListener ) ((JSONListener)listener).enterPair(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof JSONListener ) ((JSONListener)listener).exitPair(this);
+ }
+ }
+
+ public final PairContext pair() throws RecognitionException {
+ PairContext _localctx = new PairContext(_ctx, getState());
+ enterRule(_localctx, 4, RULE_pair);
+ try {
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(29); match(STRING);
+ setState(30); match(T__0);
+ setState(31); value();
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class ArrayContext extends ParserRuleContext {
+ public ValueContext value(int i) {
+ return getRuleContext(ValueContext.class,i);
+ }
+ public List<ValueContext> value() {
+ return getRuleContexts(ValueContext.class);
+ }
+ public TerminalNode RSQUARE() { return getToken(JSONParser.RSQUARE, 0); }
+ public TerminalNode LSQUARE() { return getToken(JSONParser.LSQUARE, 0); }
+ public ArrayContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_array; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof JSONListener ) ((JSONListener)listener).enterArray(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof JSONListener ) ((JSONListener)listener).exitArray(this);
+ }
+ }
+
+ public final ArrayContext array() throws RecognitionException {
+ ArrayContext _localctx = new ArrayContext(_ctx, getState());
+ enterRule(_localctx, 6, RULE_array);
+ int _la;
+ try {
+ setState(46);
+ switch ( getInterpreter().adaptivePredict(_input,4,_ctx) ) {
+ case 1:
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(33); match(LSQUARE);
+ setState(34); value();
+ setState(39);
+ _errHandler.sync(this);
+ _la = _input.LA(1);
+ while (_la==T__1) {
+ {
+ {
+ setState(35); match(T__1);
+ setState(36); value();
+ }
+ }
+ setState(41);
+ _errHandler.sync(this);
+ _la = _input.LA(1);
+ }
+ setState(42); match(RSQUARE);
+ }
+ break;
+ case 2:
+ enterOuterAlt(_localctx, 2);
+ {
+ setState(44); match(LSQUARE);
+ setState(45); match(RSQUARE);
+ }
+ break;
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static class ValueContext extends ParserRuleContext {
+ public ObjectContext object() {
+ return getRuleContext(ObjectContext.class,0);
+ }
+ public TerminalNode NUMBER() { return getToken(JSONParser.NUMBER, 0); }
+ public TerminalNode STRING() { return getToken(JSONParser.STRING, 0); }
+ public ArrayContext array() {
+ return getRuleContext(ArrayContext.class,0);
+ }
+ public ValueContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_value; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof JSONListener ) ((JSONListener)listener).enterValue(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof JSONListener ) ((JSONListener)listener).exitValue(this);
+ }
+ }
+
+ public final ValueContext value() throws RecognitionException {
+ ValueContext _localctx = new ValueContext(_ctx, getState());
+ enterRule(_localctx, 8, RULE_value);
+ try {
+ setState(52);
+ switch (_input.LA(1)) {
+ case STRING:
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(48); match(STRING);
+ }
+ break;
+ case NUMBER:
+ enterOuterAlt(_localctx, 2);
+ {
+ setState(49); match(NUMBER);
+ }
+ break;
+ case LBRACE:
+ enterOuterAlt(_localctx, 3);
+ {
+ setState(50); object();
+ }
+ break;
+ case LSQUARE:
+ enterOuterAlt(_localctx, 4);
+ {
+ setState(51); array();
+ }
+ break;
+ default:
+ throw new NoViableAltException(this);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
+ public static final String _serializedATN =
+ "\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\139\4\2\t\2\4\3\t"+
+ "\3\4\4\t\4\4\5\t\5\4\6\t\6\3\2\3\2\5\2\17\n\2\3\3\3\3\3\3\3\3\7\3\25\n"+
+ "\3\f\3\16\3\30\13\3\3\3\3\3\3\3\3\3\5\3\36\n\3\3\4\3\4\3\4\3\4\3\5\3\5"+
+ "\3\5\3\5\7\5(\n\5\f\5\16\5+\13\5\3\5\3\5\3\5\3\5\5\5\61\n\5\3\6\3\6\3"+
+ "\6\3\6\5\6\67\n\6\3\6\2\2\7\2\4\6\b\n\2\2;\2\16\3\2\2\2\4\35\3\2\2\2\6"+
+ "\37\3\2\2\2\b\60\3\2\2\2\n\66\3\2\2\2\f\17\5\4\3\2\r\17\5\b\5\2\16\f\3"+
+ "\2\2\2\16\r\3\2\2\2\17\3\3\2\2\2\20\21\7\b\2\2\21\26\5\6\4\2\22\23\7\3"+
+ "\2\2\23\25\5\6\4\2\24\22\3\2\2\2\25\30\3\2\2\2\26\24\3\2\2\2\26\27\3\2"+
+ "\2\2\27\31\3\2\2\2\30\26\3\2\2\2\31\32\7\t\2\2\32\36\3\2\2\2\33\34\7\b"+
+ "\2\2\34\36\7\t\2\2\35\20\3\2\2\2\35\33\3\2\2\2\36\5\3\2\2\2\37 \7\5\2"+
+ "\2 !\7\4\2\2!\"\5\n\6\2\"\7\3\2\2\2#$\7\n\2\2$)\5\n\6\2%&\7\3\2\2&(\5"+
+ "\n\6\2\'%\3\2\2\2(+\3\2\2\2)\'\3\2\2\2)*\3\2\2\2*,\3\2\2\2+)\3\2\2\2,"+
+ "-\7\13\2\2-\61\3\2\2\2./\7\n\2\2/\61\7\13\2\2\60#\3\2\2\2\60.\3\2\2\2"+
+ "\61\t\3\2\2\2\62\67\7\5\2\2\63\67\7\6\2\2\64\67\5\4\3\2\65\67\5\b\5\2"+
+ "\66\62\3\2\2\2\66\63\3\2\2\2\66\64\3\2\2\2\66\65\3\2\2\2\67\13\3\2\2\2"+
+ "\b\16\26\35)\60\66";
+ public static final ATN _ATN =
+ new ATNDeserializer().deserialize(_serializedATN.toCharArray());
+ static {
+ _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
+ for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
+ _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
+ }
+ }
+}
\ No newline at end of file
Added: plugins/XML/trunk/sidekick/json/parser/JSONSideKickListener.java
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/JSONSideKickListener.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/JSONSideKickListener.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,119 @@
+package sidekick.json.parser;
+
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.antlr.v4.runtime.misc.NotNull;
+import org.antlr.v4.runtime.tree.TerminalNode;
+
+import sidekick.util.Location;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import javax.swing.ImageIcon;
+
+import eclipseicons.EclipseIconsPlugin;
+
+public class JSONSideKickListener extends JSONBaseListener {
+
+ Deque<JSONNode> stack = new ArrayDeque<JSONNode>();
+ JSONNode root = null;
+
+ ImageIcon pairIcon = EclipseIconsPlugin.getIcon("field_public_obj.gif");
+ ImageIcon objectIcon = EclipseIconsPlugin.getIcon("javaassist_co.gif");
+ ImageIcon arrayIcon = EclipseIconsPlugin.getIcon("packd_obj.gif");
+
+
+ public JSONNode getRoot() {
+ return root;
+ }
+ @Override public void enterPair( @NotNull JSONParser.PairContext ctx ) {
+ JSONNode node = new JSONNode( ctx.STRING().getText() );
+ node.setStartLocation( getStartLocation( ctx ) );
+ node.setEndLocation( getEndLocation( ctx ) );
+ node.setIcon(pairIcon);
+ stack.push( node );
+ }
+ @Override public void exitPair( @NotNull JSONParser.PairContext ctx ) {
+ JSONNode node = stack.pop();
+ JSONNode parent = stack.peek();
+ parent.addChild( node );
+ }
+ @Override public void enterJson( @NotNull JSONParser.JsonContext ctx ) {
+ root = new JSONNode();
+ root.setStartLocation( getStartLocation( ctx ) );
+ root.setEndLocation( getEndLocation( ctx ) );
+ stack.push( root );
+ }
+ @Override public void exitJson( @NotNull JSONParser.JsonContext ctx ) {
+ stack.pop();
+ }
+ @Override public void enterValue( @NotNull JSONParser.ValueContext ctx ) {
+ // if the value is a number, which is defined as a number, true, false, or null,
+ // then go ahead and add it to the name of the parent node. If it is an object
+ // or an array, go ahead and recurse.
+ JSONNode node = new JSONNode();
+ TerminalNode number = ctx.NUMBER();
+ if ( number != null ) {
+ JSONNode parent = stack.peek();
+ parent.setName(parent.getName() + ": " + number.getText());
+ } else {
+ number = ctx.STRING();
+ if ( number != null ) {
+ JSONNode parent = stack.peek();
+ parent.setName(parent.getName() + ": " + number.getText());
+ }
+ }
+ node.setStartLocation( getStartLocation( ctx ) );
+ node.setEndLocation( getEndLocation( ctx ) );
+ stack.push( node );
+ }
+ @Override public void exitValue( @NotNull JSONParser.ValueContext ctx ) {
+ JSONNode node = stack.pop();
+ String name = node.getName();
+ // numbers and strings are already part of the parent node name, this
+ // next 'if' adds object and array nodes to the parent.
+ if (name == null || name.isEmpty()) {
+ JSONNode parent = stack.peek();
+ parent.addChild( node );
+ }
+ }
+ @Override public void enterObject( @NotNull JSONParser.ObjectContext ctx ) {
+ JSONNode node = new JSONNode();
+ node.setStartLocation( getStartLocation( ctx ) );
+ node.setEndLocation( getEndLocation( ctx ) );
+ node.setIcon(objectIcon);
+ stack.push( node );
+ }
+ @Override public void exitObject( @NotNull JSONParser.ObjectContext ctx ) {
+ JSONNode node = stack.pop();
+ JSONNode parent = stack.peek();
+ parent.addChild( node );
+ }
+ @Override public void enterArray( @NotNull JSONParser.ArrayContext ctx ) {
+ JSONNode node = new JSONNode();
+ node.setIsArray(true);
+ node.setStartLocation( getStartLocation( ctx ) );
+ node.setEndLocation( getEndLocation( ctx ) );
+ node.setIcon(arrayIcon);
+ stack.push( node );
+ }
+ @Override public void exitArray( @NotNull JSONParser.ArrayContext ctx ) {
+ JSONNode node = stack.pop();
+ JSONNode parent = stack.peek();
+ parent.addChild( node );
+ }
+
+ // return a Location representing the start of the rule context
+ private Location getStartLocation( ParserRuleContext ctx ) {
+ int line = ctx.getStart().getLine();
+ int col = ctx.getStart().getCharPositionInLine();
+ return new Location( line, col );
+ }
+
+ // return a Location representing the end of the rule context
+ private Location getEndLocation( ParserRuleContext ctx ) {
+ int line = ctx.getStop().getLine();
+ int col = ctx.getStop().getCharPositionInLine();
+ return new Location( line, col );
+ }
+
+}
\ No newline at end of file
Added: plugins/XML/trunk/sidekick/json/parser/ParseException.java
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/ParseException.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/ParseException.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,31 @@
+package sidekick.json.parser;
+
+public class ParseException extends Exception {
+ private String message;
+ private int lineNumber;
+ private int column;
+ private int length;
+
+ public ParseException(String message, int lineNumber, int column, int length) {
+ this.message = message;
+ this.lineNumber = lineNumber;
+ this.column = column;
+ this.length = length;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public int getLineNumber() {
+ return lineNumber;
+ }
+
+ public int getColumn() {
+ return column;
+ }
+
+ public int getLength() {
+ return length;
+ }
+}
\ No newline at end of file
Added: plugins/XML/trunk/sidekick/json/parser/SideKickErrorListener.java
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/SideKickErrorListener.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/SideKickErrorListener.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,26 @@
+package sidekick.json.parser;
+
+import org.antlr.v4.runtime.*;
+
+import java.util.*;
+
+public class SideKickErrorListener extends BaseErrorListener {
+
+ private List<ParseException> errors = new ArrayList<ParseException>();
+
+ public List<ParseException> getErrors() {
+ return errors;
+ }
+
+ @Override
+ public void syntaxError( Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e ) {
+ int length = 0;
+ if ( e != null && e.getOffendingToken() != null ) {
+ int startOffset = e.getOffendingToken().getStartIndex();
+ int endOffset = e.getOffendingToken().getStopIndex();
+ length = endOffset - startOffset;
+ }
+ ParseException pe = new ParseException( msg, line - 1, charPositionInLine, length );
+ errors.add( pe );
+ }
+}
\ No newline at end of file
Added: plugins/XML/trunk/sidekick/json/parser/SideKickPosition.java
===================================================================
--- plugins/XML/trunk/sidekick/json/parser/SideKickPosition.java (rev 0)
+++ plugins/XML/trunk/sidekick/json/parser/SideKickPosition.java 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,17 @@
+package sidekick.json.parser;
+
+import javax.swing.text.Position;
+
+// a concrete implementation of Position
+public class SideKickPosition implements Position {
+
+ private int offset;
+
+ public SideKickPosition(int offset) {
+ this.offset = offset;
+ }
+
+ public int getOffset() {
+ return offset;
+ }
+}
\ No newline at end of file
Added: plugins/XML/trunk/sidekick/json/test.json
===================================================================
--- plugins/XML/trunk/sidekick/json/test.json (rev 0)
+++ plugins/XML/trunk/sidekick/json/test.json 2014-12-20 18:07:04 UTC (rev 23797)
@@ -0,0 +1,22 @@
+{
+ "glossary": {
+ "title": "example glossary",
+ "GlossDiv": {
+ "title": "S",
+ "GlossList": {
+ "GlossEntry": {
+ "ID": "SGML",
+ "SortAs": "SGML",
+ "GlossTerm": "Standard Generalized Markup Language",
+ "Acronym": "SGML",
+ "Abbrev": "ISO 8879:1986",
+ "GlossDef": {
+ "para": "A meta-markup language, used to create markup languages such as DocBook.",
+ "GlossSeeAlso": ["GML", "XML"]
+ },
+ "GlossSee": "markup"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|