我必须解析 CIMPLICITY 的 ctx 文件。Ctx 文件示例:
(Version 42)
(DocumentSummary)
(GmmiToplevelDocument
(GmmiDocumentObject
(GmmiContainerObject
(GmmiObject "" 0
(Help "" "" "")
(GmmiPointMap
(GmmiPoint "MODBUS.HOIST.HST1.HST" 8 0 1)
(GmmiPoint "MODBUS.HOIST.HST2.MAXVAL" 9 0 1))
(GmmiOptionTable
(GmmiVariables))
(GmmiTabOrder -1)) (Color 3 8) (Color 3 5)
(Font "Arial" 0 280 1 0)
(GmmiObjectPtrList
(GmmiOleObject
(GmmiObject "" 0
(Help "" "" "")
(Empty)
(GmmiTabOrder 0)) 0
(Extents
(Rect 180 6840 6255 3825)
(Rect 180 6840 6255 3825))
(Border (Color 1 &hff000000) 0 11 0)
(Interior (Color 0) (Color 1 &hff000000) 1)
(Interior (Color 1 &hff000000) (Color 1 &hff000000) 1) 0 0 1000 1000 1000 1000
(Rect 180 6840 6255 3825) "TREND.TrendCtrl.1"
(OleMagic 0)
(GROleControl
(OlePropBag {B4E7803D-9435-11CE-9CF4-0020AF743F4D}
"BInLegend1" 1
"BaseProject" "MOD_TEST"
"Color1" 255
"CompressionSampleUnits1" 0
"Name1" "MODBUS.HOIST.HST1.HST"
"Name2" "Chart X Axis"
"Name3" "Chart Y Axis"
"NumberLines" 1
"Order1" 0
"PointID1" "MODBUS.HOIST.HST1.HST"
"Type1" 7
"Type3" 1
"_ExtentX" 10716
"_ExtentY" 5318
"_StockProps" 13
"_Version" 393220)))
(GmmiTextObject
(GmmiObject "" 0
(Help "" "" "")
(Empty)
(GmmiTabOrder -1)) 23
(Extents
(Rect 180 3600 3144 2752)
(Rect 180 3600 1776 2752))
(Font "" 0 720 1 0)
(Interior (Color 1 &hff000000) (Color 1 &hffffffff) 1)
(Border (Color 1 &hff000000) 0 11 0) 18
(Point 180 3600) "HOIST 1")
(GmmiTextObject
(GmmiObject "" 0
(Help "" "" "")
(GmmiOptionTable
(GmmiOptionTable
(GmmiValueAnim
(GmmiExprAnim 3
(GmmiExpr "MODBUS.HOIST.HST1.HST")) 0
(ExecCond "" "") "%s" 4)))
(GmmiTabOrder -1)) 23
(Extents
(Rect 3240 3600 4436 2964)
(Rect 3240 3420 4436 2784))
(Font "" 0 540 1 0)
(Interior (Color 1 &hff000000) (Color 1 &hffffffff) 1)
(Border (Color 1 &hff000000) 0 11 0) 18
(Point 3240 3600) "Text")
(GmmiTextObject
(GmmiObject "" 0
(Help "" "" "")
(Empty)
(GmmiTabOrder -1)) 23
(Extents
(Rect 360 1800 1662 1471)
(Rect 360 1800 1662 1471))
(Font "Arial" 0 -280 1 0)
(Interior (Color 1 &hff000000) (Color 1 &hffffffff) 1)
(Border (Color 1 &hff000000) 0 11 0) 18
(Point 360 1800) "Test data:")
(GmmiTextObject
(GmmiObject "" 0
(Help "" "" "")
(GmmiOptionTable
(GmmiOptionTable
(GmmiValueAnim
(GmmiExprAnim 3
(GmmiExpr "MODBUS.HOIST.HST2.MAXVAL")) 0
(ExecCond "" "") "%s" 4)))
(GmmiTabOrder -1)) 23
(Extents
(Rect 1980 1800 2599 1471)
(Rect 1980 1800 2599 1471))
(Font "Arial" 0 -280 1 0)
(Interior (Color 1 &hff000000) (Color 1 &hffffffff) 1)
(Border (Color 1 &hff000000) 0 11 0) 18
(Point 1980 1800) "Text")) 0
(GmmiBackdrop
(Border (Color 1 &hff000000) 0 11 0)
(Interior (Color 1 &hffc0c0c0) (Color 1 &hff000000) 1))))
(Point 100 100)
(Size 9600 7200) 100 "")
(OleItems)
上面的文件代表 CIMPLICITY 的屏幕。问题是基于该文件构建 WPF 屏幕。首先,在我看来,我应该解析该文件,删除不需要的部分,然后构建接口。
我在 Internet 上搜索了基于 .Net 的解析器 - FParsec。问题是我从来没有用 F# 编码过,而且很难理解如何使用这个库。所以我不想做额外的工作。
主要问题:是否可以将该文件解析为使用 FParsec 表示屏幕结构的自定义对象。例如,这个对象可能有这样的定义:
public class Document
{
public string Version { get; set; }
public object Summary { get; set; }
public GmmiTopLevelDocument GmmiTopLevelDocument { get; set: }
}
public class GmmiTopLevelDocument
{
public GmmiDocumentObject GmmiDocumentObject { get; set; }
public Point Point { get; set; }
public Size Size { get; set; }
}
public class GmmiDocumentObject
{
...
}
可能是方法不对?什么是对的?
更新:
我也有用于 scree 语言的BNF 。样本:
<GmmiTextButtonObject> ::= "(" GmmiTextButtonObject<GmmiButtonObject><GRTextButton>")"
<GmmiTextObject> ::= "(" GmmiTextObject<GmmiGraphicObject> <GRText> ")"
<ToplevelDocument> ::= "(" GmmiToplevelDocument<GmmiDocument><initialPosition.Point><Size>zoom.number> ")"
<ToplevelDocumentPO> ::= <GmmiPointMap><ambientForeground.GRColorAttr><ambientBackground.GRColorAttr>
<ambientFont.GRFontAttr>
<GmmiProcedureMap>