Package: BindReader

BindReader

nameinstructionbranchcomplexitylinemethod
BindReader(LexTokenReader)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
readBind()
M: 2 C: 50
96%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 17
100%
M: 0 C: 1
100%
readBindList()
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
readMultipleBind()
M: 13 C: 55
81%
M: 3 C: 5
63%
M: 3 C: 3
50%
M: 4 C: 15
79%
M: 0 C: 1
100%
readPatternOrBind()
M: 17 C: 42
71%
M: 2 C: 0
0%
M: 1 C: 1
50%
M: 4 C: 13
76%
M: 0 C: 1
100%
readSetSeqBind()
M: 13 C: 43
77%
M: 3 C: 4
57%
M: 3 C: 2
40%
M: 3 C: 12
80%
M: 0 C: 1
100%
readTypeBind()
M: 4 C: 23
85%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 6
86%
M: 0 C: 1
100%
readTypeBindList()
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (c) 2008 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.parser.syntax;
25:
26: import java.util.List;
27: import java.util.Vector;
28:
29: import org.overture.ast.factory.AstFactory;
30: import org.overture.ast.lex.VDMToken;
31: import org.overture.ast.patterns.ADefPatternBind;
32: import org.overture.ast.patterns.ATypeBind;
33: import org.overture.ast.patterns.PBind;
34: import org.overture.ast.patterns.PMultipleBind;
35: import org.overture.ast.patterns.PPattern;
36: import org.overture.config.Release;
37: import org.overture.config.Settings;
38: import org.overture.parser.lex.LexException;
39: import org.overture.parser.lex.LexTokenReader;
40:
41: /**
42: * A syntax analyser to parse set and type binds.
43: */
44:
45: public class BindReader extends SyntaxReader
46: {
47:         public BindReader(LexTokenReader reader)
48:         {
49:                 super(reader);
50:         }
51:
52:         public ADefPatternBind readPatternOrBind() throws ParserException,
53:                         LexException
54:         {
55:                 ParserException bindError = null;
56:
57:                 try
58:                 {
59:                         reader.push();
60:                         PBind bind = readBind();
61:                         reader.unpush();
62:                         return AstFactory.newADefPatternBind(bind.getLocation(), bind);
63:                 } catch (ParserException e)
64:                 {
65:                         e.adjustDepth(reader.getTokensRead());
66:                         reader.pop();
67:                         bindError = e;
68:                 }
69:
70:                 try
71:                 {
72:                         reader.push();
73:                         PPattern p = getPatternReader().readPattern();
74:                         reader.unpush();
75:                         return AstFactory.newADefPatternBind(p.getLocation(), p);
76:                 } catch (ParserException e)
77:                 {
78:                         e.adjustDepth(reader.getTokensRead());
79:                         reader.pop();
80:•                        throw e.deeperThan(bindError) ? e : bindError;
81:                 }
82:         }
83:
84:         public PBind readBind() throws ParserException, LexException
85:         {
86:                 ParserException setBindError = null;
87:
88:                 try
89:                 {
90:                         reader.push();
91:                         PBind bind = readSetSeqBind();
92:                         reader.unpush();
93:                         return bind;
94:                 } catch (ParserException e)
95:                 {
96:                         e.adjustDepth(reader.getTokensRead());
97:                         reader.pop();
98:                         setBindError = e;
99:                 }
100:
101:                 try
102:                 {
103:                         reader.push();
104:                         PBind bind = readTypeBind();
105:                         reader.unpush();
106:                         return bind;
107:                 } catch (ParserException e)
108:                 {
109:                         e.adjustDepth(reader.getTokensRead());
110:                         reader.pop();
111:•                        throw e.deeperThan(setBindError) ? e : setBindError;
112:                 }
113:         }
114:
115:         public PBind readSetSeqBind() throws LexException, ParserException
116:         {
117:                 PPattern pattern = getPatternReader().readPattern();
118:                 PBind sb = null;
119:
120:•                if (lastToken().is(VDMToken.IN))
121:                 {
122:•                        switch (nextToken().type)
123:                         {
124:                         case SET:
125:                                 nextToken();
126:                                 sb = AstFactory.newASetBind(pattern, getExpressionReader().readExpression());
127:                                 break;
128:
129:                         case SEQ:
130:•                                if (Settings.release == Release.CLASSIC)
131:                                 {
132:                                         throwMessage(2328, "Sequence binds are not available in classic");
133:                                 }
134:                                 
135:                                 nextToken();
136:                                 sb = AstFactory.newASeqBind(pattern, getExpressionReader().readExpression());
137:                                 break;
138:                                 
139:                         default:
140:                                 throwMessage(2000, "Expecting 'in set' or 'in seq' after pattern in binding");
141:                         }
142:                 }
143:                 else
144:                 {
145:                         throwMessage(2001, "Expecting 'in set' or 'in seq' in bind");
146:                 }
147:
148:                 return sb;
149:         }
150:
151:         public ATypeBind readTypeBind() throws LexException, ParserException
152:         {
153:                 PPattern pattern = getPatternReader().readPattern();
154:                 ATypeBind tb = null;
155:
156:•                if (lastToken().is(VDMToken.COLON))
157:                 {
158:                         nextToken();
159:                         tb = AstFactory.newATypeBind(pattern, getTypeReader().readType());
160:                 } else
161:                 {
162:                         throwMessage(2002, "Expecting ':' in type bind");
163:                 }
164:
165:                 return tb;
166:         }
167:
168:         public List<ATypeBind> readTypeBindList() throws ParserException,
169:                         LexException
170:         {
171:                 List<ATypeBind> list = new Vector<ATypeBind>();
172:                 list.add(readTypeBind());
173:
174:•                while (ignore(VDMToken.COMMA))
175:                 {
176:                         list.add(readTypeBind());
177:                 }
178:
179:                 return list;
180:         }
181:
182:         public PMultipleBind readMultipleBind() throws LexException,
183:                         ParserException
184:         {
185:                 List<PPattern> plist = getPatternReader().readPatternList();
186:                 PMultipleBind mb = null;
187:
188:•                switch (lastToken().type)
189:                 {
190:                         case IN:
191:•                                switch (nextToken().type)
192:                                 {
193:                                 case SET:
194:                                         nextToken();
195:                                         mb = AstFactory.newASetMultipleBind(plist, getExpressionReader().readExpression());
196:                                         break;
197:                                         
198:                                 case SEQ:
199:•                                        if (Settings.release == Release.CLASSIC)
200:                                         {
201:                                                 throwMessage(2328, "Sequence binds are not available in classic");
202:                                         }
203:                                         
204:                                         nextToken();
205:                                         mb = AstFactory.newASeqMultipleBind(plist, getExpressionReader().readExpression());
206:                                         break;
207:                                         
208:                                 default:
209:                                         throwMessage(2003, "Expecting 'in set' or 'in seq' after pattern in binding");
210:                                 }
211:                                 break;
212:
213:                         case COLON:
214:                                 nextToken();
215:                                 mb = AstFactory.newATypeMultipleBind(plist, getTypeReader().readType());
216:                                 break;
217:
218:                         default:
219:                                 throwMessage(2004, "Expecting 'in set', 'in seq' or ':' after patterns");
220:                 }
221:
222:                 return mb;
223:         }
224:
225:         public List<PMultipleBind> readBindList() throws ParserException,
226:                         LexException
227:         {
228:                 List<PMultipleBind> list = new Vector<PMultipleBind>();
229:                 list.add(readMultipleBind());
230:
231:•                while (ignore(VDMToken.COMMA))
232:                 {
233:                         list.add(readMultipleBind());
234:                 }
235:
236:                 return list;
237:         }
238: }