{"id":1687,"date":"2018-12-16T13:15:55","date_gmt":"2018-12-16T18:15:55","guid":{"rendered":"http:\/\/codinggorilla.com\/?p=1687"},"modified":"2019-02-02T10:34:45","modified_gmt":"2019-02-02T15:34:45","slug":"refinements-to-piggy","status":"publish","type":"post","link":"http:\/\/165.227.223.229\/index.php\/2018\/12\/16\/refinements-to-piggy\/","title":{"rendered":"Refinements to Piggy"},"content":{"rendered":"<p>While I now have Piggy producing a p\/invoke header for a Clang-C header file, there are several improvements that I&#8217;ve made or will make soon.<\/p>\n<p><!--more--><\/p>\n<p>In order to have code blocks and text blocks recognized as a single token by the Antlr-generated lexer and parser, I needed to make new delimiters for code and text blocks. C# code is now contained in <em><strong>{{ &#8230; }}<\/strong><\/em>; Text is now contained in <em><strong>[[ &#8230;.\u00c2\u00a0]]<\/strong><\/em>.<\/p>\n<p>Antlr implements a means to allow user code to be inserted into parsers via a <em><strong>header<\/strong><\/em> option. Following by example, I&#8217;m going to generate a class to contain all code blocks that will be JIT compiled by the tool. The <em><strong>vars[]<\/strong><\/em> dictionary will be removed because the user will be able to add code with a <em><strong>header<\/strong><\/em>\u00c2\u00a0option in the spec file. Note, separate compilation and referenced assemblies do not work yet&#8211;I am getting load assembly errors.<\/p>\n<p>Since a symbol table is a basic requirement for code generation, I&#8217;m going to be adding a symbol table to Piggy. In order to not re-invent the wheel, I&#8217;ve ported <a href=\"https:\/\/github.com\/antlr\/symtab\">Parr&#8217;s Symbol Table<\/a> into C#. However, it seems that it may need changes for enums.<\/p>\n<p>The syntax for passes and templates is now changed. Templates are just parenthesized expressions, with the keyword template no longer used. Passes use\u00c2\u00a0curly braces to enclose all the templates for the pass: <em><strong>pass ID { template* }<\/strong><\/em>.<\/p>\n<p>SWIG allows a user include other SWIG input files via a <em><strong>%include<\/strong><\/em> directive. Follow by example, I&#8217;m going to be adding an include mechanism for Piggy specs. The reason is that it&#8217;s a little much to always supply the full pass\/template patterns for any conversion. Instead, you should be able to load the base conversion rules,\u00c2\u00a0then specialize that. I haven&#8217;t worked all this out, but I will very soon.<\/p>\n<p>A useful feature in C# is string interpolation. In Piggy, C# interpolation is possible for attribute\u00c2\u00a0values, e.g., in the pattern <em><strong>( SrcRange=$&#8221;{Templates.limit}&#8221; &#8230; )<\/strong><\/em>. which gets the string value <em><strong>limit<\/strong><\/em> that is part of the <em><strong>Templates<\/strong><\/em> class (where all code blocks go), currently a <em><strong>Regex<\/strong><\/em> pattern to match on <em><strong>clang-c<\/strong><\/em>. The result is an extremely powerful method of changing the pattern matcher based upon user code block values!!<\/p>\n<p>&#8211;Ken<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While I now have Piggy producing a p\/invoke header for a Clang-C header file, there are several improvements that I&#8217;ve made or will make soon.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/1687"}],"collection":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/comments?post=1687"}],"version-history":[{"count":0,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/1687\/revisions"}],"wp:attachment":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/media?parent=1687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/categories?post=1687"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/tags?post=1687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}