Skip to content

Commit

Permalink
Merge pull request #2358 from SocketDev/component-adt-csv
Browse files Browse the repository at this point in the history
Parse CSV QualifiedNames instead of just Identifier for ADTs
  • Loading branch information
quentin authored Nov 9, 2022
2 parents 1817bcd + 3047414 commit a11d23e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/include/souffle/io/ReadStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ReadStream : public SerialisationStream<false> {

// Consume initial character
consumeChar(source, '$', pos);
std::string constructor = readIdentifier(source, pos);
std::string constructor = readQualifiedName(source, pos);

json11::Json branchInfo = [&]() -> json11::Json {
for (auto branch : branches.array_items()) {
Expand Down Expand Up @@ -250,7 +250,7 @@ class ReadStream : public SerialisationStream<false> {
* Consume preceding whitespace.
* TODO (darth_tytus): use std::string_view?
*/
std::string readIdentifier(const std::string& source, std::size_t& pos) {
std::string readQualifiedName(const std::string& source, std::size_t& pos) {
consumeWhiteSpace(source, pos);
if (pos >= source.length()) {
throw std::invalid_argument("Unexpected end of input");
Expand All @@ -259,7 +259,7 @@ class ReadStream : public SerialisationStream<false> {
const std::size_t bgn = pos;
while (pos < source.length()) {
unsigned char ch = static_cast<unsigned char>(source[pos]);
bool valid = std::isalnum(ch) || ch == '_' || ch == '?';
bool valid = std::isalnum(ch) || ch == '_' || ch == '?' || ch == '.';
if (!valid) break;
++pos;
}
Expand Down
1 change: 1 addition & 0 deletions tests/syntactic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ positive_test(type)
positive_test(union_comp_type)
positive_test(dot_identifiers)
positive_test(input_adt_names1)
positive_test(input_adt_names2)
positive_test(input_directive_rfc4180)
if (NOT MSVC)
# does not pass with Visual Studio pre-processor because it preserves all whitespaces
Expand Down
2 changes: 2 additions & 0 deletions tests/syntactic/input_adt_names2/B.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$MyInstance.A
$MyInstance.A2(123)
2 changes: 2 additions & 0 deletions tests/syntactic/input_adt_names2/facts/A.facts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$MyInstance.A
$MyInstance.A2(123)
11 changes: 11 additions & 0 deletions tests/syntactic/input_adt_names2/input_adt_names2.dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.comp Component {
.type ADT = A {} | A2 { n: number }
}
.init MyInstance = Component
.decl A(value: MyInstance.ADT)
.decl B(value: MyInstance.ADT)

B(v) :- A(v).

.input A
.output B
Empty file.
Empty file.

0 comments on commit a11d23e

Please sign in to comment.