| /*********************************************************************** |
| * Copyright (c) 2007 OptXware Research and Development LLC. |
| * All rights reserved. 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 |
| * |
| * Contributors: |
| * Daniel Varro - Initial API and implementation |
| ************************************************************************ |
| */ |
| |
| package org.eclipse.viatra2.lpgparser; |
| |
| //import java.io.File; |
| //import java.io.IOException; |
| //import java.util.HashMap; |
| //import java.util.Map; |
| // |
| //import org.eclipse.emf.common.util.URI; |
| //import org.eclipse.emf.ecore.resource.Resource; |
| //import org.eclipse.emf.ecore.resource.ResourceSet; |
| //import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
| //import org.eclipse.emf.ecore.xmi.XMLResource; |
| //import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; |
| // |
| //import org.eclipse.viatra2.core.IModelSpace; |
| //import org.eclipse.viatra2.framework.FrameworkManager; |
| //import org.eclipse.viatra2.framework.IFramework; |
| //import org.eclipse.viatra2.gtasmmodel.gtasm.metamodel.asm.definitions.Module; |
| //import org.eclipse.viatra2.natives.ASMNativeFunction; |
| import org.eclipse.viatra2.lpgparser.ast.ASTNode; |
| |
| |
| /** |
| * This class is used only for testing purposes. |
| * |
| * @deprecated |
| * @author Daniel Varro |
| * |
| */ |
| public class Main |
| { |
| public static void main(String[] args) throws Exception |
| { |
| // ErrorInformation errorInfo = new ErrorInformation("Error {1}", ErrorKind.PARSE_ERROR); |
| // String[] context = new String[] {"Dani"}; |
| // errorInfo.bind(context); |
| // System.out.println(errorInfo.getMessage()); |
| Option option; |
| VTCLLexer vtcl_lexer; |
| VTCLParser vtcl_parser; |
| |
| ASTNode ast; |
| // |
| //// IFramework framework = FrameworkManager.getInstance().createFramework(); |
| //// framework.mergeFile("vpmlFileName"); |
| //// IModelSpace modelSpace = framework.getTopmodel(); |
| // |
| try |
| { |
| option = new Option(args); |
| option.readInputChars(); |
| vtcl_lexer = new VTCLLexer(option.getInputChars(), option.getFileName()); // Create the lexer |
| vtcl_lexer.setTab(4); |
| vtcl_parser = new VTCLParser(vtcl_lexer); // Create the parser |
| vtcl_lexer.lexer(vtcl_parser); // Lex the stream to produce the token stream |
| if (option.dumpTokens()) |
| { |
| System.out.println("\n****Output Tokens: \n"); |
| vtcl_parser.dumpTokens(); |
| } |
| ast = vtcl_parser.parser(100); // Parse the token stream to produce an AST |
| if (ast == null) { |
| System.out.println("****Failure"); |
| System.out.println("Number of parser errors: " + vtcl_parser.getAllErrorInfos().size()); |
| for (int i = 0; i < vtcl_parser.getAllErrorInfos().size(); i++) { |
| System.out.println(vtcl_parser.getAllErrorInfos().get(i).getMessageWithLocation()); |
| } |
| } |
| else |
| { |
| System.out.println("*** Parsing completed ***"); |
| // String result = (String) ast.accept(new VTCLResultVisitor()); |
| // System.out.println(result.toString()); |
| // Machine machine = (Machine) result.getMachine().get(0); |
| // // Initializing a sample model space |
| // IFramework framework = FrameworkManager.getInstance().createFramework(); |
| // framework.mergeFile("c:\\java\\eclipse_sensoria\\eclipse\\workspace\\viatra_vtcl_lpg_parser\\tests\\example.vpml"); |
| // IModelSpace modelSpace = framework.getTopmodel(); |
| // // Retrieve native functions from framework |
| // ASMNativeFunction[] asmNativeFunctions = framework.getNativeFunctionManager().getAllNativeFunctions(); |
| // |
| // // Starting the model builder |
| // VTCLModelBuilder modelBuilder = new VTCLModelBuilder(modelSpace, asmNativeFunctions); |
| // Module vtclModule = (Module) ast.accept(modelBuilder); |
| // |
| // Reporting parser errors |
| System.out.println("Number of parser errors: " + vtcl_parser.getAllErrorInfos().size()); |
| for (int i = 0; i < vtcl_parser.getAllErrorInfos().size(); i++) { |
| System.out.println(vtcl_parser.getAllErrorInfos().get(i).getMessageWithLocation()); |
| } |
| // // Reporting model resolution and validation errors |
| // System.out.println("*** Starting model builder ***"); |
| // VTCLModelResolver modelResolver = modelBuilder.getModelResolver(); |
| // System.out.println("Number of validation errors: " + |
| // modelResolver.getAllReferenceErrorInfos().size()); |
| // for (int i = 0; i < modelResolver.getAllReferenceErrorInfos().size(); i++) { |
| // System.out.println(modelResolver.getAllReferenceErrorInfos().get(i).getMessageWithLocation()); |
| // |
| // } |
| // |
| // // Serializing to XMI |
| // // Create a resource set. |
| // ResourceSet resourceSet = new ResourceSetImpl(); |
| // |
| // // Register the default resource factory -- only needed for stand-alone! |
| // resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put( |
| // Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); |
| // |
| // // Get the URI of the model file. |
| // URI fileURI = URI.createFileURI(new File("mygtasmmodel.xmi").getAbsolutePath()); |
| // |
| // // Create a resource for this file. |
| // Resource resource = resourceSet.createResource(fileURI); |
| // |
| // // Add the book and writer objects to the contents. |
| // resource.getContents().add(vtclModule); |
| // |
| // // Save the contents of the resource to the file system. |
| // try |
| // { |
| // Map options = new HashMap(); |
| // options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); |
| // resource.save(options); |
| //// resource.save(Collections.EMPTY_MAP); |
| // } catch (IOException e) { |
| // e.printStackTrace(); |
| // } |
| // |
| // // Print all contents |
| //// Iterator iter = EcoreUtil.getAllContents(vtclModule, false); |
| //// while (iter.hasNext()) { |
| //// Object obj = iter.next(); |
| //// if (obj instanceof GTASMElement) { |
| //// System.out.println(((GTASMElement) obj).eClass().getName() + "->" + |
| //// ((GTASMElement) obj).getName()); |
| //// } |
| //// } |
| // |
| } |
| |
| return; |
| } |
| catch (Exception e) |
| { |
| System.err.println(e.getMessage()); |
| e.printStackTrace(); |
| } |
| } |
| } |