public FileSyntax Parse() { var ps = new ParseState(); ps.Position = 0; ps.Tokens = _tokenizer.Tokenize().ToList(); return(FileSyntax.Parser.Get.Parse(ps).First().Node as FileSyntax); /*var r = 0; * foreach (var parseResult in FileSyntax.Parser.Get.Parse(ps)) * { * r++; * return parseResult.Node as FileSyntax; * } * * if (r == 0) * { * throw new Exception("Failed to parse"); * } * * if (r > 1) * { * throw new Exception($"Ambiguous ({r})"); * }*/ }
public FileSyntax Parse() { var ps = new ParseState(); ps.Position = 0; ps.Tokens = _tokenizer.Tokenize().ToList(); return((FileSyntax.Parser.Get.Parse(ps).FirstOrDefault()?.Node as FileSyntax) ?? throw new InvalidDataException("Parsing failed. There may be syntax errors.")); /*var r = 0; * foreach (var parseResult in FileSyntax.Parser.Get.Parse(ps)) * { * r++; * return parseResult.Node as FileSyntax; * } * * if (r == 0) * { * throw new Exception("Failed to parse"); * } * * if (r > 1) * { * throw new Exception($"Ambiguous ({r})"); * }*/ }