diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index cee9eb8..052e0a8 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -236,12 +236,12 @@ namespace Assignment_1 source.Position = initPos; source.SetLength(initPos); break; - case Statements.writeout: + /*case Statements.writeout: // Writes the full command history to the stream. Console.WriteLine("Writing input commands to {0}..."); source.Position = initPos; source.SetLength(initPos); - break; + break;*/ } // Do a check semicolons etc if (IsNextEoS(source)) @@ -260,7 +260,7 @@ namespace Assignment_1 return; } } - else if (source.Position != lastLinePos - 1) + else if (source.Position != lastLinePos)// - 1) { // In the case that we expect some more data, we must keep tabs of our current line, and keep accumulating data until we're finished lastLinePos = source.Position; @@ -416,7 +416,6 @@ namespace Assignment_1 { consoleOutput.Append(string.Format(entryFormat, j >= keyLines.Count ? "" : keyLines[j], j >= valueLines.Count ? "" : valueLines[j], j == 0 ? Convert.ToString((byte)Symbols[eligibleKeys[i]].Item2, 2).PadLeft(8, '0'): "")); } - //consoleOutput.Append(string.Format(entryFormat, eligibleKeys[i], Symbols[eligibleKeys[i]].Item1.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t"), Convert.ToString((byte)Symbols[eligibleKeys[i]].Item2, 2).PadLeft(8, '0'))); if (i + 1 < eligibleKeys.Count) { consoleOutput.Append(string.Format("├" + new string('─', keyWidth) + "┼" + new string('─', valueWidth) + "┼" + new string('─', flagWidth) + "┤\n")); @@ -463,7 +462,7 @@ namespace Assignment_1 } Action Print(Stream source, int mode = 0) { - StringBuilder outputString = new StringBuilder(); + StringBuilder outputString = new(); string expression = ValidateValue(source); if (mode == 0) { @@ -500,7 +499,7 @@ namespace Assignment_1 string key = ValidateKey(source, true); string ToReverse = Symbols[key].Item1; string[] words = ToReverse.Split(' '); - StringBuilder reversed = new StringBuilder(); + StringBuilder reversed = new(); for (int i = words.Length - 1; i >= 0; i--) { reversed.Append(words[i]); @@ -526,6 +525,7 @@ namespace Assignment_1 string errorMSG = new string(' ', (caratPos - lineStart) >= 0 ? (int)(caratPos - lineStart) : 0) + "^ " + errorMessage; Console.WriteLine(fullLine); Console.WriteLine(errorMSG); + source.Position = lineStart; source.SetLength(source.Position); } #endregion @@ -614,7 +614,7 @@ namespace Assignment_1 if (!Symbols.ContainsKey(keyValue)) { - throw new ParserException("Could not find key: " + keyValue, 0); + throw new ParserException("Could not find key: " + keyValue, 0, s.Position); } returnedValue = Symbols[keyValue].Item1; return t; @@ -654,7 +654,6 @@ namespace Assignment_1 // Is a literal. Now we must parse until we find the end of the literal // Remove the first char, if it is a literal definition. if (PeekChar(s) == '\"') ReadChar(s); - string resultLiteral; long resultPosition = FindNextOccurance(s, (c, s) => { if (c == '\"') @@ -671,14 +670,14 @@ namespace Assignment_1 } } return false; - }, out resultLiteral); + }, out string resultLiteral); if (resultPosition > -1) { returnedLiteral = resultLiteral; } else { - throw new ParserException("Could not parse the literal"); + throw new ParserException("Could not parse the literal", 0, s.Position); } s.Position = pos; return resultPosition; @@ -918,15 +917,8 @@ namespace Assignment_1 public long LinePosition = -1; public ParserException(string message, int importance, long linePos) : base(message) { - - } - public ParserException(string message, int importance) : base(message) - { - - } - public ParserException(string message) : base(message) - { - + Importance = importance; + LinePosition = linePos; } } }