且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

FParsec-如何从标准输入流进行解析

更新时间:2023-11-17 23:31:04

出于性能原因和简单性考虑,FParsec逐块读取输入流(或在开始解析之前将完整的流读取为字符串).参见例如此答案以获取更多详细信息:使用FParsec进行分块分析

For performance reasons and simplicity, FParsec reads input streams block-wise (or reads the complete stream into a string before starting to parse). See e.g. this answer for some more details: Chunked Parsing with FParsec

如果要使用FParsec解析来自REPL的输入,则可以实现一个简单的扫描程序,该扫描程序等待输入流中的终止符(例如,";;"后跟换行符,例如FSI控制台中的)然后,当遇到这样的终结符时,将直到终结符的输入复制到字符串中,然后将其交给FParsec解析器进行评估.

If you want to parse the input from a REPL with FParsec, you could implement a simple scanner that waits for a terminator in the input stream (e.g. a ";;" followed by a newline, like in the FSI console) and then, when it encounters such a terminator, copies the input up to the terminator into a string and hands it over to an FParsec parser for evaluation.