Pregunta

Estoy implementando un analizador que trata los comentarios como espacio en blanco con FPARSEC. Parece que requiere una conversión de analizador trivial, pero aún no sé cómo implementar eso.

Aquí está el código que estoy tratando de verificar tipo -

let whitespaceTextChars = " \t\r\n"

/// Read whitespace characters.
let whitespaceText = many (anyOf whitespaceTextChars)

/// Read a line comment.
let lineComment = pchar lineCommentChar >>. restOfLine true

/// Skip any white space characters.
let skipWhitespace = skipMany (lineComment <|> whitespaceText)

/// Skip at least one white space character.
let skipWhitespace1 = skipMany1 (lineComment <|> whitespaceText)

El error está en el segundo argumento de ambos <|> operadores ( whitespaceText). Los errores son -

Error   1   Type mismatch. Expecting a     Parser<string,'a>     but given a     Parser<char list,'a>     The type 'string' does not match the type 'char list'
Error   2   Type mismatch. Expecting a     Parser<string,'a>     but given a     Parser<char list,'a>     The type 'string' does not match the type 'char list'

Parece que necesito convertir un Parser<char list, 'a> a un Parser<string, 'a>. O, como solo me estoy saltando, podría convertirlos a ambos a Parser<unit, 'a>. Sin embargo, no sé cómo escribir ese código. ¿Es una expresión lambda simple?

¡Salud!

¿Fue útil?

Solución

let whitespaceText = manyChars (anyOf whitespaceTextChars)

o

let whitespaceText = many (anyOf whitespaceTextChars) |>> fun cs -> System.String (Array.ofList cs)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top