added lexer and parser basics
This commit is contained in:
+10
-4
@@ -3,31 +3,37 @@ package p.studio.compiler.messages;
|
||||
import p.studio.utilities.structures.ReadOnlyCollection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BuildingIssueSink extends ReadOnlyCollection<BuildingIssue> {
|
||||
public class BuildingIssueSink implements ReadOnlyCollection<BuildingIssue> {
|
||||
private final ArrayList<BuildingIssue> issues = new ArrayList<>();
|
||||
private boolean hasErrors = false;
|
||||
|
||||
protected BuildingIssueSink() {
|
||||
super(new ArrayList<>());
|
||||
}
|
||||
|
||||
public static BuildingIssueSink empty() {
|
||||
return new BuildingIssueSink();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<BuildingIssue> asCollection() {
|
||||
return issues;
|
||||
}
|
||||
|
||||
public BuildingIssueSink report(final Consumer<BuildingIssue.BuildingIssueBuilder> consumer) {
|
||||
final var builder = BuildingIssue.builder();
|
||||
consumer.accept(builder);
|
||||
final var issue = builder.build();
|
||||
hasErrors |= issue.isError();
|
||||
collection.add(issue);
|
||||
issues.add(issue);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BuildingIssueSink merge(final BuildingIssueSink issues) {
|
||||
hasErrors |= issues.hasErrors();
|
||||
collection.addAll(issues.collection);
|
||||
this.issues.addAll(issues.issues);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -2,6 +2,7 @@ package p.studio.compiler.models;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
import p.studio.compiler.utilities.SourceProvider;
|
||||
import p.studio.compiler.utilities.SourceProviderFactory;
|
||||
@@ -26,6 +27,8 @@ public class SourceHandle {
|
||||
@Getter
|
||||
private final String filename;
|
||||
@Getter
|
||||
private final String extension;
|
||||
@Getter
|
||||
private final long size;
|
||||
@Getter
|
||||
private final long lastModified;
|
||||
@@ -42,6 +45,7 @@ public class SourceHandle {
|
||||
this.relativePath = relativePath;
|
||||
this.canonPath = canonPath;
|
||||
this.filename = canonPath.getFileName().toString();
|
||||
this.extension = FilenameUtils.getExtension(this.filename);
|
||||
this.size = size;
|
||||
this.lastModified = lastModified;
|
||||
this.provider = factory.create(canonPath);
|
||||
|
||||
+9
-3
@@ -4,21 +4,27 @@ import p.studio.compiler.source.Span;
|
||||
import p.studio.utilities.structures.ReadOnlyCollection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DiagnosticSink extends ReadOnlyCollection<Diagnostic> {
|
||||
public class DiagnosticSink implements ReadOnlyCollection<Diagnostic> {
|
||||
private final ArrayList<Diagnostic> diagnostics = new ArrayList<>();
|
||||
private int errorCount = 0;
|
||||
private int warningCount = 0;
|
||||
|
||||
protected DiagnosticSink() {
|
||||
super(new ArrayList<>());
|
||||
}
|
||||
|
||||
public static DiagnosticSink empty() {
|
||||
return new DiagnosticSink();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Diagnostic> asCollection() {
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
public DiagnosticSink report(final Diagnostic diagnostic) {
|
||||
Objects.requireNonNull(diagnostic);
|
||||
if (diagnostic.getSeverity().isError()) {
|
||||
@@ -26,7 +32,7 @@ public class DiagnosticSink extends ReadOnlyCollection<Diagnostic> {
|
||||
} else {
|
||||
warningCount++;
|
||||
}
|
||||
collection.add(diagnostic);
|
||||
diagnostics.add(diagnostic);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -6,9 +6,9 @@ import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
|
||||
public class FileTable extends InternTable<FileId, SourceHandle> implements FileTableReader {
|
||||
|
||||
@@ -23,20 +23,20 @@ public class FileTable extends InternTable<FileId, SourceHandle> implements File
|
||||
@Override
|
||||
public FileId register(final SourceHandle value) {
|
||||
final var fileId = super.register(value);
|
||||
projectFiles[value.getProjectId().getIndex()].set.add(fileId);
|
||||
projectFiles[value.getProjectId().getIndex()].collection.add(fileId);
|
||||
return fileId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadOnlyList<FileId> getFiles(final ProjectId projectId) {
|
||||
final var fileIds = projectFiles[projectId.getIndex()];
|
||||
if (CollectionUtils.isEmpty(fileIds.set)) {
|
||||
if (CollectionUtils.isEmpty(fileIds.collection)) {
|
||||
return ReadOnlyList.empty();
|
||||
}
|
||||
return ReadOnlyList.wrap(fileIds.set);
|
||||
return ReadOnlyList.wrap(fileIds.collection);
|
||||
}
|
||||
|
||||
private static class FileIds {
|
||||
public final Set<FileId> set = new HashSet<>();
|
||||
public final List<FileId> collection = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user