I am very, very, old school, grew up with ASM and Macro Assembly. I really appreciate this.
I prefer to write Go code in a purely idiomatic way but there are times i just want to finish the job and ship it. Thank you for sharing. On Sunday, March 24, 2019 at 4:23:52 PM UTC-5, Ecstatic Coder wrote: > > Just to inform you that I've just released an first version of *Generis*, > a lightweight code preprocessor adding the following features to the Go > language : > > - Generic code definition and instantiation. > - Conditional compilation. > - ERB-like HTML templating. > - Allman to K&R style conversion. > > https://github.com/senselogic/GENERIS > > It's very similar in function to both Ego and Genny, but implemented as a > free-form C++-like preprocessor. > > Probably of no use at all for anyone who likes to develop Go code in a > purely idiomatic way, which obviously I'm not... > > > *Sample* > > package main; > // -- IMPORTS > import ( > "html" > "io" > "log" > "net/http" > "strconv" > ); > // -- DEFINITIONS > > #define DebugMode > #as true > // ~~ > > #define HttpPort > #as 8080 > // ~~ > > #define WriteLine( {{text}} ) > #as log.Println( {{text}} ) > // ~~ > > #define local {{variable}} : {{type}}; > #as var {{variable}} {{type}}; > // ~~ > > #define DeclareStack( {{type}}, {{name}} ) > #as > // -- TYPES > > type {{name}}Stack struct > { > ElementArray []{{type}}; > } > > // -- INQUIRIES > > func ( stack * {{name}}Stack ) IsEmpty( > ) bool > { > return len( stack.ElementArray ) == 0; > } > > // -- OPERATIONS > > func ( stack * {{name}}Stack ) Push( > element {{type}} > ) > { > stack.ElementArray = append( stack.ElementArray, element ); > } > > // ~~ > > func ( stack * {{name}}Stack ) Pop( > ) {{type}} > { > local > element : {{type}}; > > element = stack.ElementArray[ len( stack.ElementArray ) - 1 ]; > > stack.ElementArray = stack.ElementArray[ : len( stack.ElementArray ) > - 1 ]; > > return element; > } > #end > // ~~ > > #define DeclareStack( {{type}} ) > #as DeclareStack( {{type}}, {{type:PascalCase}} ) > // -- TYPES > DeclareStack( string )DeclareStack( int32 ) > // -- FUNCTIONS > func HandleRootPage( > response_writer http.ResponseWriter, > request * http.Request > ) > { > local > boolean : bool; > local > natural : uint; > local > integer : int; > local > real : float64; > local > escaped_text, > text : string; > local > integer_stack : Int32Stack; > > boolean = true; > natural = 10; > integer = 20; > real = 30.0; > text = "text"; > escaped_text = "<escaped text/>"; > > integer_stack.Push( 10 ); > integer_stack.Push( 20 ); > integer_stack.Push( 30 ); > > #write response_writer > <!DOCTYPE html> > <html lang="en"> > <head> > <meta charset="utf-8"> > <title><%= request.URL.Path %></title> > </head> > <body> > <% if ( boolean ) { %> > <%= "URL : " + request.URL.Path %> > <br/> > <%@ natural %> > <%# integer %> > <%& real %> > <br/> > <%~ text %> > <%= escaped_text %> > <%= "<%% ignored %%>" %> > <%% ignored %%> > <% } %> > <br/> > Stack : > <br/> > <% for !integer_stack.IsEmpty() { %> > <%# integer_stack.Pop() %> > <% } %> > </body> > </html> > #end > } > // ~~ > func main() > { > http.HandleFunc( "/", HandleRootPage ); > > #if DebugMode > WriteLine( "Listening on http://localhost:HttpPort" ); > #end > > log.Fatal( > http.ListenAndServe( ":8080", nil ) > ); > } > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.