Example #1
0
        public CodeWriter Rule( RuleMethodStatement ruleMethodStatement, string fileName, bool isDefault, bool generateAttribute )
        {
            var writer = new CodeWriter();

            if (generateAttribute)
            {
            writer.Indent = 0;
            writer.Append( "[RuleMethod( \"" );
            writer.AppendText( ruleMethodStatement.Name );
            writer.Indent = 0;
            writer.Append( "\", " );
            if (ruleMethodStatement.MatchMethodStatement != null){
            writer.Indent = 0;
            writer.Append( "\"" );
            writer.AppendText( ruleMethodStatement.MatchMethodStatement.Name );
            writer.Indent = 0;
            writer.Append( "\"" );
            }else{
            writer.Indent = 0;
            writer.Append( "null" );
            }
            writer.Indent = 0;
            writer.Append( ", \"" );
            writer.AppendText( fileName );
            writer.Indent = 0;
            writer.AppendLine( "\" )]" );
            }
            writer.Indent = 0;
            writer.Append( "public CodeWriter " );
            writer.AppendText( ruleMethodStatement.Name );
            if (ruleMethodStatement.MatchMethodStatement != null){
            writer.Indent = 0;
            writer.Append( "_" );
            writer.AppendText( ruleMethodStatement.MatchMethodStatement.Name );
            }else if (isDefault){
            writer.Indent = 0;
            writer.Append( "_Default" );
            }
            writer.Indent = 0;
            writer.Append( "(" );
            writer.Append( this.Invoke( "MethodParamenters", ruleMethodStatement.Variables ) );
            writer.Indent = 0;
            writer.AppendLine( ")" );
            writer.AppendLine( "{" );
            writer.Indent = 1;
            writer.AppendLine( "var writer = new CodeWriter();" );
            writer.Indent = 0;
            writer.AppendLine();
            writer.Indent = 1;
            {
                var list = new List<CodeWriter>();
                CodeWriter temp;

                foreach (var item in ruleMethodStatement.Statements)
                {
                    temp = this.Invoke( "Statement", item, "writer" );
                    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();
            writer.Indent = 1;
            writer.AppendLine( "return writer;" );
            writer.Indent = 0;
            writer.Append( "}" );

            return writer;
        }
Example #2
0
 void RuleMethod(out RuleMethodStatement statement)
 {
     string methodName; IList<Variable> variables;
     List<Variable> variableList;
     List<RuleStatement> statements = new List<RuleStatement>();
     bool isStart = true;
     ValueStatement valueStatement;
     JoinStatement joinStatement;
     CodeStatement codeStatement;
     CallStatement callStatement;
     MatchMethodStatement matchStatement = null;
     Token start = la;
     if (la.kind == 8) {
     MatchMethod(out matchStatement);
     }
     while (!(la.kind == 0 || la.kind == 3)) {SynErr(35); Get();}
     Expect(3);
     Expect(1);
     methodName = t.val;
     Expect(22);
     Variables(out variableList);
     ExpectWeak(23, 1);
     while (!(la.kind == 0 || la.kind == 10)) {SynErr(36); Get();}
     Expect(10);
     variables = variableList == null ? null : variableList.AsReadOnly();
     while (StartOf(2)) {
     if (la.kind == 32) {
         Get();
         AddStatement( isStart, statements, la.kind == _end, t );
     } else if (la.kind == 12) {
         Value(out valueStatement);
         statements.Add( valueStatement ); isStart = false;
     } else if (la.kind == 4) {
         Join(out joinStatement);
         statements.Add( joinStatement ); isStart = false;
     } else if (la.kind == 13) {
         isStart = false;
         Code(out codeStatement, ref isStart);
         statements.Add( codeStatement );
     } else {
         Call(out callStatement);
         statements.Add( callStatement ); isStart = false;
     }
     }
     while (!(la.kind == 0 || la.kind == 11)) {SynErr(37); Get();}
     Expect(11);
     statement = new RuleMethodStatement( new StatementPosition( start, t ), matchStatement, methodName, variables, statements );
 }