Author: timotei
Date: Tue Jul 26 17:26:04 2011
New Revision: 50411
URL: http://svn.gna.org/viewcvs/wesnoth?rev=50411&view=rev
Log:
eclipse plugin: Create a simple wml parser that
parses the xtext's resource of a cfg file into a WMLConfig
structure
Added:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
Modified:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java?rev=50411&r1=50410&r2=50411&view=diff
==============================================================================
---
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
(original)
+++
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
Tue Jul 26 17:26:04 2011
@@ -26,8 +26,6 @@
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.ecore.EObject;
import org.wesnoth.Constants;
import org.wesnoth.Logger;
import org.wesnoth.Messages;
@@ -41,12 +39,9 @@
import org.wesnoth.utils.ExternalToolInvoker;
import org.wesnoth.utils.ResourceUtils;
import org.wesnoth.utils.StringUtils;
-import org.wesnoth.utils.WMLUtils;
import org.wesnoth.utils.WMLTools;
import org.wesnoth.utils.WorkspaceUtils;
-import org.wesnoth.wml.WMLKey;
-import org.wesnoth.wml.WMLRoot;
-import org.wesnoth.wml.WMLTag;
+import org.wesnoth.wml.core.SimpleWMLParser;
import org.wesnoth.wml.core.WMLConfig;
/**
@@ -316,62 +311,9 @@
monitor.subTask( String.format(
Messages.WesnothProjectBuilder_22, filePath ) );
WMLConfig config = projectCache_.getWMLConfig(
filePath );
- WMLRoot root = ResourceUtils.getWMLRoot( file );
- TreeIterator<EObject> itor = root.eAllContents(
);
- WMLTag currentTag = null;
- String currentTagName = "";
-
- while ( itor.hasNext( ) ) {
- EObject object = itor.next( );
-
- if ( object instanceof WMLTag ) {
- currentTag = ( WMLTag ) object;
- currentTagName = currentTag.getName( );
-
- if ( currentTagName.equals( "scenario"
) )
- config.IsScenario = true;
- else if ( currentTagName.equals(
"campaign" ) )
- config.IsCampaign = true;
- }
- else if ( object instanceof WMLKey ) {
- if ( currentTag != null ) {
- WMLKey key = ( WMLKey ) object;
- String keyName = key.getName( );
-
- if ( keyName.equals( "id" ) ) {
- if ( currentTagName.equals(
"scenario" ) )
- config.ScenarioId =
WMLUtils.getKeyValue( key.getValue( ) );
- else if (
currentTagName.equals( "campaign" ) )
- config.CampaignId =
WMLUtils.getKeyValue( key.getValue( ) );
- }
- }
- }
- }
-
- System.out.println( "Config: " + config );
-
-// WMLSaxHandler handler = (WMLSaxHandler)
ResourceUtils.
-// getWMLSAXHandlerFromResource(
-//
PreprocessorUtils.getInstance().getPreprocessedFilePath(file, false,
false).toString(),
-// new
WMLSaxHandler(file.getLocation().toOSString()));
-//
-// if (handler != null)
-// {
-// WMLConfig cfg = handler.getConfigFile();
-// projectCache_.getWMLConfigs().put(
file.getProjectRelativePath( ).toString( ), cfg);
-// if (cfg.IsScenario)
-// {
-// if ( StringUtils.isNullOrEmpty(
cfg.ScenarioId ) )
-// {
-//
Logger.getInstance().log("added scenarioId [" + cfg.ScenarioId + //$NON-NLS-1$
-// "] for
file: " + filePath ); //$NON-NLS-1$
-// }
-// else
-// {
-//
projectCache_.getWMLConfigs().remove( filePath );
-// }
-// }
-// }
+ SimpleWMLParser parser = new SimpleWMLParser(
file, config );
+ parser.parse( );
+
monitor.worked(10);
} catch (Exception e)
Added:
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java?rev=50411&view=auto
==============================================================================
---
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java
(added)
+++
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/wml/core/SimpleWMLParser.java
Tue Jul 26 17:26:04 2011
@@ -1,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2011 by Timotei Dolean <[email protected]>
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+
*******************************************************************************/
+package org.wesnoth.wml.core;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.wesnoth.utils.ResourceUtils;
+import org.wesnoth.utils.WMLUtils;
+import org.wesnoth.wml.WMLKey;
+import org.wesnoth.wml.WMLRoot;
+import org.wesnoth.wml.WMLTag;
+
+/**
+ * A simple WML Parser that parses a xtext WML Config file resource
+ */
+public class SimpleWMLParser
+{
+ protected WMLConfig config_;
+ protected IFile file_;
+
+ /**
+ * Creates a new parser for the specified file
+ */
+ public SimpleWMLParser( IFile file )
+ {
+ file_ = file;
+ config_ = new WMLConfig( file.getProjectRelativePath( ).toString( ) );
+ }
+
+ /**
+ * Creates a new parser and fills the specified config file
+ */
+ public SimpleWMLParser( IFile file, WMLConfig config )
+ {
+ if ( config == null )
+ throw new IllegalArgumentException( "The config must not be null."
);
+
+ config_ = config;
+ file_ = file;
+ }
+
+ /**
+ * Parses the config. The results will be available in {@link
#getParsedConfig()}
+ */
+ public void parse()
+ {
+ WMLRoot root = ResourceUtils.getWMLRoot( file_ );
+ TreeIterator<EObject> itor = root.eAllContents( );
+ WMLTag currentTag = null;
+ String currentTagName = "";
+
+ while ( itor.hasNext( ) ) {
+ EObject object = itor.next( );
+
+ if ( object instanceof WMLTag ) {
+ currentTag = ( WMLTag ) object;
+ currentTagName = currentTag.getName( );
+
+ if ( currentTagName.equals( "scenario" ) )
+ config_.IsScenario = true;
+ else if ( currentTagName.equals( "campaign" ) )
+ config_.IsCampaign = true;
+ }
+ else if ( object instanceof WMLKey ) {
+ if ( currentTag != null ) {
+ WMLKey key = ( WMLKey ) object;
+ String keyName = key.getName( );
+
+ if ( keyName.equals( "id" ) ) {
+ if ( currentTagName.equals( "scenario" ) )
+ config_.ScenarioId = WMLUtils.getKeyValue(
key.getValue( ) );
+ else if ( currentTagName.equals( "campaign" ) )
+ config_.CampaignId = WMLUtils.getKeyValue(
key.getValue( ) );
+ }
+ }
+ }
+ }
+
+ System.out.println( "parsed config: " + config_ );
+
+ }
+
+
+ public WMLConfig getParsedConfig()
+ {
+ return config_;
+ }
+}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits