# HG changeset patch # User unc0rr # Date 1441312386 -10800 # Node ID 3ecf0610700502a5ab759b1188e5793302a895e7 # Parent 3851ce4f2061dd67faf93a5f995ce7c4a5844266 Generate handlers accepting parameters dummies diff -r 3851ce4f2061 -r 3ecf06107005 tools/protocolParser.hs --- a/tools/protocolParser.hs Thu Sep 03 20:59:48 2015 +0300 +++ b/tools/protocolParser.hs Thu Sep 03 23:33:06 2015 +0300 @@ -130,7 +130,7 @@ zeroChar = text "#0: state:= pstDisconnected;" elsePart = text "else end;" -renderArrays (letters, commands, handlers) = vcat $ punctuate (char '\n') [cmds, l, s, bodies, c, structs] +renderArrays (letters, commands, handlers) = vcat $ punctuate (char '\n') [cmds, l, s, {-bodies, -}c, structs, realHandlers] where maybeQuotes "$" = text "#0" maybeQuotes s = if null $ tail s then quotes $ text s else text s @@ -140,7 +140,8 @@ <> parens (hsep . punctuate comma $ map text commands) <> semi c = text "const handlers: array[0.." <> (int $ length fixedNames - 1) <> text "] of PHandler = " <> parens (hsep . punctuate comma $ map (text . (:) '@') handlerTypes) <> semi - handlerTypes = map cmdParams2handlerType . reverse $ sort commandsDescription + handlerTypes = map cmdParams2handlerType sortedCmdDescriptions + sortedCmdDescriptions = reverse $ sort commandsDescription fixedNames = map fixName handlers fixName = map fixChar fixChar c | isLetter c = c @@ -151,6 +152,10 @@ $+$ text "end" <> semi 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 + rh cmd@(Command n _) = text "procedure handler_" <> text (fixName n) <> parens (text "var p: " <> text (cmdParams2str cmd)) <> semi + $+$ text "begin" + $+$ text "end" <> semi pas = renderArrays $ buildTables $ buildParseTree commandsDescription where