Skip to content

Commit

Permalink
Restrict lexical contexts where %{ is recognized as a block start.
Browse files Browse the repository at this point in the history
As Krishna noticed in bug #392 "Cannot compile when user c string has a
special pattern", `%{` in the middle of a string makes re2c think that
this is a start of a re2c block. The user has to braek the string in two
in order to separate `%` from `{`.

The problem is exacerbated by the fact that `%{` does not require -F,
--flex-support option. It affects all re2c programs.

In general re2c cannot be sure if `%{` appears in the middle of a
string, a comment, a macro defintion or some other lexical context where
it is a part of a larger lexeme and not a standalone block start marker.
This is because re2c doesn't parse user-defined code in-between re2c
blocks (doing that would require implementing multiple language
frontends in re2c, which is out of the question).

This commit mitigates the problem in #392 by restricting lexical context
wheer `%{` is recognized as a block start: the marker must be on a new
line, optionally preceded by whitespace characters. This does not cover
all the cases and it may break some re2c programs that used block start
`%{` in other lexical contexts, but it is a reasonable compromise
between usability and backards compatibility.
  • Loading branch information
skvadrik committed Dec 24, 2021
1 parent 92c1a45 commit dba7d05
Show file tree
Hide file tree
Showing 5 changed files with 2,596 additions and 2,453 deletions.
Loading

0 comments on commit dba7d05

Please sign in to comment.