hs
Size: a a a
hs
hs
let dfProp = parser |>> (fun str node -> DfProp str node)hs
let dfProp = returnString "common" (fun str node -> DFProp(str, node))hs
hs
let dfProp = nodeParser (fun node str -> DFProp(str, node))hs
VS
abcd: "xxx"abcd и dcba это common
dbca {
aaa: 1
bbb {
}
}
hs
VS
let dfProperty =
manyCharsTill (noneOf <| seq { '{'; '}'; ' ' }) (skipString ": ") .>>. dfLiteral .>> spaces
|>> DFProperty
let dfObject =
manyCharsTill (noneOf <| seq { ':'; '}'; ' ' }) (skipString " {") .>> spaces .>>. (many dfNode) .>> (skipString "}") .>> spaces
|>> DFObject
do dfNodeRef := choice [
attempt dfProperty
attempt dfObject
]
hs
let ident = identifier(IdentifierOptions())
let common =
ident .>> spaces
let value =
between (pstring "") (pstring "") ident
|>> fun _ -> Value
let prop =
value |>> fun node str -> Prop (str, node "")
let obj =
pchar ':' >>. spaces >>.
many (between (pstring "{") (pstring "}") value) .>> spaces
|>> fun nodes str -> Obj (str, (nodes |> List.map (fun f -> f "")))
let node: Parser<_, unit> = (pipe2 common (choice [obj; prop; value]) (|>))hs
hs
VS
let ident = identifier(IdentifierOptions())
let common =
ident .>> spaces
let value =
between (pstring "") (pstring "") ident
|>> fun _ -> Value
let prop =
value |>> fun node str -> Prop (str, node "")
let obj =
pchar ':' >>. spaces >>.
many (between (pstring "{") (pstring "}") value) .>> spaces
|>> fun nodes str -> Obj (str, (nodes |> List.map (fun f -> f "")))
let node: Parser<_, unit> = (pipe2 common (choice [obj; prop; value]) (|>))hs
type DFNode =
| DFLiteral of string
| DFProperty of string * DFNode
| DFObject of string * DFNode list
let dfNode, dfNodeRef = createParserForwardedToRef()
let ident = identifier(IdentifierOptions())
let dfLiteral =
between (pchar '"') (pchar '"') ident .>> spaces |>> DFLiteral
let dfProperty =
pchar ':' >>. spaces1 >>. dfLiteral .>> spaces |>> (fun node str -> DFProperty (str, node))
let dfObject =
between (pchar '{' .>> spaces) (pchar '}' .>> spaces) (many dfNode)
|>> (fun node str -> DFObject (str, node))
do dfNodeRef := pipe2 common (dfProperty <|> dfObject) (|>)VS
_root_ а _ уже невалидный символ для идентификатораhs
hs
hs
hs
type DFNode =
| DFLiteral of string
| DFProperty of string * DFNode
| DFObject of string * DFNode list
let dfNode, dfNodeRef = createParserForwardedToRef ()
let ident: Parser<_, unit> = identifier (IdentifierOptions())
let dfLiteral =
between (pchar '"') (pchar '"') ident
|>> DFLiteral
let dfProperty =
pchar ':' >>. spaces >>. dfLiteral
|>> fun node str -> DFProperty(str, node)
let dfObject =
between (pchar '{' .>> spaces) (spaces >>. pchar '}') (many dfNode)
|>> fun node str -> DFObject(str, node)
do dfNodeRef :=
spaces >>. pipe2 (ident .>> spaces) (dfProperty <|> dfObject) (|>) <|> dfLiteral .>> spaces
let test p i =
match run (p .>> eof) i with
| Success (v, _, _) -> printfn "%A" v
| Failure (e, _, _) -> printfn "%s" e
let x1 = "abcd: \"xxx\""
let x2 = """
dbca {
"xxx"
"yyy"
}
"""
test dfNode x1
test dfNode x2