Multiple S/R via regexp

Hi Ruby GURU!
I’m slightely frustrated… Sorry.

Here is my text for input of my C++ program (C++ -> HTML colored
converter for Windows). Attached is the my own program (Windows) and
examples. The program can convert any C++ source (.cpp, .h, .hpp, .c
etc) to HTML with coloring syntax using my own approach using REGEXP
based on PERL.

The question:
How can I do it using Ruby (easyly)?


My regexp S/R template for my C++ program:

^/</ <
^/>/ >
^/\t/  
/(\b(__asm)|(__cdecl)|(__declspec)|(__export)|(__far16)|(__fastcall)|(__fortran)|(__import)|(__pascal)|(__rtti)|(__stdcall)|(_asm)|(_cdecl)|(__except)|(_export)|(_far16)|(_fastcall)|(__finally)|(_fortran)|(_import)|(_pascal)|(_stdcall)|(__thread)|(__try)|(asm)|(auto)|(bool)|(break)|(case)|(catch)|(cdecl)|(char)|(class)|(const)|(const_cast)|(continue)|(default)|(delete)|(do)|(double)|(dynamic_cast)|(else)|(enum)|(explicit)|(extern)|(false)|(float)|(for)|(friend)|(goto)|(if)|(inline)|(int)|(long)|(mutable)|(namespace)|(new)|(operator)|(pascal)|(private)|(protected)|(public)|(register)|(reinterpret_cast)|(return)|(short)|(signed)|(sizeof)|(static)|(static_cast)|(struct)|(switch)|(template)|(this)|(throw)|(true)|(try)|(typedef)|(typeid)|(typename)|(union)|(unsigned)|(using)|(virtual)|(void)|(volatile)|(wchar_t)|(while)|(_T)|(TCHAR)\B)|((’(([^\’])|(\.))’)|("(([^\"])|(\.))"))|((//[^\n])|(/*(([^])|(*+[^/]))*+/))|((\c.\d+([eE][-+]?\d+)?([lLfF]?))|(\b\d+.\d*([eE][-+]?\d+)?([lLfF]?)\B)|(\b\d+([eE][-+]?\d+)([lLfF]?)\B))|(\b(\d+(([UuLl]{1,2})|(i64)|(i128))?)\B)|(\b0[xX][\da-fA-F]+([UuLl]{1,2}|(i64)|(i128))?\B)|(^[\s]#([^\n]\[\s]+)[^\n])|(((<)|(>)|( )|([;=±/*&|^()[],.:!~<>%{}?#@])))/

(?1$&)
(?92$&)
(?101$&)
(?107$&)
(?117$&)
(?123$&)
(?127$&)
(?129$&)

^/[BOF]/

\r\n\r\n\r\n\r\n\r\n

^/[EOF]/
\r\n\r\n

You can see, that I use the indexes, that match to all found
expressions.
Not 1-9 (\1 - \9 or $1 - $9 - 9 is MAX), but any found - (?123…)

  • (In such case the match number is 123)
    And I use $& as well.

You can try my C++ program. It will work!
I’m waiting from You the same on Ruby, wisemen!

Thanks a lot!
Vadim

I know, the question is not so easy.
I’m GURU in C++ but now I have to move to Ruby now (life is life :-).
It would be very aprecciated if You could me to show how the task can be
completed in Ruby. Elegantly. Like in C++ for Windows :slight_smile:

Cheers,
Vad

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs