brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame^] | 1 | class MessageElementReq |
| 2 | def initialize(type,name) |
| 3 | @type = type |
| 4 | @name = name |
| 5 | end |
| 6 | def self.parse(tokens) |
| 7 | type = tokens.expect(:tWord).data |
| 8 | name = tokens.expect(:tWord).data |
| 9 | tokens.expect(:tSemi) |
| 10 | return self.new(type,name) |
| 11 | end |
| 12 | end |
| 13 | class QueueReq |
| 14 | def initialize(name,type = nil) |
| 15 | @name = name |
| 16 | @type = type |
| 17 | end |
| 18 | def self.parse(tokens) |
| 19 | type_or_name = tokens.expect(:tWord).data |
| 20 | if(tokens.peak == :tSemi) |
| 21 | tokens.expect(:tSemi) |
| 22 | return self.new(type_or_name) |
| 23 | else |
| 24 | name = tokens.expect(:tWord).data |
| 25 | tokens.expect(:tSemi) |
| 26 | return self.new(name,type_or_name) |
| 27 | end |
| 28 | end |
| 29 | end |
| 30 | class InterfaceStmt < QStmt |
| 31 | def initialize(name,elements) |
| 32 | @name = name |
| 33 | @elements = elements |
| 34 | end |
| 35 | def q_eval(locals) |
| 36 | |
| 37 | end |
| 38 | def self.check_type(tokens,new_type,old_type) |
| 39 | return new_type if(old_type == nil) |
| 40 | if(new_type != old_type) |
| 41 | tokens.qError(<<ERROR_MSG) |
| 42 | error: intermixing queue definitions (a queue_group feature) |
| 43 | and type definitions (a message_group feature) |
| 44 | this results in an undefined type value. |
| 45 | Wot. Wot. |
| 46 | ERROR_MSG |
| 47 | end |
| 48 | return old_type |
| 49 | end |
| 50 | def self.parse(tokens) |
| 51 | name = tokens.expect(:tWord).data |
| 52 | values = [] |
| 53 | type = nil |
| 54 | tokens.expect(:tOpenB) |
| 55 | while(tokens.peak != :tCloseB) |
| 56 | if(tokens.peak.data == "queue") |
| 57 | tokens.expect(:tWord) |
| 58 | values << QueueReq.parse(tokens) |
| 59 | type = check_type(tokens,:queue_group,type) |
| 60 | else |
| 61 | values << MessageElementReq.parse(tokens) |
| 62 | type = check_type(tokens,:message_group,type) |
| 63 | end |
| 64 | end |
| 65 | tokens.expect(:tCloseB) |
| 66 | tokens.expect(:tSemi) |
| 67 | self.new(name,values) |
| 68 | end |
| 69 | end |