MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / read

Method read

src/main/java/wyc/io/WhileyFileParser.java:167–201  ·  view source on GitHub ↗

Read a WhileyFile from the token stream. If the stream is invalid in some way (e.g. contains a syntax error, etc) then a SyntaxError is thrown. @return

()

Source from the content-addressed store, hash-verified

165 * @return
166 */
167 public boolean read() {
168 boolean status = true;
169 ArrayList<Decl> declarations = new ArrayList<>();
170 Name name = new Name(new Identifier(path.last()));
171 try {
172 name = parseModuleName(path);
173 skipWhiteSpace();
174 while (index < tokens.size()) {
175 // Parse next logical declaration
176 declarations.add(parseDeclaration());
177 skipWhiteSpace();
178 }
179 } catch (ParseError e) {
180 // Allocate an unknown declaration to represent this parse error.
181 Decl d = target.allocate(new Decl.Unknown());
182 // Add to declarations for enclosing unit
183 declarations.add(d);
184 // Give the unknown declaration a span corresponding to exact point of error.
185 target.allocate(new Attribute.Span(d, e.getStart(), e.getEnd()));
186 // Generate a syntax error which identifies the parse error
187 ErrorMessages.syntaxError(d, e.getErrorCode(), e.context);
188 // Signal that we have failed
189 status = false;
190 }
191 // Finally, construct the new file.
192 Tuple<Decl> decls = new Tuple<>(declarations);
193 Decl.Unit module = new Decl.Unit(name, decls);
194 //
195 Decl.Unit nunit = target.allocate(module);
196 Decl.Unit ounit = target.getModule().putUnit(nunit);
197 if (ounit != null) {
198 target.replace(ounit, nunit);
199 }
200 return status;
201 }
202
203 private Name parseModuleName(Trie id) {
204 ArrayList<Identifier> components = new ArrayList<>();

Callers 1

compileMethod · 0.95

Calls 14

parseModuleNameMethod · 0.95
skipWhiteSpaceMethod · 0.95
parseDeclarationMethod · 0.95
syntaxErrorMethod · 0.95
lastMethod · 0.80
putUnitMethod · 0.80
getModuleMethod · 0.80
sizeMethod · 0.65
addMethod · 0.65
allocateMethod · 0.65
getStartMethod · 0.65
getEndMethod · 0.65

Tested by

no test coverage detected