blob: 136834f52afce011fb7fe8956f635ce9a6017cb6 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001class QueueGroupTypeStmt < QStmt
2 def initialize(name,suite)
3 @name,@suite = name,suite
4 end
5 def q_eval(locals)
6 group = Target::QueueGroupDec.new(@name)
7 group.created_by = self
8 locals.register(group)
9 @suite.each do |stmt|
10 stmt.q_eval(locals.bind(group))
11 end
12 return group
13 end
14end
15class ImplementsStmt < QStmt
16 def initialize(name)
17 @name = name
18 end
19 def q_eval(locals)
20
21 end
22 def self.parse(tokens)
23 name = QualifiedName.parse(tokens)
24 tokens.expect(:tSemi)
25 return self.new(name)
26 end
27end
28class QueueGroupStmt < QStmt
29 def initialize(type,name)
30 @type,@name = type,name
31 end
32 def q_eval(locals)
33 group = Target::QueueGroup.new(@type.lookup(locals),@name)
34 group.created_by = self
35 locals.register(group)
36 return group
37 end
38 def self.parse(tokens)
39 line = tokens.pos
40 type_name = QualifiedName.parse(tokens)
41 if(type_name.names.include?("queue_group"))
42 tokens.qError(<<ERROR_MSG)
43I was looking at the identifier you gave
44\tfor the queue group type between line #{line} and #{tokens.pos}
45\tThere shouldn't be a queue_group type called queue_group
46\tor including queue_group in it's path, it is a reserved keyword.
47\tWot. Wot.
48ERROR_MSG
49 end
50 if(tokens.peak == :tOpenB)
51 if(type_name.is_simple?())
52 type_name = type_name.to_simple
53 else
54 tokens.qError(<<ERROR_MSG)
55You gave the name: "#{type_name.to_s}" but you're only allowed to
56\thave simple names like "#{type_name.names[-1]}" in queue_group definitions
57\ttry something like:
58\tqueue_group ControlLoop { }
59\tWot. Wot.
60ERROR_MSG
61 end
62 tokens.expect(:tOpenB)
63 suite = []
64 while(tokens.peak != :tCloseB)
65 token = tokens.expect(:tWord) do |token|
66 <<ERROR_MSG
67I'm a little confused, I found a #{token.humanize} at #{token.pos}
68\tbut what I really wanted was an identifier signifying a nested
69\tmessage declaration, or queue definition, or an impliments statement.
70\tWot.Wot
71ERROR_MSG
72 end
73 case token.data
74 when "message"
75 suite << MessageStmt.parse(tokens)
76 when "queue"
77 suite << QueueStmt.parse(tokens)
78 when "implements"
79 suite << ImplementsStmt.parse(tokens)
80 else
81 tokens.qError(<<ERROR_MSG)
82expected a "queue","implements" or "message" statement rather
83\tthan a #{token.data.inspect}.
84\tWot. Wot.
85ERROR_MSG
86 end
87 end
88 tokens.expect(:tCloseB)
89 obj = QueueGroupTypeStmt.new(type_name,suite).set_line(line)
90 else
91 name = (tokens.expect(:tWord) do |token|
92 <<ERROR_MSG
93I found a #{token.humanize} at #{token.pos}
94\tbut I was in the middle of parsing a queue_group statement, and
95\twhat I really wanted was an identifier to store the queue group.
96\tSomething like: queue_group control_loops.Drivetrain my_cool_group;
97\tWot.Wot
98ERROR_MSG
99 end).data
100 obj = QueueGroupStmt.new(type_name,name).set_line(line)
101 if(tokens.peak == :tDot)
102 tokens.qError(<<ERROR_MSG)
103Hey! It looks like you're trying to use a complex identifier at: #{tokens.pos}
104\tThats not going to work. Queue Group definitions have to be of the form:
105\tqueue_group ComplexID SimpleID
106\tWot. Wot.
107ERROR_MSG
108 end
109 end
110 tokens.expect(:tSemi) do |token|
111 token.pos
112 end
113 return obj
114 end
115end