Skip to content

Commit

Permalink
more error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pramothragavan committed May 6, 2024
1 parent ad734fe commit fb1cab1
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions gap/io.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ function(config, key)
fi;
end);

BindGlobal("DIGRAPHS_LegalEdge",
BindGlobal("DIGRAPHS_LegalDreadnautEdge",
function(vertex, x, r)
if x > r.nValue then
Error("Illegal edge ", vertex + r.dollarValue - 1, " -> ", x + r.dollarValue - 1, " (original indexing)");
Expand Down Expand Up @@ -1456,7 +1456,8 @@ function(inputString)
if currentChar = '$' and nextChar = '$' then
Info(InfoWarning, 1, "Vertex indexing will start at 1");
if ForAll(inputString{[currentPos + 2..Length(inputString)]}, c -> c = ' ' or c = '\n') then;
break;
Add(segments, inputString{[startPos..currentPos - 1]});
return segments;
else
ErrorNoReturn("Syntax error: unexpected characters after \"$$\"");
fi;
Expand All @@ -1468,9 +1469,27 @@ function(inputString)
return segments;
fi;

if IsDigitChar(currentChar) and nextChar = ' ' and inputString[currentPos + 2] = ':' then #in the case of a new vertex
# if IsDigitChar(currentChar) and nextChar = ' ' and inputString[currentPos + 2] = ':' then #in the case of a new vertex
# repeat #backtrack to find the start of the vertex
# currentPos := currentPos - 1;
# until currentPos <= 1 or not IsDigitChar(inputString[currentPos]);
# if startPos < currentPos then
# Add(segments, inputString{[startPos..currentPos-1]});
# fi;
# if currentPos > 1 then
# startPos := currentPos;
# fi;
# fi;

if currentChar = ':' then
repeat #backtrack to find the start of the vertex
currentPos := currentPos - 1;
if inputString[currentPos] <> ' ' and not IsDigitChar(inputString[currentPos]) then
ErrorNoReturn("Syntax error: unexpected character (", inputString[currentPos],") before \":\""); #catches 1: 3\n : 4
fi;
until currentPos <= 1 or IsDigitChar(inputString[currentPos]);
repeat
currentPos := currentPos - 1;
until currentPos <= 1 or not IsDigitChar(inputString[currentPos]);
if startPos < currentPos then
Add(segments, inputString{[startPos..currentPos-1]});
Expand All @@ -1487,12 +1506,11 @@ end);

BindGlobal("DIGRAPHS_ParseDreadnautGraph",
function(graphData, r)
local edgeList, part, parts, subparts, vertex, connectedTo, adjacencyPart, breakflag, newlineCounter;
local edgeList, part, parts, subparts, vertex, connectedTo, adjacencyPart, breakflag;

# Initialize an empty list to hold the edges
edgeList := List([1..r.nValue], x -> []);
breakflag := false;
newlineCounter := 1;

graphData := ReplacedString(graphData, ":", " : ");
graphData := ReplacedString(graphData, ";", " ; ");
Expand All @@ -1512,11 +1530,11 @@ function(graphData, r)

subparts := SplitString(part, ":");

if Length(subparts) = 0 then
continue;
elif Length(subparts) = 1 then
Error("Formatting error", part); ### HOW TO FIND I?
if Length(subparts) = 0 or Length(subparts) = 1 then
continue;
# elif Length(subparts) = 1 then
# Error("Formatting error", part); ### HOW TO FIND I?
# continue;
else
vertex := subparts[1];
RemoveCharacters(vertex, " ");
Expand All @@ -1542,7 +1560,7 @@ function(graphData, r)

connectedTo := Filtered(connectedTo, y -> IsInt(y)); # Ensure only integers are included
connectedTo := List(connectedTo, x -> x - r.dollarValue + 1); # Adjust the vertex numbering to start at 1
connectedTo := Filtered(connectedTo, x -> DIGRAPHS_LegalEdge(vertex, x, r));
connectedTo := Filtered(connectedTo, x -> DIGRAPHS_LegalDreadnautEdge(vertex, x, r));


Append(edgeList[vertex], connectedTo);
Expand Down

0 comments on commit fb1cab1

Please sign in to comment.