Ejemplo n.º 1
0
        public CodeWriter Class( RuleClassStatement ruleClassStatement, string fileName )
        {
            var writer = new CodeWriter();

            writer.Indent = 0;
            writer.Append( "public partial class " );
            writer.AppendText( ruleClassStatement.Name );
            writer.Indent = 0;
            writer.AppendLine( " : GeneratorBase" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in ruleClassStatement.RuleMethodStatements.OfType<MethodStatement>())
                {
                    temp = this.Invoke( "Method", item, fileName );
                    list.Add( temp );
                }
                foreach (var item in ruleClassStatement.MatchMethodGroups.Where( mmg => mmg.IsMatched ).SelectMany( mmg => mmg.RuleMethodStatements ).Select( ms => ms.MatchMethodStatement ))
                {
                    temp = this.Invoke( "Match", item, fileName );
                    list.Add( temp );
                }
                foreach (var item in ruleClassStatement.MatchMethodGroups.Where( mmg => mmg.IsMatched ).SelectMany( mmg => mmg.RuleMethodStatements ))
                {
                    temp = this.Invoke( "Rule", item, fileName, false, true );
                    list.Add( temp );
                }
                foreach (var item in ruleClassStatement.MatchMethodGroups.Where( mmg => mmg.IsMatched ).SelectMany( mmg => mmg.DefaultStatements ))
                {
                    temp = this.Invoke( "Rule", item, fileName, true,  true );
                    list.Add( temp );
                }
                foreach (var item in ruleClassStatement.MatchMethodGroups.Where( mmg => !mmg.IsMatched ).SelectMany( mmg => mmg.DefaultStatements ))
                {
                    temp = this.Invoke( "Rule", item, fileName, false, false );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.Append( "}" );

            return writer;
        }
Ejemplo n.º 2
0
        public CodeWriter Generate( string @namespace, RuleClassStatement ruleClassStatement, string fileName )
        {
            var writer = new CodeWriter();

            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in ruleClassStatement.UsingStatements.Select( u => u.Namespace ).Concat( defaultNamespaces ).Distinct())
                {
                    temp = this.Invoke( "Using", item );
                    list.Add( temp );
                }

                writer.AppendType = AppendType.EmptyLastLine;
                for (var listI = 0; listI < list.Count; listI++)
                {
                    var codeWriter = list[listI];
                    writer.Append( codeWriter );
                    if (listI < list.Count - 1)
                        writer.AppendText( "\r\n" );
                }
                writer.AppendType = AppendType.EmptyLastLine;
            }
            writer.Indent = 0;
            writer.AppendLine();
            writer.AppendLine();
            if (@namespace != null)
            {
            writer.Indent = 0;
            writer.Append( "namespace " );
            writer.AppendText( @namespace );
            writer.Indent = 0;
            writer.AppendLine();
            writer.AppendLine( "{" );
            writer.Indent = 1;
            writer.Append( this.Invoke( "Class", ruleClassStatement, fileName ) );
            writer.Indent = 0;
            writer.AppendLine();
            writer.AppendLine( "}" );
            }
            else
            {
            writer.Append( this.Invoke( "Class", ruleClassStatement, fileName ) );
            writer.Indent = 0;
            writer.AppendLine();
            }

            return writer;
        }
Ejemplo n.º 3
0
 void WolfGenerator()
 {
     List<UsingStatement> usingStatementList = null;
     List<RuleClassMethodStatement> ruleMethodStatementList = null;
     string name;
     Expect(2);
     Token start = t;
     Expect(1);
     name = t.val;
     Expect(10);
     while (la.kind == 9) {
     UsingStatement usingStatement;
     Using(out usingStatement);
     if (usingStatementList == null) usingStatementList = new List<UsingStatement>();
     usingStatementList.Add( usingStatement );
     }
     while (la.kind == 3 || la.kind == 7 || la.kind == 8) {
     if (la.kind == 3 || la.kind == 8) {
         RuleMethodStatement ruleMethod;
         RuleMethod(out ruleMethod);
         if (ruleMethodStatementList == null)
            ruleMethodStatementList = new List<RuleClassMethodStatement>();
         ruleMethodStatementList.Add( ruleMethod );
     } else {
         MethodStatement method;
         Method(out method);
         if (ruleMethodStatementList == null)
            ruleMethodStatementList = new List<RuleClassMethodStatement>();
         ruleMethodStatementList.Add( method );
     }
     }
     while (!(la.kind == 0 || la.kind == 11)) {SynErr(34); Get();}
     ExpectWeak(11, 1);
     ruleClassStatement = new RuleClassStatement( new StatementPosition( start, t ), name, usingStatementList, ruleMethodStatementList );
 }