souffle-lang / souffle

Soufflé is a variant of Datalog for tool designers crafting analyses in Horn clauses. Soufflé synthesizes a native parallel C++ program from a logic specification.
http://souffle-lang.github.io/
Universal Permissive License v1.0
927 stars 208 forks source link

Regex syntax differs betwen versions 2.0.2 and 2.1 #2079

Closed gfour closed 3 years ago

gfour commented 3 years ago

Test program:

.decl Fact(s:symbol)
Fact("hello.py").

.decl isPy1(s:symbol)
.output isPy1

.decl isPy2(s:symbol)
.output isPy2

isPy1(s) :- Fact(s), match(".*\.py", s).
isPy2(s) :- Fact(s), match(".*\\.py", s).

(1) Running this script with Souffle 2.0.2 only populates relation isPy1. (2) Running this script with Souffle 2.1 crashes:

Error: Unknown escape sequence \. in file regex-test.dl at line 10
isPy1(s) :- Fact(s), match(".*\.py", s).
---------------------------^-------------
1 errors generated, evaluation aborted

I understand that Souffle 2.1 follows std::regex for regex syntax but that doesn't seem to be the case for version 2.0.2 (or isPy2 would contain tuples). Can there be a match clause that uses slashes and works under both Souffle 2.1 and pre-2.1 versions?

quentin commented 3 years ago

Hi, Probably the effect of https://github.com/souffle-lang/souffle/pull/1950 fixing https://github.com/souffle-lang/souffle/issues/1947 Chances are thin to find a common ground since escape sequences are handled differently in 2.1 and pre-2.1. This is deeply rooted in the lexer.

gfour commented 3 years ago

Workaround (by @gkastrinis), works in both Souffle 2.1 and pre-2.1:

.decl Fact(s:symbol)
Fact("hello.py").

.decl isPy(s:symbol)
.output isPy

isPy(s) :- Fact(s), match(".*[.]py", s).

In Doop (where this issue was observed in a few rules), this means replacing: \\. -> [.] \\$ -> [$] \\( -> [(] \\) -> [)]