XML Parser Error: tag mismatch, in line 182 of /code/class_MacroInterpreter.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE language SYSTEM "klayout_doc.dtd"> <doc><title>API reference - Class MacroInterpreter</title> <keyword name="MacroInterpreter"/> <p><link href="/about/rba_notation.xml"/></p> <p><b>Module</b>: <a href="/code/module_lay.xml">lay</a></p><p><b>Description</b>: A custom interpreter for a DSL (domain specific language)</p> <h2-index/> <p></p><p>DSL interpreters are a way to provide macros written in a language specific for the application. One example are DRC scripts which are written in some special language optimized for DRC ruledecks. Interpreters for such languages can be built using scripts itself by providing the interpreter implementation through this object.</p><p>An interpreter implementation involves at least these steps:</p><p><ul> <li> Derive a new object from RBA::MacroInterpreter </li> <li> Reimplement the <a href="#m_execute">execute</a> method for the actual execution of the code </li> <li> In the initialize method configure the object using the attribute setters like <a href="#m_suffix=">suffix=</a> and register the object as DSL interpreter (in that order) </li> <li> Create at least one template macro in the initialize method </li> </ul></p><p>Template macros provide a way for the macro editor to present macros for the new interpreter in the list of templates. Template macros can provide menu bindings, shortcuts and some initial text for example</p><p>The simple implementation can be enhanced by providing more information, i.e. syntax highlighter information, the debugger to use etc. This involves reimplementing further methods, i.e. "syntax_scheme".</p><p>This is a simple example for an interpreter in Ruby. Is is registered under the name 'simple-dsl' and just evaluates the script text:</p><p><pre> class SimpleInterpreter < RBA::MacroInterpreter # Constructor def initialize self.description = "A test interpreter" # Registers the new interpreter register("simple-dsl") # create a template for the macro editor: # Name is "new_simple", the description will be "Simple interpreter macro" # in the "Special" group. mt = create_template("new_simple") mt.description = "Special;;Simple interpreter macro" end # Implements the execute method def execute(macro) eval(macro.text, nil, macro.path) end end # Register the new interpreter SimpleInterpreter::new </pre></p><p>Please note that such an implementation is dangerous because the evaluation of the script happens in the context of the interpreter object. In this implementation the script could redefine the execute method for example. This implementation is provided as an example only. A real implementation should add execution of prolog and epilog code inside the execute method and proper error handling.</p><p>In order to make the above code effective, store the code in an macro, set "early auto-run" and restart KLayout.</p><p>This class has been introduced in version 0.23. </p> <h2>Public constructors</h2> <table> <tr class="row0"> <td>new MacroInterpreter ptr</td><td><b><a href="#method21">new</a></b></td><td></td><td>Creates a new object of this class</td></tr> </table> <h2>Public methods</h2> <table> <tr class="row0"> <td></td><td>void</td><td><b><a href="#method5">_create</a></b></td><td></td><td>Ensures the C++ object is created</td></tr> <tr class="row1"> <td></td><td>void</td><td><b><a href="#method6">_destroy</a></b></td><td></td><td>Explicitly destroys the object</td></tr> <tr class="row0"> <td><i>[const]</i></td><td>bool</td><td><b><a href="#method7">_destroyed?</a></b></td><td></td><td>Returns a value indicating whether the object was already destroyed</td></tr> <tr class="row1"> <td><i>[const]</i></td><td>bool</td><td><b><a href="#method8">_is_const_object?</a></b></td><td></td><td>Returns a value indicating whether the reference is a const reference</td></tr> <tr class="row0"> <td></td><td>void</td><td><b><a href="#method9">_manage</a></b></td><td></td><td>Marks the object as managed by the script side.</td></tr> <tr class="row1"> <td></td><td>void</td><td><b><a href="#method10">_unmanage</a></b></td><td></td><td>Marks the object as no longer owned by the script side.</td></tr> <tr class="row0"> <td></td><td>void</td><td><b><a href="#method11">assign</a></b></td><td>(const MacroInterpreter other)</td><td>Assigns another object to self</td></tr> <tr class="row1"> <td></td><td>Macro ptr</td><td><b><a href="#method13">create_template</a></b></td><td>(string url)</td><td>Creates a new macro template</td></tr> <tr class="row0"> <td></td><td>void</td><td><b><a href="#method14">debugger_scheme=</a></b></td><td>(int scheme)</td><td>Sets the debugger scheme (which debugger to use for the DSL macro)</td></tr> <tr class="row1"> <td></td><td>void</td><td><b><a href="#method15">description=</a></b></td><td>(string description)</td><td>Sets a description string</td></tr> <tr class="row0"> <td><i>[const]</i></td><td>new MacroInterpreter ptr</td><td><b><a href="#method18">dup</a></b></td><td></td><td>Creates a copy of self</td></tr> <tr class="row1"> <td><i>[virtual,const]</i></td><td>void</td><td><b><a href="#method19">execute</a></b></td><td>(const Macro ptr macro)</td><td>Gets called to execute a macro</td></tr> <tr class="row0"> <td></td><td>void</td><td><b><a href="#method22">register</a></b></td><td>(string name)</td><td>Registers the macro interpreter</td></tr> <tr class="row1"> <td></td><td>void</td><td><b><a href="#method23">storage_scheme=</a></b></td><td>(int scheme)</td><td>Sets the storage scheme (the format as which the macro is stored)</td></tr> <tr class="row0"> <td></td><td>void</td><td><b><a href="#method24">suffix=</a></b></td><td>(string suffix)</td><td>Sets the file suffix</td></tr> <tr class="row1"> <td></td><td>void</td><td><b><a href="#method25">syntax_scheme=</a></b></td><td>(string scheme)</td><td>Sets a string indicating the syntax highlighter scheme</td></tr> </table> <h2>Public static methods and constants</h2> <table> <tr class="row0"> <td></td><td>int</td><td><b><a href="#method0">MacroFormat</a></b></td><td></td><td>Indicates macro (XML) format for storage_scheme</td></tr> <tr class="row1"> <td></td><td>int</td><td><b><a href="#method1">NoDebugger</a></b></td><td></td><td>Indicates no debugging for debugger_scheme</td></tr> <tr class="row0"> <td></td><td>int</td><td><b><a href="#method2">PlainTextFormat</a></b></td><td></td><td>Indicates plain text format for storage_scheme</td></tr> <tr class="row1"> <td></td><td>int</td><td><b><a href="#method3">PlainTextWithHashAnnotationsFormat</a></b></td><td></td><td>Indicates plain text format for storage_scheme</td></tr> <tr class="row0"> <td></td><td>int</td><td><b><a href="#method4">RubyDebugger</a></b></td><td></td><td>Indicates Ruby debugger for debugger_scheme</td></tr> </table> <h2>Deprecated methods (protected, public, static, non-static and constructors)</h2> <table> <tr class="row0"> <td></td><td>void</td><td><b><a href="#method12">create</a></b></td><td></td><td>Use of this method is deprecated. Use _create instead</td></tr> <tr class="row1"> <td></td><td>void</td><td><b><a href="#method16">destroy</a></b></td><td></td><td>Use of this method is deprecated. Use _destroy instead</td></tr> <tr class="row0"> <td><i>[const]</i></td><td>bool</td><td><b><a href="#method17">destroyed?</a></b></td><td></td><td>Use of this method is deprecated. Use _destroyed? instead</td></tr> <tr class="row1"> <td><i>[const]</i></td><td>bool</td><td><b><a href="#method20">is_const_object?</a></b></td><td></td><td>Use of this method is deprecated. Use _is_const_object? instead</td></tr> </table> <a name="detailed"/><h2>Detailed description</h2> <table><tr><td rowspan="1"><h3>MacroFormat</h3> </td><td style="padding-bottom: 16px"><a name="method0"/><a name="m_MacroFormat"/><keyword title="API reference - Class MacroInterpreter, Method MacroFormat" name="MacroInterpreter#MacroFormat"/> <p><b>Signature</b>: <i>[static] </i>int <b> MacroFormat </b> </p> <p><b>Description</b>: Indicates macro (XML) format for storage_scheme</p> </td></tr><tr><td rowspan="1"><h3>NoDebugger</h3> </td><td style="padding-bottom: 16px"><a name="method1"/><a name="m_NoDebugger"/><keyword title="API reference - Class MacroInterpreter, Method NoDebugger" name="MacroInterpreter#NoDebugger"/> <p><b>Signature</b>: <i>[static] </i>int <b> NoDebugger </b> </p> <p><b>Description</b>: Indicates no debugging for debugger_scheme</p> </td></tr><tr><td rowspan="1"><h3>PlainTextFormat</h3> </td><td style="padding-bottom: 16px"><a name="method2"/><a name="m_PlainTextFormat"/><keyword title="API reference - Class MacroInterpreter, Method PlainTextFormat" name="MacroInterpreter#PlainTextFormat"/> <p><b>Signature</b>: <i>[static] </i>int <b> PlainTextFormat </b> </p> <p><b>Description</b>: Indicates plain text format for storage_scheme</p> </td></tr><tr><td rowspan="1"><h3>PlainTextWithHashAnnotationsFormat</h3> </td><td style="padding-bottom: 16px"><a name="method3"/><a name="m_PlainTextWithHashAnnotationsFormat"/><keyword title="API reference - Class MacroInterpreter, Method PlainTextWithHashAnnotationsFormat" name="MacroInterpreter#PlainTextWithHashAnnotationsFormat"/> <p><b>Signature</b>: <i>[static] </i>int <b> PlainTextWithHashAnnotationsFormat </b> </p> <p><b>Description</b>: Indicates plain text format for storage_scheme</p> <p><p> This format is identical to <a href="#m_PlainTextFormat">PlainTextFormat</a> but indicates that it is possible to insert annotations (properties) into the text in a hash-commented header.</p></p> </td></tr><tr><td rowspan="1"><h3>RubyDebugger</h3> </td><td style="padding-bottom: 16px"><a name="method4"/><a name="m_RubyDebugger"/><keyword title="API reference - Class MacroInterpreter, Method RubyDebugger" name="MacroInterpreter#RubyDebugger"/> <p><b>Signature</b>: <i>[static] </i>int <b> RubyDebugger </b> </p> <p><b>Description</b>: Indicates Ruby debugger for debugger_scheme</p> </td></tr><tr><td rowspan="1"><h3>_create</h3> </td><td style="padding-bottom: 16px"><a name="method5"/><a name="m__create"/><keyword title="API reference - Class MacroInterpreter, Method _create" name="MacroInterpreter#_create"/> <p><b>Signature</b>: void <b> _create </b> </p> <p><b>Description</b>: Ensures the C++ object is created</p> <p><p> Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. Usually C++ objects are created on demand and not necessarily when the script object is created.</p></p> </td></tr><tr><td rowspan="1"><h3>_destroy</h3> </td><td style="padding-bottom: 16px"><a name="method6"/><a name="m__destroy"/><keyword title="API reference - Class MacroInterpreter, Method _destroy" name="MacroInterpreter#_destroy"/> <p><b>Signature</b>: void <b> _destroy </b> </p> <p><b>Description</b>: Explicitly destroys the object</p> <p><p> Explicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception. If the object is not owned by the script, this method will do nothing.</p></p> </td></tr><tr><td rowspan="1"><h3>_destroyed?</h3> </td><td style="padding-bottom: 16px"><a name="method7"/><a name="m__destroyed?"/><keyword title="API reference - Class MacroInterpreter, Method _destroyed?" name="MacroInterpreter#_destroyed?"/> <p><b>Signature</b>: <i>[const] </i>bool <b> _destroyed? </b> </p> <p><b>Description</b>: Returns a value indicating whether the object was already destroyed</p> <p><p> This method returns true, if the object was destroyed, either explicitly or by the C++ side. The latter may happen, if the object is owned by a C++ object which got destroyed itself.</p></p> </td></tr><tr><td rowspan="1"><h3>_is_const_object?</h3> </td><td style="padding-bottom: 16px"><a name="method8"/><a name="m__is_const_object?"/><keyword title="API reference - Class MacroInterpreter, Method _is_const_object?" name="MacroInterpreter#_is_const_object?"/> <p><b>Signature</b>: <i>[const] </i>bool <b> _is_const_object? </b> </p> <p><b>Description</b>: Returns a value indicating whether the reference is a const reference</p> <p><p> This method returns true, if self is a const reference. In that case, only const methods may be called on self.</p></p> </td></tr><tr><td rowspan="1"><h3>_manage</h3> </td><td style="padding-bottom: 16px"><a name="method9"/><a name="m__manage"/><keyword title="API reference - Class MacroInterpreter, Method _manage" name="MacroInterpreter#_manage"/> <p><b>Signature</b>: void <b> _manage </b> </p> <p><b>Description</b>: Marks the object as managed by the script side.</p> <p><p> After calling this method on an object, the script side will be responsible for the management of the object. This method may be called if an object is returned from a C++ function and the object is known not to be owned by any C++ instance. If necessary, the script side may delete the object if the script's reference is no longer required.</p><p>Usually it's not required to call this method. It has been introduced in version 0.24.</p></p> </td></tr><tr><td rowspan="1"><h3>_unmanage</h3> </td><td style="padding-bottom: 16px"><a name="method10"/><a name="m__unmanage"/><keyword title="API reference - Class MacroInterpreter, Method _unmanage" name="MacroInterpreter#_unmanage"/> <p><b>Signature</b>: void <b> _unmanage </b> </p> <p><b>Description</b>: Marks the object as no longer owned by the script side.</p> <p><p> Calling this method will make this object no longer owned by the script's memory management. Instead, the object must be managed in some other way. Usually this method may be called if it is known that some C++ object holds and manages this object. Technically speaking, this method will turn the script's reference into a weak reference. After the script engine decides to delete the reference, the object itself will still exist. If the object is not managed otherwise, memory leaks will occur.</p><p>Usually it's not required to call this method. It has been introduced in version 0.24.</p></p> </td></tr><tr><td rowspan="1"><h3>assign</h3> </td><td style="padding-bottom: 16px"><a name="method11"/><a name="m_assign"/><keyword title="API reference - Class MacroInterpreter, Method assign" name="MacroInterpreter#assign"/> <p><b>Signature</b>: void <b> assign </b> (const <a href="/code/class_MacroInterpreter.xml">MacroInterpreter</a> other)</p> <p><b>Description</b>: Assigns another object to self</p> </td></tr><tr><td rowspan="1"><h3>create</h3> </td><td style="padding-bottom: 16px"><a name="method12"/><a name="m_create"/><keyword title="API reference - Class MacroInterpreter, Method create" name="MacroInterpreter#create"/> <p><b>Signature</b>: void <b> create </b> </p> <p><b>Description</b>: Ensures the C++ object is created</p> <p>Use of this method is deprecated. Use _create instead</p> </td></tr><tr><td rowspan="1"><h3>create_template</h3> </td><td style="padding-bottom: 16px"><a name="method13"/><a name="m_create_template"/><keyword title="API reference - Class MacroInterpreter, Method create_template" name="MacroInterpreter#create_template"/> <p><b>Signature</b>: <a href="/code/class_Macro.xml">Macro</a> ptr <b> create_template </b> (string url)</p> <p><b>Description</b>: Creates a new macro template</p> <p><p> <u>rl The template will be initialized from that URL.</p><p>This method will create a register a new macro template. It returns a <a href="/code/class_Macro.xml">Macro</a> object which can be modified in order to adjust the template (for example to set description, add a content, menu binding, autorun flags etc.)</p><p>This method must be called after <a href="#m_register">register</a> has called. </p></p> </td></tr><tr><td rowspan="1"><h3>debugger_scheme=</h3> </td><td style="padding-bottom: 16px"><a name="method14"/><a name="m_debugger_scheme="/><keyword title="API reference - Class MacroInterpreter, Method debugger_scheme=" name="MacroInterpreter#debugger_scheme="/> <p><b>Signature</b>: void <b> debugger_scheme= </b> (int scheme)</p> <p><b>Description</b>: Sets the debugger scheme (which debugger to use for the DSL macro)</p> <p><p></p><p>The value can be one of the constants <a href="#m_RubyDebugger">RubyDebugger</a> or <a href="#m_NoDebugger">NoDebugger</a>.</p><p>Use this attribute setter in the initializer before registering the interpreter.</p><p>Before version 0.25 this attribute was a reimplementable method. It has been turned into an attribute for performance reasons in version 0.25. </p></p> <p><b>Python specific notes:</b><br/>The object exposes a writable attribute 'debugger_scheme'. This is the setter. </p> </td></tr><tr><td rowspan="1"><h3>description=</h3> </td><td style="padding-bottom: 16px"><a name="method15"/><a name="m_description="/><keyword title="API reference - Class MacroInterpreter, Method description=" name="MacroInterpreter#description="/> <p><b>Signature</b>: void <b> description= </b> (string description)</p> <p><b>Description</b>: Sets a description string</p> <p><p></p><p>This string is used for showing the type of DSL macro in the file selection box together with the suffix for example. Use this attribute setter in the initializer before registering the interpreter.</p><p>Before version 0.25 this attribute was a reimplementable method. It has been turned into an attribute for performance reasons in version 0.25. </p></p> <p><b>Python specific notes:</b><br/>The object exposes a writable attribute 'description'. This is the setter. </p> </td></tr><tr><td rowspan="1"><h3>destroy</h3> </td><td style="padding-bottom: 16px"><a name="method16"/><a name="m_destroy"/><keyword title="API reference - Class MacroInterpreter, Method destroy" name="MacroInterpreter#destroy"/> <p><b>Signature</b>: void <b> destroy </b> </p> <p><b>Description</b>: Explicitly destroys the object</p> <p>Use of this method is deprecated. Use _destroy instead</p> </td></tr><tr><td rowspan="1"><h3>destroyed?</h3> </td><td style="padding-bottom: 16px"><a name="method17"/><a name="m_destroyed?"/><keyword title="API reference - Class MacroInterpreter, Method destroyed?" name="MacroInterpreter#destroyed?"/> <p><b>Signature</b>: <i>[const] </i>bool <b> destroyed? </b> </p> <p><b>Description</b>: Returns a value indicating whether the object was already destroyed</p> <p>Use of this method is deprecated. Use _destroyed? instead</p> </td></tr><tr><td rowspan="1"><h3>dup</h3> </td><td style="padding-bottom: 16px"><a name="method18"/><a name="m_dup"/><keyword title="API reference - Class MacroInterpreter, Method dup" name="MacroInterpreter#dup"/> <p><b>Signature</b>: <i>[const] </i>new <a href="/code/class_MacroInterpreter.xml">MacroInterpreter</a> ptr <b> dup </b> </p> <p><b>Description</b>: Creates a copy of self</p> </td></tr><tr><td rowspan="1"><h3>execute</h3> </td><td style="padding-bottom: 16px"><a name="method19"/><a name="m_execute"/><keyword title="API reference - Class MacroInterpreter, Method execute" name="MacroInterpreter#execute"/> <p><b>Signature</b>: <i>[virtual,const] </i>void <b> execute </b> (const <a href="/code/class_Macro.xml">Macro</a> ptr macro)</p> <p><b>Description</b>: Gets called to execute a macro</p> <table class="layout-table"> <tr><td><b>macro</b>:</td><td>The macro to execute</td></tr> </table> <p><p> This method must be reimplemented to execute the macro. The system will call this script when a macro with interpreter type 'dsl' and the name of this interpreter is run.</p></p> </td></tr><tr><td rowspan="1"><h3>is_const_object?</h3> </td><td style="padding-bottom: 16px"><a name="method20"/><a name="m_is_const_object?"/><keyword title="API reference - Class MacroInterpreter, Method is_const_object?" name="MacroInterpreter#is_const_object?"/> <p><b>Signature</b>: <i>[const] </i>bool <b> is_const_object? </b> </p> <p><b>Description</b>: Returns a value indicating whether the reference is a const reference</p> <p>Use of this method is deprecated. Use _is_const_object? instead</p> </td></tr><tr><td rowspan="1"><h3>new</h3> </td><td style="padding-bottom: 16px"><a name="method21"/><a name="m_new"/><keyword title="API reference - Class MacroInterpreter, Method new" name="MacroInterpreter#new"/> <p><b>Signature</b>: <i>[static] </i>new <a href="/code/class_MacroInterpreter.xml">MacroInterpreter</a> ptr <b> new </b> </p> <p><b>Description</b>: Creates a new object of this class</p> <p><b>Python specific notes:</b><br/>This method is the default initializer of the object </p> </td></tr><tr><td rowspan="1"><h3>register</h3> </td><td style="padding-bottom: 16px"><a name="method22"/><a name="m_register"/><keyword title="API reference - Class MacroInterpreter, Method register" name="MacroInterpreter#register"/> <p><b>Signature</b>: void <b> register </b> (string name)</p> <p><b>Description</b>: Registers the macro interpreter</p> <table class="layout-table"> <tr><td><b>name</b>:</td><td>The interpreter name. This is an arbitrary string which should be unique.</td></tr> </table> <p><p></p><p>Registration of the interpreter makes the object known to the system. After registration, macros whose interpreter is set to 'dsl' can use this object to run the script. For executing a script, the system will call the interpreter's <a href="#m_execute">execute</a> method. </p></p> </td></tr><tr><td rowspan="1"><h3>storage_scheme=</h3> </td><td style="padding-bottom: 16px"><a name="method23"/><a name="m_storage_scheme="/><keyword title="API reference - Class MacroInterpreter, Method storage_scheme=" name="MacroInterpreter#storage_scheme="/> <p><b>Signature</b>: void <b> storage_scheme= </b> (int scheme)</p> <p><b>Description</b>: Sets the storage scheme (the format as which the macro is stored)</p> <p><p></p><p>This value indicates how files for this DSL macro type shall be stored. The value can be one of the constants <a href="#m_PlainTextFormat">PlainTextFormat</a>, <a href="#m_PlainTextWithHashAnnotationsFormat">PlainTextWithHashAnnotationsFormat</a> and <a href="#m_MacroFormat">MacroFormat</a>.</p><p>Use this attribute setter in the initializer before registering the interpreter.</p><p>Before version 0.25 this attribute was a reimplementable method. It has been turned into an attribute for performance reasons in version 0.25. </p></p> <p><b>Python specific notes:</b><br/>The object exposes a writable attribute 'storage_scheme'. This is the setter. </p> </td></tr><tr><td rowspan="1"><h3>suffix=</h3> </td><td style="padding-bottom: 16px"><a name="method24"/><a name="m_suffix="/><keyword title="API reference - Class MacroInterpreter, Method suffix=" name="MacroInterpreter#suffix="/> <p><b>Signature</b>: void <b> suffix= </b> (string suffix)</p> <p><b>Description</b>: Sets the file suffix</p> <p><p></p><p>This string defines which file suffix to associate with the DSL macro. If an empty string is given (the default) no particular suffix is assciated with that macro type and "lym" is assumed. Use this attribute setter in the initializer before registering the interpreter.</p><p>Before version 0.25 this attribute was a reimplementable method. It has been turned into an attribute for performance reasons in version 0.25. </p></p> <p><b>Python specific notes:</b><br/>The object exposes a writable attribute 'suffix'. This is the setter. </p> </td></tr><tr><td rowspan="1"><h3>syntax_scheme=</h3> </td><td style="padding-bottom: 16px"><a name="method25"/><a name="m_syntax_scheme="/><keyword title="API reference - Class MacroInterpreter, Method syntax_scheme=" name="MacroInterpreter#syntax_scheme="/> <p><b>Signature</b>: void <b> syntax_scheme= </b> (string scheme)</p> <p><b>Description</b>: Sets a string indicating the syntax highlighter scheme</p> <p><p></p><p>The scheme string can be empty (indicating no syntax highlighting), "ruby" for the Ruby syntax highlighter or another string. In that case, the highlighter will look for a syntax definition under the resource path ":/syntax/<scheme>.xml".</p><p>Use this attribute setter in the initializer before registering the interpreter.</p><p>Before version 0.25 this attribute was a reimplementable method. It has been turned into an attribute for performance reasons in version 0.25. </p></p> <p><b>Python specific notes:</b><br/>The object exposes a writable attribute 'syntax_scheme'. This is the setter. </p> </td></tr></table></doc>