more work qmlfrontend
authorunc0rr
Tue, 08 Sep 2015 19:20:58 +0300
branchqmlfrontend
changeset 11076 fcbdee9cdd74
parent 11075 842eb00b36ac
child 11408 b894922d58cc
more work
tools/protocolParser.hs
--- a/tools/protocolParser.hs	Sat Sep 05 20:12:49 2015 +0300
+++ b/tools/protocolParser.hs	Tue Sep 08 19:20:58 2015 +0300
@@ -31,6 +31,8 @@
 cmd1 s p = Command s [p]
 cmd2 s p1 p2 = Command s [p1, p2]
 
+cmdName (Command n _) = n
+
 cmdParams2str (Command _ p) = "TCmdParam" ++ concatMap f p
     where
     f Skip = ""
@@ -133,7 +135,7 @@
         zeroChar = text "#0: state:= pstDisconnected;"
         elsePart = text "else <unknown cmd> end;"
 
-renderArrays (letters, commands, handlers) = vcat $ punctuate (char '\n') [cmds, l, s, {-bodies, -}c, structs, realHandlers]
+renderArrays (letters, commands, handlers) = vcat $ punctuate (char '\n') [cmds, l, s, {-bodies, -}c, structs, realHandlers, realHandlersArray]
     where
         maybeQuotes "$" = text "#0"
         maybeQuotes s = if null $ tail s then quotes $ text s else text s
@@ -153,6 +155,8 @@
         cmds = text "type TCmdType = " <> parens (hsep $ punctuate comma $ map ((<>) (text "cmd_") . text) $ reverse fixedNames) <> semi
         structs = vcat (map text . Set.toList . Set.fromList $ map cmdParams2record commandsDescription)
         realHandlers = vcat $ punctuate (char '\n') $ map rh sortedCmdDescriptions
+        realHandlersArray = text "const handlers: array[TCmdType] of PHandler = "
+            <> parens (hsep . punctuate comma . (:) (text "@handler__UNKNOWN_") $ map (text . (++) "@handler_" . fixName . cmdName) sortedCmdDescriptions) <> semi
 
 rh cmd@(Command n p) = text "procedure handler_" <> text (fixName n) <> parens (text "var p: " <> text (cmdParams2str cmd)) <> semi
     $+$ emptyBody $+$ if hasMany then vcat [space, text "procedure handler_" <> text (fixName n) <> text "_s" <> parens (text "var s: shortstring") <> semi