You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by el...@apache.org on 2006/12/09 19:10:23 UTC

svn commit: r485019 - in /labs/dungeon/src: main/java/org/apache/dungeon/meta/parser/ test/java/org/apache/dungeon/meta/parser/

Author: elecharny
Date: Sat Dec  9 10:10:20 2006
New Revision: 485019

URL: http://svn.apache.org/viewvc?view=rev&rev=485019
Log:
Renammed the metaRhs class to metaRule
Added some javadoc

Added:
    labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaRule.java
      - copied, changed from r484670, labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaRhs.java
Removed:
    labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaRhs.java
Modified:
    labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java
    labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaParser.java
    labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaProduction.java
    labs/dungeon/src/test/java/org/apache/dungeon/meta/parser/MetaParserTest.java

Modified: labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java
URL: http://svn.apache.org/viewvc/labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java?view=diff&rev=485019&r1=485018&r2=485019
==============================================================================
--- labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java (original)
+++ labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaGrammar.java Sat Dec  9 10:10:20 2006
@@ -55,7 +55,7 @@
     private Symbol startingSymbol;
     
     /** The list of all VNs on all the RHS parts */
-    private Set<String> rhsVNs;
+    private Set<String> rulesVNs;
     
 	/**
      * 
@@ -66,7 +66,7 @@
 	{
 		productions = new ArrayList<Production>();
         vns = new HashSet<String>();
-        rhsVNs = new HashSet<String>();
+        rulesVNs = new HashSet<String>();
 	}
     
     /**
@@ -137,7 +137,7 @@
      */
     public Set<String> getRhsVNs()
     {
-        return rhsVNs;
+        return rulesVNs;
     }
 
     /**
@@ -146,9 +146,9 @@
      */
     public void addRhsVN( String vn )
     {
-        if ( !rhsVNs.contains( vn ) )
+        if ( !rulesVNs.contains( vn ) )
         {
-            rhsVNs.add( vn );
+            rulesVNs.add( vn );
         }
     }
     

Modified: labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaParser.java
URL: http://svn.apache.org/viewvc/labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaParser.java?view=diff&rev=485019&r1=485018&r2=485019
==============================================================================
--- labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaParser.java (original)
+++ labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaParser.java Sat Dec  9 10:10:20 2006
@@ -442,7 +442,7 @@
      * @return 
      * @throws ParserException
      */
-    private MetaRhs parseRhsEmpty( char[] grammarText, Position pos, Production production ) throws ParserException
+    private MetaRule parseRhsEmpty( char[] grammarText, Position pos, Production production ) throws ParserException
     {
         // BAR
         if ( StringTools.isCharASCII( grammarText, pos.current, BAR ) == false )
@@ -479,7 +479,7 @@
      * @return
      * @throws ParserException
      */
-    private MetaRhs parseRule( char[] grammarText, Position pos, MetaRhs rhs ) throws ParserException
+    private MetaRule parseRule( char[] grammarText, Position pos, MetaRule rhs ) throws ParserException
     {
         char c = StringTools.charAt( grammarText, pos.current );
         
@@ -563,7 +563,7 @@
      * @return
      * @throws ParserException
      */
-    private MetaRhs parseRhs( char[] grammarText, Position pos, Production production ) throws ParserException
+    private MetaRule parseRhs( char[] grammarText, Position pos, Production production ) throws ParserException
     {
         char c = StringTools.charAt( grammarText, pos.current );
         
@@ -574,7 +574,7 @@
         }
         
         Symbol symbol = null;
-        MetaRhs rhs = new MetaRhs();
+        MetaRule rhs = new MetaRule();
         
         switch ( c )
         {
@@ -607,7 +607,7 @@
                 }
                 
                 rhs.addSymbol( epsilonTransition );
-                ((MetaProduction)production).addRhs( rhs );
+                ((MetaProduction)production).addRule( rhs );
                 return rhs;
             
             case QUOTE :
@@ -659,7 +659,7 @@
         
         try
         {
-            ((MetaProduction)production).addRhs( rhs );
+            ((MetaProduction)production).addRule( rhs );
             parseRhsEmpty( grammarText, pos, production );
             return rhs;
         }
@@ -849,7 +849,7 @@
             parseRhs( grammarText, pos, production );
 
             // Feed the grammar with all the found VN
-            for ( MetaRhs rhs:((MetaProduction)production).getRhs() )
+            for ( MetaRule rhs:((MetaProduction)production).getRules() )
             {
                 for ( Symbol symbol:rhs.getSymbols() )
                 if ( symbol instanceof VN )

Modified: labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaProduction.java
URL: http://svn.apache.org/viewvc/labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaProduction.java?view=diff&rev=485019&r1=485018&r2=485019
==============================================================================
--- labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaProduction.java (original)
+++ labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaProduction.java Sat Dec  9 10:10:20 2006
@@ -41,7 +41,7 @@
 public class MetaProduction extends AbstractProduction 
 {
     /** The RHS list */
-	private List<MetaRhs> rhsList;
+	private List<MetaRule> rules;
     
     /** This flag is set if the production has an epsilon transition */ 
     private boolean epsilonTransition;
@@ -55,7 +55,7 @@
      */
 	public MetaProduction()
 	{
-		rhsList = new ArrayList<MetaRhs>();
+		rules = new ArrayList<MetaRule>();
         epsilonTransition = false;
 	}
 
@@ -68,21 +68,21 @@
 	}
 
     /**
-     * Add a new RHS to the current production
-     * @param rhs The RHS associated with this production
+     * Add a new Rule to the current production
+     * @param rule The Rule associated with this production
      */
-    public void addRhs( MetaRhs rhs )
+    public void addRule( MetaRule rule )
     {
-        rhsList.add( rhs );
+        rules.add( rule );
     }
     
     /**
      * 
-     * @return The production's RHS
+     * @return The production's rules
      */
-    public List<MetaRhs> getRhs()
+    public List<MetaRule> getRules()
     {
-        return rhsList;
+        return rules;
     }
     
     /**
@@ -119,7 +119,7 @@
         
         boolean isFirst = true;
         
-        for ( MetaRhs rhs:rhsList )
+        for ( MetaRule rule:rules )
         {
             if ( isFirst )
             {
@@ -130,7 +130,7 @@
                 sb.append( " | " );
             }
             
-            sb.append( rhs.toStringValue() );
+            sb.append( rule.toStringValue() );
         }
         
         return sb.toString();

Copied: labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaRule.java (from r484670, labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaRhs.java)
URL: http://svn.apache.org/viewvc/labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaRule.java?view=diff&rev=485019&p1=labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaRhs.java&r1=484670&p2=labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaRule.java&r2=485019
==============================================================================
--- labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaRhs.java (original)
+++ labs/dungeon/src/main/java/org/apache/dungeon/meta/parser/MetaRule.java Sat Dec  9 10:10:20 2006
@@ -23,31 +23,50 @@
 import java.util.List;
 
 /**
+ * The MetaRule class is used to contain a rule. A rule is a list 
+ * of symbols (VT and VN) or an epsilon transition. A production is 
+ * a LHS associated to a list of rules.
  * 
- * TODO MetaProduction.
+ * Rule -> ( VN | VT )+ | # 
  *
  * @author <a href="mailto:dev@labs.apache.org">Dungeon Project</a>
- * @version $Rev$, $Date$
  */
-public class MetaRhs
+public class MetaRule
 {
+    /** The list of symbols for this rule */
 	private List<Symbol> symbols;
 	
-	public MetaRhs()
+    /**
+     * 
+     * Creates a new instance of MetaRule.
+     *
+     */
+	public MetaRule()
 	{
         symbols = new ArrayList<Symbol>();
 	}
 
+    /**
+     * Add a symbol to this rule while parsing the grammar
+     *
+     * @param symbol
+     */
     public void addSymbol( Symbol symbol )
     {
         symbols.add( symbol );
     }
     
+    /**
+     *  @return The list of symbols for this rule
+     */
     public List<Symbol> getSymbols()
     {
         return symbols;
     }
     
+    /**
+     *  @return A string representing the rule
+     */
     public String toStringValue()
     {
         StringBuilder sb = new StringBuilder();
@@ -71,11 +90,14 @@
         return sb.toString();
     }
     
+    /**
+     * @see java.lang.Object#toString()
+     */
     public String toString()
     {
         StringBuilder sb = new StringBuilder();
         
-        sb.append( "RHS : " );
+        sb.append( "Rule : " );
         
         boolean isFirst = true;
         
@@ -95,5 +117,4 @@
         
         return sb.toString();
     }
-    
 }

Modified: labs/dungeon/src/test/java/org/apache/dungeon/meta/parser/MetaParserTest.java
URL: http://svn.apache.org/viewvc/labs/dungeon/src/test/java/org/apache/dungeon/meta/parser/MetaParserTest.java?view=diff&rev=485019&r1=485018&r2=485019
==============================================================================
--- labs/dungeon/src/test/java/org/apache/dungeon/meta/parser/MetaParserTest.java (original)
+++ labs/dungeon/src/test/java/org/apache/dungeon/meta/parser/MetaParserTest.java Sat Dec  9 10:10:20 2006
@@ -64,7 +64,7 @@
         
         Production production = productions.get( 0 );
         
-        MetaRhs rhs = ((MetaProduction)production).getRhs().get( 0 );
+        MetaRule rhs = ((MetaProduction)production).getRules().get( 0 );
         
         assertNotNull( rhs );
         
@@ -91,7 +91,7 @@
         
         Production production = productions.get( 0 );
         
-        MetaRhs rhs = ((MetaProduction)production).getRhs().get( 0 );
+        MetaRule rhs = ((MetaProduction)production).getRules().get( 0 );
         
         assertNotNull( rhs );
         
@@ -119,7 +119,7 @@
         
         Production production = productions.get( 0 );
         
-        MetaRhs rhs = ((MetaProduction)production).getRhs().get( 0 );
+        MetaRule rhs = ((MetaProduction)production).getRules().get( 0 );
         
         assertNotNull( rhs );
         
@@ -156,7 +156,7 @@
         List<Production> productions = mg.getProductions();
         
         Production production = productions.get( 0 );
-        MetaRhs rhs = ((MetaProduction)production).getRhs().get( 0 );
+        MetaRule rhs = ((MetaProduction)production).getRules().get( 0 );
         
         assertNotNull( rhs );
         
@@ -170,7 +170,7 @@
         assertEquals( expected1, production.toString() );
 
         production = productions.get( 1 );
-        rhs = ((MetaProduction)production).getRhs().get( 0 );
+        rhs = ((MetaProduction)production).getRules().get( 0 );
         assertNotNull( rhs );
 
         symbols = rhs.getSymbols();
@@ -207,7 +207,7 @@
         List<Production> productions = mg.getProductions();
         
         Production production = productions.get( 0 );
-        MetaRhs rhs = ((MetaProduction)production).getRhs().get( 0 );
+        MetaRule rhs = ((MetaProduction)production).getRules().get( 0 );
         
         assertNotNull( rhs );
         
@@ -221,7 +221,7 @@
         assertEquals( expected1, production.toString() );
 
         production = productions.get( 1 );
-        rhs = ((MetaProduction)production).getRhs().get( 0 );
+        rhs = ((MetaProduction)production).getRules().get( 0 );
         assertNotNull( rhs );
 
         symbols = rhs.getSymbols();
@@ -254,7 +254,7 @@
         List<Production> productions = mg.getProductions();
         
         Production production = productions.get( 0 );
-        MetaRhs rhs = ((MetaProduction)production).getRhs().get( 0 );
+        MetaRule rhs = ((MetaProduction)production).getRules().get( 0 );
         
         assertNotNull( rhs );
         
@@ -265,7 +265,7 @@
         Symbol symbol = symbols.get( 0 );
         assertTrue( symbol instanceof VT );
 
-        rhs = ((MetaProduction)production).getRhs().get( 1 );
+        rhs = ((MetaProduction)production).getRules().get( 1 );
         symbols = rhs.getSymbols();
         assertNotNull( symbols );
         



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org