Rebol[ title: "C# Code Generator" author: "http://reboltutorial.com/blog/create-dsl-2/" version: 1.0.0 ] phrase: ask "Enter your phrase: " rule: ["Create " ["a" | ] copy Language to " class" thru " with " copy attributes-list to end (generate-code)] parse phrase rule generate-code: func[][ attributes: parse/all attributes-list "," switch Language [ "C#" [generate-code-csharp attributes] ] /default [print ["Language" Language "not yet implemented"]] ] generate-code-csharp: func[attributes][ namespace: if/else ((answer: ask "namespace (ex.:MyApp): ") = "") ["MyApp"][answer] class-name: if/else ((answer: ask "class-name (ex.: Cperson): ") = "") ["CPerson"][answer] private-prefix: "_" code-template: {using System; // Generated by http://www.reboltutorial.com // Template based on http://www.csharpfriends.com/demos/csharp_class_generator.aspx namespace <%namespace%> { public class <%class-name%> { // private members <%private-members%> // empty constructor public <%class-name%> () { } // full constructor public <%class-name%> (<%private-constructor-arguments-list%>) { <%private-constructor-body%> } // public accessors <%public-accessors%> } } }; end of C# class template private-members-template: {<%attribute-type%> <%private-prefix%><%attribute-name%>;} private-constructor-arguments-list-template: {<%attribute-type%> <%attribute-name%>} private-constructor-body-template: {this.<%private-prefix%><%attribute-name%> = <%attribute-name%>;} public-accessors-template: {public <%attribute-type%> <%attribute-name%> { get { return <%private-prefix%><%attribute-name%>;} set { <%private-prefix%><%attribute-name%> = value; } } } private-members: "" private-constructor-arguments-list: "" private-constructor-body: "" public-accessors: "" n: length? attributes counter: 0 foreach attribute attributes [ counter: counter + 1 attribute-name: trim/all attribute; remove all whitespaces attribute-type: if/else ((answer: ask ["attribute-type for" attribute "(ex. string) : " ]) = "") ["string"][answer] if (counter > 1) [ append private-members " " append private-constructor-body " " append public-accessors " " ] append private-members build-markup private-members-template append private-constructor-arguments-list build-markup private-constructor-arguments-list-template append private-constructor-body build-markup private-constructor-body-template append public-accessors build-markup public-accessors-template if (counter < n) [ append private-members newline append private-constructor-arguments-list ", " append private-constructor-body newline ] ] source-code: build-markup code-template write clipboard:// source-code Print "source code copied into clipboard ..." input ]