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:
grab:
hello world
_('hello'+ ' world')
grab:
hello \nworld
_("hello \ world")
grab:
hello "world"
_("hello \"world\"")
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
Post a Comment