//[Test] static async Task ParseTest() { var pTexts = new[] { //"20$", //"20", //"20x", //"(20)", //"3 - 2 * 6 - 1", //"20x+30y+20x^2-x+100", //"-(3x-2)", //"2x(3+x)(x-2)6", //"20a+3b+c=1", //"2x(3+x", //"(sin (x))^2=1", //"(sin (x))^2+(cos (x))^2=1" //"x", "2x=3", //"20a+3b+c=1\nb=20", }; foreach (var pText in pTexts) { try { using (var pReader = new StringReader(pText)) { Console.WriteLine($"{pText} :"); var pParser = new ST.Parser2(pReader, CancellationToken.None); var pExpr = await pParser.Parse(); Console.WriteLine(pExpr); } } catch (ST.STException ex) { var pLine = string.Empty; using (var pReader = new StringReader(pText)) { for (var i = ex.Line; i > 0; i--) { pLine = pReader.ReadLine(); } } PrintError(ex.Message); PrintError(pLine); PrintError($"{new string(' ', ex.Position - 1)}^"); } catch (Exception ex) { PrintError(ex.Message); } } }
//[Test] static async Task ParseLinesTest() { var pTexts = new[] { "20a+3b+c=1", "20a+3b+c=1\nb=20", }; foreach (var pText in pTexts) { try { using (var pReader = new StringReader(pText)) { Console.WriteLine($"{pText} :"); var pParser = new ST.Parser2(pReader, CancellationToken.None); var pExprs = await pParser.ParseLines(); foreach (var e in pExprs) { Console.WriteLine(e); } } } catch (ST.STException ex) { var pLine = string.Empty; using (var pReader = new StringReader(pText)) { for (var i = ex.Line; i > 0; i--) { pLine = pReader.ReadLine(); } } PrintError(ex.Message); PrintError(pLine); PrintError($"{new string(' ', ex.Position - 1)}^"); } catch (Exception ex) { PrintError(ex.Message); } } }