The following top-level XML parser definition returns the error The value or constructor ‘TOP_LEVEL_RECORD’ is not defined. …
let xTop_Level, xTop_Level_Ref = createParserForwardedToRef<TOP_LEVEL_RECORD, unit>()
do xTop_Level_Ref :=
pipe4
(opt xDeclaration)
(opt (many xComment_or_CData))
xElement
(opt (many xComment_or_CData))
(fun decl before_root root after_root
-> {Declaration = decl
Before_Root = before_root
Root = root
After_Root = after_root}) |>> TOP_LEVEL_RECORD
// This returns the error -------------------→^^^^^^^^^^^^^^^^
TOP_LEVEL_RECORD is defined as …
type TOP_LEVEL_RECORD = {Declaration : XDECLARATION option
Before_Root : COMMENTS_OR_CDATA list option
Root : XELEMENT
After_Root : COMMENTS_OR_CDATA list option
}
The parsers xDeclaration, xCommentor_Cdata, and xElement are all correctly defined and return the corresponding types in the TOP_LEVEL_RECORD.
The let xTop_Level, xTop_Level_Ref = createParserForwardedToRef<TOP_LEVEL_RECORD, unit>() is Fparsec’s syntax for recursive parser calls documented here: http://www.quanttec.com/fparsec/tutorial.html#parsing-json.createParserForwardedToRef-example.
If I define the type type TOP_LEVEL = TOP_LEVEL_TYPE of TOP_LEVEL_RECORD and replace TOP_LEVEL_RECORD with TOP_LEVEL and TOP_LEVEL_TYPE as follows …
let xTop_Level, xTop_Level_Ref = createParserForwardedToRef<TOP_LEVEL, unit>()
// Replaced this text ------------------------------------->^^^^^^^^^
do xTop_Level_Ref :=
pipe4
(opt xDeclaration)
(opt (many xComment_or_CData))
xElement
(opt (many xComment_or_CData))
(fun decl before_root root after_root
-> {Declaration = decl
Before_Root = before_root
Root = root
After_Root = after_root}) |>> TOP_LEVEL_TYPE
// Replaced this text ----------------------->^^^^^^^^^^^^^^
... the code compiles without any errors or warnings.
Why does TOP_LEVEL_TYPE have a constructor here and not TOP_LEVEL_RECORD?
Can you point me to the relevant part of the F# or FParsec documentation?