[llvm-dev] RFC: FileCheck Enhancements

Vedant Kumar via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 12 18:04:38 PDT 2016


That's a good example. While '{{REGEX}}' usually creates a new matching group,
we could introduce some new syntax to make it possible to use pattern arguments
inside of regexes. E.g for an argument named 'x', writing 'x' in a pattern
definition preserves the current behavior, and writing '#x' concatenates the
value of 'x' with any surrounding regexes (resulting in just one matching
group).

So, to match one or more things you could write:

  CHECK-DEFINE-PATTERN: one_or_more(x): #x {{+}}
  CHECK: [[@one_or_more("1")]]

Without the '#', you'd see a syntax error because '+' isn't a valid regex.

I like this approach because it doesn't require changing the definitions of
REGEX or POSIX_REGEX. It'd be interesting to hear what other people think.

We should be able to hash this out in parallel to the work on D22403, since the
plan is to defer work on pattern arguments until basic support for pattern
definitions has landed.

Revised grammar (** proposal **):

  ACTION <- CHECK ':' MATCH '\n' ;
  ACTION <- CHECK-DEFINE-PATTERN ':' IDENT PARAMLIST? ':' PATTERN_ELEMENT* '\n' ;
  PARAMLIST <- '(' IDENT (',' IDENT)* ')' ;
  PATTERN_ELEMENT <- '#'? IDENT ;
  PATTERN_ELEMENT <- REGEX ;
  MATCH <- (TEXT | REGEX | PATTERN_USE | VAR)* ;
  REGEX <- '{{' POSIX_REGEX '}}' ;
  PATTERN_USE <- '[[' '@' IDENT ARGLIST? ']]' ;
  VAR <- '[[' IDENT ':' POSIX_REGEX ']]' ;
  VAR <- '[[' IDENT '@' IDENT ARGLIST? ']]' ;
  ARGLIST <- '(' ARG (',' ARG)* ')' ;
  ARG <- "([^"]|\\")*" ;


best,
vedant

> On Sep 12, 2016, at 5:57 AM, Elena Lepilkina <Elena.Lepilkina at synopsys.com> wrote:
> 
> Hi,
> 
> I have question again about modifiers for pattern parameters.
> 
> Vedant suggested such way.
> 
>>  CHECK-DEFINE-PATTERN: one_or_more(x): x {{+}}
> 
> But I have some doubts. This should be equal to x+. This approach differs from standard one.
> In FileCheck I can write
> 
> CHECK: {{x|y}}{{something}}
> 
> This line will be equal to regex (x|y)(something).
> 
> But if I use suggested approach and write same string in pattern CHECK-DEFINE-PATTERN: example: {{x|y}}{{something}}, it will be equal to (x|ysomething).
> As user I expected behavior as in first check.
> 
> Thanks, Elena.
> 
> 
> 
> 
> 



More information about the llvm-dev mailing list