Package net.percederberg.grammatica.code.csharp

Examples of net.percederberg.grammatica.code.csharp.CSharpMethod


            modifiers = CSharpClass.PUBLIC;
        } else {
            modifiers = CSharpClass.INTERNAL;
        }
        this.cls = new CSharpClass(modifiers, name, "Tokenizer");
        this.initMethod = new CSharpMethod(CSharpMethod.PRIVATE,
                                           "CreatePatterns",
                                           "",
                                           "void");
        initializeCode();
    }
View Full Code Here


        this.cls = new CSharpClass(modifiers,
                                   name,
                                   "RecursiveDescentParser");
        this.enm = new CSharpEnumeration(CSharpEnumeration.PRIVATE,
                                          "SynteticPatterns");
        this.initMethod = new CSharpMethod(CSharpMethod.PRIVATE,
                                           "CreatePatterns",
                                           "",
                                           "void");
        initializeCode(tokenizer, analyzer);
    }
View Full Code Here

     * @param analyzer       the analyzer file generator
     */
    private void initializeCode(CSharpTokenizerFile tokenizer,
                                CSharpAnalyzerFile analyzer) {
        CSharpConstructor  constr;
        CSharpMethod       method;
        String             str;

        // Add using
        file.addUsing(new CSharpUsing("System.IO"));
        file.addUsing(new CSharpUsing("PerCederberg.Grammatica.Runtime"));

        // Add namespace
        if (gen.getNamespace() == null) {
            file.addClass(cls);
        } else {
            CSharpNamespace n = new CSharpNamespace(gen.getNamespace());
            n.addClass(cls);
            file.addNamespace(n);
        }

        // Add file comment
        str = file.toString() + "\n\n" + gen.getFileComment();
        file.addComment(new CSharpComment(CSharpComment.BLOCK, str));

        // Add type comment
        cls.addComment(new CSharpComment(TYPE_COMMENT));

        // Add enumeration
        cls.addEnumeration(enm);
        enm.addComment(new CSharpComment(ENUM_COMMENT));

        // Add constructor
        constr = new CSharpConstructor("TextReader input");
        cls.addConstructor(constr);
        constr.addComment(new CSharpComment(CONSTRUCTOR1_COMMENT));
        constr.addInitializer("base(input)");
        constr.addCode("CreatePatterns();");

        // Add constructor
        constr = new CSharpConstructor("TextReader input, " +
                                       analyzer.getClassName() + " analyzer");
        cls.addConstructor(constr);
        constr.addComment(new CSharpComment(CONSTRUCTOR2_COMMENT));
        constr.addInitializer("base(input, analyzer)");
        constr.addCode("CreatePatterns();");

        // Add tokenizer factory method
        method = new CSharpMethod(CSharpMethod.PROTECTED + CSharpMethod.OVERRIDE,
                                  "NewTokenizer",
                                  "TextReader input",
                                  "Tokenizer");
        method.addComment(new CSharpComment(FACTORY_COMMENT));
        method.addCode("return new " + tokenizer.getClassName() + "(input);");
        cls.addMethod(method);

        // Add init method
        cls.addMethod(initMethod);
        initMethod.addComment(new CSharpComment(INIT_METHOD_COMMENT));
View Full Code Here

        } else {
            modifiers = CSharpClass.INTERNAL + CSharpClass.ABSTRACT;
        }
        this.cls = new CSharpClass(modifiers, name, "Analyzer");
        modifiers = CSharpMethod.PUBLIC + CSharpMethod.OVERRIDE;
        this.enter = new CSharpMethod(modifiers,
                                      "Enter",
                                      "Node node",
                                      "void");
        this.exit = new CSharpMethod(modifiers,
                                     "Exit",
                                     "Node node",
                                     "Node");
        this.child = new CSharpMethod(modifiers,
                                      "Child",
                                      "Production node, Node child",
                                      "void");
        initializeCode();
    }
View Full Code Here

     *
     * @param name           the node name
     * @param type           the node type
     */
    private void addEnterMethod(String name, String type) {
        CSharpMethod  m;

        m = new CSharpMethod(CSharpMethod.PUBLIC + CSharpMethod.VIRTUAL,
                             "Enter" + name,
                             type + " node",
                             "void");
        m.addComment(new CSharpComment(ENTER_COMMENT));
        cls.addMethod(m);
    }
View Full Code Here

     *
     * @param name           the node name
     * @param type           the node type
     */
    private void addExitMethod(String name, String type) {
        CSharpMethod  m;

        m = new CSharpMethod(CSharpMethod.PUBLIC + CSharpMethod.VIRTUAL,
                             "Exit" + name,
                             type + " node",
                             "Node");
        m.addComment(new CSharpComment(EXIT_COMMENT));
        m.addCode("return node;");
        cls.addMethod(m);
    }
View Full Code Here

     * Adds an add child method to this file.
     *
     * @param name           the node name
     */
    private void addChildMethod(String name) {
        CSharpMethod  m;

        m = new CSharpMethod(CSharpMethod.PUBLIC + CSharpMethod.VIRTUAL,
                             "Child" + name,
                             "Production node, Node child",
                             "void");
        m.addComment(new CSharpComment(CHILD_COMMENT));
        m.addCode("node.AddChild(child);");
        cls.addMethod(m);
    }
View Full Code Here

TOP

Related Classes of net.percederberg.grammatica.code.csharp.CSharpMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.