Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong result only if another rule is present #57

Closed
skvadrik opened this issue Mar 25, 2015 · 9 comments

Comments

@skvadrik
Copy link
Owner

commented Mar 25, 2015

The following program produces the wrong result

3: \baaa

If the first rule [<]... is removed, the correct result is produced:

8:

This could be reproduced with re2c 0.13.7.5 and 0.14.1. Versions 0.13.5 and 0.13.6 work fine.

(This is a reduced testcase. The problem was discovered in a more complicated scanner in libcmark.)

#include <stdio.h>

int scan(const char *p)
{
#define YYCTYPE char
    const char *YYCURSOR = p;
    const char *YYMARKER;

/*!re2c
    re2c:yyfill:enable = 0;

    reg_char     = [a];
    escaped_char = [\\][b];

    [<] ([x] | escaped_char | [y])* [>] { return YYCURSOR - p; }
    (reg_char | escaped_char)* { return YYCURSOR - p; }
    . { return 0; }
*/
}

int main()
{
    const char *str = "aaa\\baaa";
    int res = scan(str);
    printf("%d: %s\n", res, str + res);
    return 0;
}

Original comment by: nwellnhof

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Mar 25, 2015

  • status: open --> accepted
  • assigned_to: Ulya Trofimovich

Original comment by: skvadrik

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Mar 25, 2015

Reproduced, looking into it.

Original comment by: skvadrik

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Mar 25, 2015

Since 0.13.7, re2c tries to merge common suffixes in regexps. It's a bug in the merging algorithm.

Anothe rule just re-uses 'escaped_char', which triggers the error.

Original comment by: skvadrik

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Mar 25, 2015

Fixed, see https://sourceforge.net/p/re2c/code-git/ci/1a97c678d5ae0dac02234ee65d9bd847dd43c449

Will soon release 0.14.2 with this bugfix included.

If the larger example is open source code, it will be great to add it to re2c test collection.

Original comment by: skvadrik

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Mar 25, 2015

  • status: accepted --> closed-fixed

Original comment by: skvadrik

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Mar 25, 2015

Released re2c-0.14.2 with bugfix.

Could you send me your real-world example? I will add it to re2c test collection (and it won't break next time).

Original comment by: skvadrik

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Mar 26, 2015

Is this it?

https://github.com/jgm/cmark/blob/master/src/scanners.re

Original comment by: starseeker

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Mar 26, 2015

Very likely, thanks!

Original comment by: skvadrik

@skvadrik

This comment has been minimized.

Copy link
Owner Author

commented Mar 27, 2015

Thanks for the quick response. Version 0.14.2 fixes the issue. The link provided by Cliff is correct.

Original comment by: nwellnhof

@skvadrik skvadrik self-assigned this Jul 23, 2015

@skvadrik skvadrik closed this Jul 23, 2015

skvadrik added a commit that referenced this issue Nov 21, 2015

Merge branch 'master' into simplified_codegen.
* master:
  Updated version to 0.14.4.dev
  Release 0.14.3.
  Added simple test for yacc-style brackets (see patch #27)
  Fixed '#27 re2c crashes reading files containing %{ %}' (patch by Rui)
  Makefile.am: dropped distfiles for MSVC (they are broken anyway)
  Added full another test for bug #57.
  Updated version to 0.14.3.dev
  Release 0.14.2.
  Fixed bug #57: Wrong result only if another rule is present
  Updated version to 0.14.2.dev
  Release 0.14.1.
  Pad version with '0' instead of nulls

skvadrik added a commit that referenced this issue Nov 21, 2015

Fixed bug #57: Wrong result only if another rule is present
When making regexp alternative, only 'RegExp::PRIVATE' attribute
should be propagated. Propagating 'RegExp::SHARED' attribute is
a mistake, as can be observed from the following example:

    name = "smth1";
    "smth2" | name | "smth3" { ... }
    name                     { ... }

Here, 'name' must have 'RegExp::PRIVATE' attribute, but it gets
broken after alternation. See #bug57 or test 'bug57.re' for full
working example.

skvadrik added a commit that referenced this issue Nov 21, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.