tools/protocolParser.hs
author unc0rr
Tue, 28 Apr 2015 11:49:48 +0300
branchqmlfrontend
changeset 10902 29519fe63fdd
parent 10900 6a805e822074
child 10904 ce265b038220
permissions -rw-r--r--
Will use own tree type
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
     1
module Main where
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
     2
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
     3
import Text.PrettyPrint.HughesPJ
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
     4
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
     5
data HWProtocol = Command String [CmdParam]
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
     6
data CmdParam = Skip
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
     7
              | SS
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
     8
              | LS
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
     9
              | IntP
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    10
              | Many [CmdParam]
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    11
data ClientStates = NotConnected
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    12
                  | JustConnected
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    13
                  | ServerAuth
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    14
                  | Lobby
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    15
10902
29519fe63fdd Will use own tree type
unc0rr
parents: 10900
diff changeset
    16
data ParseTree = PTChar Char [ParseTree]
29519fe63fdd Will use own tree type
unc0rr
parents: 10900
diff changeset
    17
               | PTCommand HWProtocol
29519fe63fdd Will use own tree type
unc0rr
parents: 10900
diff changeset
    18
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    19
cmd = Command
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    20
cmd1 s p = Command s [p]
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    21
cmd2 s p1 p2 = Command s [p1, p2]
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    22
10902
29519fe63fdd Will use own tree type
unc0rr
parents: 10900
diff changeset
    23
breakCmd (Command (c:cs) params) = (c, Command cs params)
29519fe63fdd Will use own tree type
unc0rr
parents: 10900
diff changeset
    24
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    25
commands = [
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    26
        cmd "CONNECTED" [Skip, IntP]
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    27
        , cmd1 "NICK" SS
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    28
        , cmd1 "PROTO" IntP
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    29
        , cmd1 "ASKPASSWORD" SS
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    30
        , cmd1 "SERVER_AUTH" SS
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    31
        , cmd1 "LOBBY:JOINED" $ Many [SS]
10902
29519fe63fdd Will use own tree type
unc0rr
parents: 10900
diff changeset
    32
        , cmd2 "LOBBY:LEFT" $ SS SS
29519fe63fdd Will use own tree type
unc0rr
parents: 10900
diff changeset
    33
        , cmd2 "CLIENT_FLAGS" $ SS $ Many [SS]
29519fe63fdd Will use own tree type
unc0rr
parents: 10900
diff changeset
    34
        , cmd1 "SERVER_MESSAGE" LS
10898
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    35
    ]
f373838129c2 Some futher work on flib net client part
unc0rr
parents:
diff changeset
    36
10902
29519fe63fdd Will use own tree type
unc0rr
parents: 10900
diff changeset
    37
29519fe63fdd Will use own tree type
unc0rr
parents: 10900
diff changeset
    38
10900
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
    39
pas = 
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
    40
    
6a805e822074 Some hedgewars coding a week keeps doctor away
unc0rr
parents: 10898
diff changeset
    41
main = putStrLn $ render pas