If you are only looking for names, then something simple:
grammar PascalFuncProc; parse : (Procedure | Function)* EOF ; Procedure : 'procedure' Spaces Identifier ; Function : 'function' Spaces Identifier ; Ignore : (StrLiteral | Comment | .) {skip();} ; fragment Spaces : (' ' | '\t' | '\r' | '\n')+; fragment Identifier : ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '_' | '0'..'9')*; fragment StrLiteral : '\'' ~'\''* '\''; fragment Comment : '{' ~'}'* '}';
will do the trick. Please note that I am not very familiar with Delhpi / Pascal, so I am sure that it works with StrLiteral and / or Comment s, but this will be easily fixed.
The lexer generated from the above grammar will generate only two types of tokens ( Procedure and Function s), the rest of the input (string literals, comments, or if nothing matches, one character: t25>) is immediately dropped from the lexer ( skip() method) .
To enter:
some valid source { function NotAFunction ... } procedure Proc Begin ... End; procedure Func Begin s = 'function NotAFunction!!!' End;
The following parsing tree is created:

source share