Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F# 如何解析在重复模式之后何时出现右键?_F#_Fparsec - Fatal编程技术网

F# 如何解析在重复模式之后何时出现右键?

F# 如何解析在重复模式之后何时出现右键?,f#,fparsec,F#,Fparsec,如何使用现有的FParsec功能在最右边的标记中查找重复的连续模式 在这种情况下,这是一种合理的可能性。预解析+转义可能有效,但有更好的解决方案吗?我们需要编写一个新的正向组合器吗?如果需要,它是什么样子的 #r"""bin\debug\FParsecCS.dll""" #r"""bin\debug\FParsec.dll""" open FParsec let str = pstring let phraseEscape = pchar '\\' >>. pchar '"' l

如何使用现有的FParsec功能在最右边的标记中查找重复的连续模式

在这种情况下,这是一种合理的可能性。预解析+转义可能有效,但有更好的解决方案吗?我们需要编写一个新的正向组合器吗?如果需要,它是什么样子的

#r"""bin\debug\FParsecCS.dll"""
#r"""bin\debug\FParsec.dll"""

open FParsec

let str = pstring
let phraseEscape = pchar '\\' >>. pchar '"'
let phraseChar = phraseEscape <|> (noneOf "|\"\r\n]")    // <- this right square bracket needs to be removed
let phrase = manyChars phraseChar

let wrapped = between (str"[[") (str"]]".>>newline) phrase 

run wrapped "[[some text]]\n"  // <- works fine

// !! problem
run wrapped "[[array[] d]]\n"    // <- that means we can't make ']' invalid in phraseChar

// !! problem
run wrapped "[[array[]]]\n"      // <- and this means that the first ]] gets match leaving a floating one to break the parser
#r“bin\debug\FParsecCS.dll”
#r“bin\debug\FParsec.dll”
开放式FParsec
设str=pstring
让短语escape=pchar'\\'>>。pchar''
让phraseChar=phrasescape(非“| \”\r\n]”/>换行符)短语

运行包装“[[一些文本]]\n”//很抱歉回答我自己的问题,但是

请参阅可组合函数phraseTill,以及传递给它的pend解析器(不遵循(s“]]”>。(s“]>)


注意。如果您在FSharp Interactive(FSI)中尝试此操作,请确保在将文本发送到FSI进行评估时至少有一行“运行包装”行(即右键单击“在Interactive中执行”)。在本例中,该类型仅在应用程序上被推断/固定。我们本可以提供明确的定义,但要冒更加冗长的风险。

@Vesa.A.J.K:我没有定义语言,所以我没有做自己事情的奢侈。除了这个奇怪的角落案例,它的可读性很强,几乎与上下文无关。有些工作可能会进入FSharp.Data,但我还没有准备好。泰。
#r"""bin\debug\FParsecCS.dll"""
#r"""bin\debug\FParsec.dll"""

open FParsec

let s = pstring
let phraseChar = (noneOf "\r\n")   
let phrase = manyChars phraseChar
/// keep eating characters until the pend parser is successful
let phraseTill pend = manyCharsTill phraseChar pend

/// when not followed by tipple, a double will truly be the end
let repeatedTo repeatedPtrn ptrn = notFollowedBy(s repeatedPtrn)>>.(s ptrn) 
let wrapped = (s"[[")>>.phraseTill (repeatedTo "]]]" "]]")
run wrapped "[[some text]]]"
run wrapped "[[some text]]"