glsl/glcpp: Add flex options to eliminate the default rule

Graphics / Mesa 3D Graphics Library / Mesa - Carl Worth [cworth.org] - 29 July 2014 17:11 UTC

We've had multiple bugs in the past where we have been inadvertently matching the default rule, (which we never want to do). We recently added a catch-all rule to avoid this, (and made this rule robust for future start conditions).

Kristian pointed out that flex allows us to go one step better. This syntax:

%option warn nodefault

instructs flex to not generate the default rule at all. Further, flex will generate a warning at compile time if the set of rules we provide are inadequate, (such that it would be possible for the default rule to be matched).

With this warning in place, I found that the catch-all rule was in fact missing something. The catch-all rule uses a pattern of "." which doesn't match newlines. So here we extend the newline-matching rule to all start conditions. That is enough to convince flex that it really doesn't need any default rule.

bc8721f glsl/glcpp: Add flex options to eliminate the default rule.
src/glsl/glcpp/glcpp-lex.l | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

Upstream: cgit.freedesktop.org


  • Share