[yast-devel] Next hackweek project done ... ycp-to-ruby-translator
Hi, Cornelius hackweek proposal of a ycp-to-ruby-translator (see http://idea.opensuse.org/content/ideas/ycp-to-ruby-translator) was an itch I had to scratch sooner or later. So I spent some spare time and did a couple of late night hacks to make the translator real. It is based on an XML representation of the abstract syntax tree produces by the YCP scanner and parser within libycp. So its a pure syntax translator with only very, very limited knowledge of the semantics. The resulting Ruby code does pass the Ruby syntax checker, though. Combined with Duncans Ruby-YCP bindings, translating ycp to Ruby should be quite useful as we try to provide support for more widespread scripting languages. The translator is available at http://svn.opensuse.org/svn/yast/trunk/yxmlconv You need a recent version of yast2-core, which supports XML output and the '-x' parameter of ycpc. Then run ycpc -c -x file.ycp -o file.xml to convert YCP code to XML. Now use the xml-ruby translator as cd yxmlconv ruby src/converter.rb file.xml > file.rb Klaus P.S.: It's fairly straightforward to change the translator to output e.g. Python or Java or C# or ... --- SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
really cool. Do you have examples of converted code?, how does it handle modules and other stuff? -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
* Duncan Mac-Vicar Prett <dmacvicar@suse.de> [Jul 18. 2007 15:32]:
really cool.
Thanks.
Do you have examples of converted code?
/usr/share/YaST2/modules/Arch.ycp for example (shortened): { module "Arch"; string _architecture = nil global string architecture () { if (_architecture == nil) _architecture = (string)SCR::Read(.probe.architecture); return _architecture; } } translates to module Arch require 'ycp/SCR' _architecture = nil def architecture( ) if ( _architecture == nil ) then _architecture = Ycp::Builtin::Read( ".probe.architecture" ) end return _architecture end end
, how does it handle modules and other stuff?
It can convert all of /usr/share/YaST2/clients and /usr/share/YaST2/modules. The README file lists current limitations. Biggest problem is YCP terms which don't have a direct representation in Ruby. Klaus --- SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
participants (2)
-
Duncan Mac-Vicar Prett
-
Klaus Kaempf