ruby - Regexp to match multiline single or double quoted strings -


i'm building ruby script read ruby sources files looking calls function _() , grabing strings of parameter passed it, can multiline string, single or double quoted, example:

  1. grab: hello world

    _('hello'+ ' world') 
  2. grab: hello \nworld

    _("hello \ world") 
  3. grab: hello "world"

    _("hello \"world\"") 
  4. grab: hello 'world'

    _('hello \'world\'') 

so need regexp match , grab string parameter. how can that?

attempting analyze source code regex leads complex fragile code doesn't work in cases. need account enclosing single , double quotes, here docs, quotes within parentheses, etc.

what need ruby lexer. there several of these, written in ruby, in antlr, 1 in lex. lexer parse source tokens, scan token list find pieces want.

you might ideas how looking @ ruby interpreter or @ syntax colouring code in opensource editor.

an alternate way write regex locates interesting tokens, singe quote, double quote, _, (, ), , newline. write finite state machine scans list looking phrases of interest. i've used technique manipulating sql.

what haven't told s actual requirement. there may solution doesn't require of this.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -