Phil Tomson wrote: > This is good to know. So you could also do this, correct?: > > rule inline_atom > ( numz { def bar; ... end} / wrrd { def bar; ... end} ) { def foo; ... end} > end > > so that each alternative gets it's own bar method. Yes. > So how would one go about extracting one valid syntactic element (the > port_decl in this case) from surrounding elements that one doesn't > care about? You're trying to skip any amount of stuff up to the port declaration, then parse that, then skip to the end. Now first I'll ignore that your "stuff" can presumably contain comments, which may contain the word "port", but you do it like this: rule vhdl_file_wth_port ( !'port' . )* port_decl .* end This says to parse any number of single characters as long as you aren't looking at the word "port", then parse the port_decl and skip the rest. Just beware of the fact that here, port might be embedded inside another word "supportable". I tend to create keyword rules to handle that: rule port 'port' !alphanumeric end rule alphanumeric [a-zA-Z0-9] end The keyword rule should only be called when you know you've just seen something that can't be part of a word - never after an arbitrary character. If you want to handle comments etc that might contain the word port, you'll need to detect those separately in a sub-rule, and skip a sequence of comments and "stuff not containing 'port'" before parsing your decl: rule vhdl_file_wth_port non_port* port_decl non_port* end rule non_port comment / string / white / !port alphanumeric+ end rule string "'" ( '\\' [befntr\\'] / .)* "'" end rule white [ \t\n\r]+ end rule comment '/*' (!'*/' . )* '*/' end Clifford Heath.