1

in my lexer I wrote the following regex:

"///"\s*[^@\s].*

I executed byacc/j in debug mode and it states that the following line matched the regex.
But why does this regex match this line?

/// @Service( version="1.0.0" )

I also tried "///"\s*[^\@\s].*, in case @ is a special character, but it also matches. o.O

I thought my regex would match only a string that starts with /// followed by optional whitespaces. Than any non-whitespace character except @ must come, followed by any characters.

Edit: I'm sorry I meant the regex is used within jflex, not byacc/j.

Workaround: In the jflex documentation I didn't find any \s escape sequence, so I tried this regex "///"[ \t\f]*[^@ \t\f].* and it worked. It seems that the \s escape character is not supported and silently ignored by jflex.

Marc-Christian Schulze
  • 3,154
  • 3
  • 35
  • 45
  • Any PCRE regex engine I am familiar with, would _not_ match the string `"/// @Service( version="1.0.0" )"` using the pattern: `///\s*[^@\s].*` (I removed the quotes since this is byacc/j specific). – Bart Kiers Aug 22 '11 at 10:36
  • But the regex used in byacc/j does. – Marc-Christian Schulze Aug 22 '11 at 10:37
  • 1
    Yeah, I understand that :). I just wanted to let you know that from a regex-perspective, you're right in your assumptions. – Bart Kiers Aug 22 '11 at 10:38
  • Are you able to view the matching process like you can in Perl? That could help enormously! – pb149 Aug 22 '11 at 10:50
  • JFlex seems to transform the given regex into a state machine. So in the generated Yylex.java file are no longer the specified regular expressions contained. Would this state machine anyone help? – Marc-Christian Schulze Aug 22 '11 at 11:10

2 Answers2

1

The workaround is correct, before version 1.5.0 \s was not a special escape sequence in JFlex, and just meant the letter s. Starting with version 1.5.0, the regexp should work as expected.

@ is not a special character and doesn't need escaping.

lsf37
  • 535
  • 2
  • 7
0

Is the \ being escaped so that the regex being passed is actually "///"s[^@s].*

Try double escaping so you use "///"\\s[^@\\s].*

Bob Vale
  • 18,094
  • 1
  • 42
  • 49