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.
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. > > > > >
On Sep 12, 2016, at 6:04 PM, Vedant Kumar via llvm-dev <llvm-dev at lists.llvm.org> wrote:> 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 <- "([^"]|\\")*” ;This seems like a really complicated set of extensions to filecheck for marginal gain. I’m not enthused by the idea that you’d have to actually utter this in every individual test that needs to use the feature, because that would lead to boilerplate. Instead of doing this, has anyone considered baking “modes” into Filecheck to support the important clients (e.g. LLVM IR, MC, clang, etc)? This would mean that a test could just add a “--mode=llvmir” flag to filecheck and get a bunch of baked in patterns, potentially with magic syntax. Something like this would avoid having to redundantly enter "%[0-9]+” a kajillion times all over the place. -Chris
Elena Lepilkina via llvm-dev
2016-Sep-13 14:13 UTC
[llvm-dev] FW: RFC: FileCheck Enhancements
As I understood, I should do first of all patch with patterns implementation only with simple parameters without modifiers? And after add this feature separately? -----Original Message----- From: vsk at apple.com [mailto:vsk at apple.com] Sent: Tuesday, September 13, 2016 4:05 AM To: Elena Lepilkina <Elena.Lepilkina at synopsys.com> Cc: Mehdi Amini <mehdi.amini at apple.com>; llvm-dev at lists.llvm.org Subject: Re: [llvm-dev] RFC: FileCheck Enhancements 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. > > > > >