質問

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.

役に立ちましたか?

解決

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.

他のヒント

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

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top