[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jedit-cvs
Subject:    [ jEdit-CVS ] plugins/JBrowse/src/jbrowse/tiger/parser Tiger.jj,1.1,1.2 TigerParser.java,1.1,1.2 Tok
From:       Dale Anson <daleanson () users ! sourceforge ! net>
Date:       2005-12-31 18:06:06
Message-ID: E1Esl7M-0001nE-D6 () mail ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger/parser
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10909/src/jbrowse/tiger/parser

Modified Files:
	Tiger.jj TigerParser.java Token.java 
Removed Files:
	ModifierSet.java 
Log Message:
updates



Index: Token.java
===================================================================
RCS file: /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger/parser/Token.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Token.java	20 Dec 2005 23:44:01 -0000	1.1
+++ Token.java	31 Dec 2005 18:06:04 -0000	1.2
@@ -1,6 +1,6 @@
-/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */
-package jbrowse.tiger.parser;
+// Hand-modified for TigerParser, do not delete this file!
 
+package jbrowse.tiger.parser;
 /**
  * Describes the input token stream.
  */

Index: Tiger.jj
===================================================================
RCS file: /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger/parser/Tiger.jj,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Tiger.jj	20 Dec 2005 23:44:01 -0000	1.1
+++ Tiger.jj	31 Dec 2005 18:06:04 -0000	1.2
@@ -48,59 +48,69 @@
 
 /**
  * Based on grammar to parse Java version 1.5 written by Sreenivasa Viswanadha,
- * parses a java file for the jEdit SideKick plugin to provide a java code
+ * parses a java file for the JBrowse plugin to provide a java code
  * browser that works with java 1.5.
+ * <p>
+ * Example usage:<p>
+ * <code>
+ * TigerParser parser = new TigerParser(filename);<br>
+ * CUNode root = parser.CompilationUnit();<br>
+ * </code>
+ * Calling <code>CompilationUnit()</code> causes the file to be parsed into
+ * TigerNodes, of which, CUNode is the top-level.  The TigerNodes have a parent/
+ * child relastionship, which naturally forms a tree structure.
+ * <p>
+ * To turn this .jj file into a .java file, run <code>javacc Tiger.jj</code>
+ * from the directory that contains this file.  Javacc will produce a number of
+ * .java files, Be careful -- not all files in the directory are produced by
+ * javacc, in particular ModifierSet.java and Token.java are required files and
+ * are NOT produced by javacc. So the sequence is:<br>
+ * .jj -> javacc -> .java -> javac -> .class
  */
 public class TigerParser
 {
-    
+   // accumulates counts of classes, interfaces, methods and fields. 
    private Results results = new Results();
+
    
+   private InputStream inputStream = null;
    
-   public TigerParser(String fileName)
+    /**
+     * Constructor for TigerParser.  Note that JBrowse does not use this 
+     * constructor -- since the options for build the parser have both
+     * USER_TOKEN_MANAGER and USER_CHAR_STREAM set to false (these are the
+     * default values so are not explicitly set), javacc will create a
+     * constructor "public TigerParser(InputStream)".  It is that constructor
+     * that JBrowse uses.
+     * @param fileName name of the file to parse
+     */
+   public TigerParser(String filename)
    {
       this(System.in);
-      try { ReInit(new FileInputStream(new File(fileName))); }
-      catch(Exception e) { e.printStackTrace(); }
+      try {
+          inputStream = new FileInputStream(new File(filename));
+          ReInit(inputStream); 
+      }
+      catch(Exception e) { 
+        e.printStackTrace(); 
+      }
    }
    
+	/**
+	 * @return the accumulated counts of classes, interfaces, methods, and fields.   
+	 */
    public Results getResults() {
         return results;   
    }
 
-  public static void main(String args[]) {
-    TigerParser parser;
-    if (args.length == 0) {
-      System.out.println("TigerParser Version 1.1:  Reading from standard input . . \
                .");
-      parser = new TigerParser(System.in);
-    } else if (args.length == 1) {
-      System.out.println("TigerParser Version 1.1:  Reading from file " + args[0] + \
                " . . .");
-      try {
-        parser = new TigerParser(new java.io.FileInputStream(args[0]));
-      } catch (java.io.FileNotFoundException e) {
-        System.out.println("TigerParser Version 1.1:  File " + args[0] + " not \
                found.");
-        return;
-      }
-    } else {
-      System.out.println("TigerParser Version 1.1:  Usage is one of:");
-      System.out.println("         java TigerParser < inputfile");
-      System.out.println("OR");
-      System.out.println("         java TigerParser inputfile");
-      return;
-    }
-    try {
-      parser.CompilationUnit();
-      System.out.println("TigerParser Version 1.1:  Java program parsed \
                successfully.");
-    } catch (ParseException e) {
-      System.out.println(e.getMessage());
-      System.out.println("TigerParser Version 1.1:  Encountered errors during \
                parse.");
-    }
-  }
 
 }
 
 PARSER_END(TigerParser)
 
+
+/* **************** Parser Rules Follow ****************/
+
 /* WHITE SPACE */
 
 SKIP :
@@ -387,26 +397,44 @@
  * Program structuring syntax follows.
  */
 
+/**
+ * Main entry point for parsing.
+ * @return a CUNode, which is parent or root node of all other nodes.
+ */
 CUNode CompilationUnit():
 {
     CUNode n = new CUNode();
-    TigerNode a;
+    TigerNode a;    
 }
 {
   (
+   // don't care about package or imports for JBrowse
    [ PackageDeclaration() ]
    ( ImportDeclaration() )*
+   
+   // do care about TypeDeclaration, this will be one or more classes or 
+   // interfaces, add these as child nodes of the root node
    ( 
      a=TypeDeclaration()
      { n.addChild(a); }
    )*
+   
+   // read the whole file
    <EOF>
   )
   {
+    try {
+        if (inputStream != null)
+            inputStream.close();
+    }
+    catch(Exception e) {
+        // not to worry
+    }
     return n;   
   }
 }
 
+
 void PackageDeclaration():
 {}
 {
@@ -467,13 +495,15 @@
 /*
  * Declaration syntax follows.
  */
+
+// Handle classes, interfaces, enums, and annotations. 
 TigerNode TypeDeclaration():
 {
    int modifiers;
    TigerNode tn = null;
 }
 {
-  ";"
+    ";"     /// is this the semi-colon that I need to handle at the end of a class??
 |
   modifiers = Modifiers()
   (
@@ -489,12 +519,14 @@
   
 }
 
-
+/**
+ * @return a ClassNode or an InterfaceNode
+ */
 TigerNode ClassOrInterfaceDeclaration(int modifiers):
 {
    boolean isInterface = false;
    Token t;
-   TigerNode kids = null;
+   TigerNode kids = null;   // only need the children of this node
    String type_params = "";
    List extends_list = null;
    List implements_list = null;
@@ -509,7 +541,7 @@
   /* danson, added this check for trailing semi-colon.  Apparently, this has been
   legal since the beginning of Java, some sort of a C hold-over.  Sun's latest
   Java 1.5 compiler doesn't mind it, but this parser whined if the class has a
-  semi-colon after the last }.  Note: the original Java1.5.jj file that this parser
+  semi-colon after the last }.  The original Java1.5.jj file that this parser
   is based on does NOT whine, so I've done something to change the base behaviour. 
   See below, I probably broke this in ClassOrInterfaceBody. */
   [ LOOKAHEAD(2) <SEMICOLON> ]
@@ -521,6 +553,8 @@
     else
         results.incClassCount();
     
+    // add the child nodes, don't need the 'kids' node itself, it's just a holder
+    // for the nodes I want.
     if (kids != null && kids.getChildren() != null)
         node.addChildren(kids.getChildren());
     node.setTypeParams(type_params);
@@ -530,10 +564,14 @@
   }
 }
 
+/**
+ * @return a list of jbrowse.tiger.node.Types representing items in an 'extends'
+ * list, e.g. the "Bar" in "public class Foo extends Bar"
+ */
 List ExtendsList(boolean isInterface):
 {
    boolean extendsMoreThanOne = false;
-   List list = new ArrayList();
+   List list = new ArrayList();     // a list of Types
    Type type_s = null;
    Type type_a = null;
 }
@@ -547,6 +585,10 @@
    }
 }
 
+/**
+ * @return a list of jbrowse.tiger.node.Types representing items in an 'implements'
+ * list, e.g. the "Bar" and "Serializable" in "public class Foo implements Bar, \
Serializable" + */
 List ImplementsList(boolean isInterface):
 {
     List list = new ArrayList();
@@ -563,6 +605,9 @@
    }
 }
 
+/**
+ * @return an EnumNode
+ */
 TigerNode EnumDeclaration(int modifiers):
 {
     Token t;
@@ -592,6 +637,10 @@
   <IDENTIFIER> [ Arguments() ] [ ClassOrInterfaceBody(false) ]
 }
 
+/**
+ * @return a string representing a generics type, e.g. the "<String>" in
+ * "List<String> list = new List();", the string will contain the angle brackets.
+ */
 String TypeParameters():
 {
     String s = "<";
@@ -657,6 +706,12 @@
   }
 }
 
+/**
+ * @return a node representing the contents of a Class or Interface body.  The
+ * returned node is simply a holder for the contents, it is the children of this
+ * node that is useful as they are the methods and fields of the class or
+ * interface.
+ */
 TigerNode ClassOrInterfaceBody(boolean isInterface):
 {
     TigerNode parent = new TigerNode("", -1, -1);
@@ -676,6 +731,10 @@
   }
 }
 
+/**
+ * @return one of several different nodes, could be a ClassNode, EnumNode,
+ * ConstructorNode, FieldNode, MethodNode, or an InterfaceNode.
+ */
 TigerNode ClassOrInterfaceBodyDeclaration(boolean isInterface):
 {
    // see note above (~ line 510), I think my changes here have broken the test for \
a @@ -717,7 +776,7 @@
       a=MethodDeclaration(modifiers)
   )
 |
-  ";"
+  ";"   /// is this the trailing semi-colon??
   )
   {
     return a;    
@@ -725,15 +784,24 @@
   
 }
 
+/**
+ * @return a FieldNode
+ */
 TigerNode FieldDeclaration(int modifiers):
 {
     Type type = null;
     TigerNode name ;
+    TigerNode a;
 }
 {
   (
   // Modifiers are already matched in the caller
-  type=Type() name=VariableDeclarator() ( "," VariableDeclarator() )* ";"
+  /// might need to change this, I'm collecting multiple declarations into a single
+  /// field, which seems to be okay, e.g. I'm putting "int x = 0, y = 6" into a 
+  /// field with Type "int" and name "x, y".  It might be better to create \
individual +  /// nodes for each, so for this example, this method could return 2 \
fields, one +  /// for "int x" and one for "int y".
+  type=Type() name=VariableDeclarator() ( "," a=VariableDeclarator() { \
name.setName(name.getName() + ", " + a.getName()); })* ";"  )
   {
       FieldNode fn = new FieldNode(name.getName(), modifiers, type, \
name.getLineNumber()); @@ -783,6 +851,9 @@
   "{" [ VariableInitializer() ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] \
"}"  }
 
+/**
+ * @return a MethodNode
+ */
 TigerNode MethodDeclaration(int modifiers):
 {
     String type_params = "";
@@ -919,6 +990,9 @@
   [ LOOKAHEAD(2) PrimaryExpression() "." ] "super" Arguments() ";"
 }
 
+/**
+ * @return an InitializerNode, this handles static initializer blocks
+ */
 TigerNode Initializer():
 {
     Token t = null;
@@ -1110,6 +1184,9 @@
     }
 }
 
+/***************** END OF MODIFICATIONS FOR JBROWSE ***************************/
+
+
 
 /*
  * Expression syntax follows.

--- ModifierSet.java DELETED ---

Index: TigerParser.java
===================================================================
RCS file: /cvsroot/jedit/plugins/JBrowse/src/jbrowse/tiger/parser/TigerParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- TigerParser.java	20 Dec 2005 23:44:01 -0000	1.1
+++ TigerParser.java	31 Dec 2005 18:06:04 -0000	1.2
@@ -8,54 +8,60 @@
 
 /**
  * Based on grammar to parse Java version 1.5 written by Sreenivasa Viswanadha,
- * parses a java file for the jEdit SideKick plugin to provide a java code
+ * parses a java file for the JBrowse plugin to provide a java code
  * browser that works with java 1.5.
+ * <p>
+ * Example usage:<p>
+ * <code>
+ * TigerParser parser = new TigerParser(filename);<br>
+ * CUNode root = parser.CompilationUnit();<br>
[...2252 lines suppressed...]
+    return false;
+  }
+
+  final private boolean jj_3R_226() {
+    if (jj_3R_155()) return true;
+    return false;
+  }
+
+  final private boolean jj_3R_86() {
+    if (jj_scan_token(LBRACE)) return true;
     Token xsp;
     while (true) {
       xsp = jj_scanpos;
-      if (jj_3R_281()) { jj_scanpos = xsp; break; }
+      if (jj_3R_123()) { jj_scanpos = xsp; break; }
     }
+    if (jj_scan_token(RBRACE)) return true;
     return false;
   }
 



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
jEdit-CVS mailing list
jEdit-CVS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic