Author: timotei
Date: Tue Jul 26 17:33:05 2011
New Revision: 50431

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50431&view=rev
Log:
eclipse plugin: Implement parsing of the lua
tag's children attributes

Modified:
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleLuaParser.java

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleLuaParser.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleLuaParser.java?rev=50431&r1=50430&r2=50431&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleLuaParser.java 
(original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleLuaParser.java 
Tue Jul 26 17:33:05 2011
@@ -28,7 +28,9 @@
     private List<Tag> tags_;
     private Reader reader_;
 
-    private String TAG_REGEX = "wml_actions\\..+\\( *cfg *\\)";
+    private final static String TAG_REGEX = "wml_actions\\..+\\( *cfg *\\)";
+    private final static String ATTRIBUTE_REGEX = "cfg\\.[a-zA-Z0-9_]*";
+    private final static String ATTRIBUTE_CHILD_REGEX = "get_child\\(cfg, 
*\"[^\"]+\"\\)";
 
     public SimpleLuaParser( String contents )
     {
@@ -44,18 +46,43 @@
         BufferedReader reader = new BufferedReader( reader_ );
         String line = null;
 
+        Tag currentTag = null;
+
         try
         {
             while( ( line = reader.readLine( ) ) != null ) {
-                List<String> tokens = StringUtils.getGroups( TAG_REGEX, line );
+                List<String> tagTokens = StringUtils.getGroups( TAG_REGEX, 
line );
 
-                for ( String token : tokens ) {
+                // we handle just on tag per line
+                if ( !tagTokens.isEmpty( ) ) {
+                    String token = tagTokens.get( 0 );
                     // parse the tag name
                     String tagName = token.substring(
                             token.indexOf( '.' ) + 1,
-                            token.length( ) - 1 );
+                            token.lastIndexOf( '(' ) );
 
-                    tags_.add( new Tag( tagName, '*' ) );
+                    currentTag = new Tag( tagName, '*' );
+                    tags_.add( currentTag );
+                }
+
+                // parse the attributes
+                if ( currentTag != null ) {
+                    List<String> attributeTokens = StringUtils.getGroups( 
ATTRIBUTE_REGEX, line );
+                    for ( String token : attributeTokens ) {
+                        String attributeName = token.substring(
+                                token.indexOf( '.' ) + 1 );
+
+                        currentTag.addKey( attributeName, "string", '*', true 
);
+                    }
+
+                    List<String> childTokens = StringUtils.getGroups( 
ATTRIBUTE_CHILD_REGEX, line );
+                    for ( String token : childTokens ) {
+                        String childName = token.substring(
+                                token.indexOf( '"' ) + 1,
+                                token.lastIndexOf( '"' ) );
+
+                        currentTag.addKey( childName, "string", '*', true );
+                    }
                 }
             }
         }


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to