Sporadic work done in an airport

- Initial ErrorBuilder class
 - Random documentation
This commit is contained in:
Jozufozu 2021-07-07 22:08:33 -07:00
parent 865926e783
commit 8c470f3158
12 changed files with 68 additions and 14 deletions

View file

@ -113,9 +113,9 @@ public class SourceFile {
int lastEnd = 0; int lastEnd = 0;
for (Span elision : elisions) { for (Span elision : elisions) {
out.append(source, lastEnd, elision.getStart()); out.append(source, lastEnd, elision.getStartPos());
lastEnd = elision.getEnd(); lastEnd = elision.getEndPos();
} }
out.append(source, lastEnd, source.length()); out.append(source, lastEnd, source.length());

View file

@ -0,0 +1,30 @@
package com.jozufozu.flywheel.backend.pipeline.error;
import com.jozufozu.flywheel.backend.pipeline.SourceFile;
public class ErrorBuilder {
private StringBuilder internal;
public ErrorBuilder header(CharSequence msg) {
internal.append("error: ")
.append(msg);
return endLine();
}
public ErrorBuilder errorIn(SourceFile file) {
internal.append("--> ")
.append(file.name);
return endLine();
}
public ErrorBuilder line(int no, CharSequence content) {
return endLine();
}
public ErrorBuilder endLine() {
internal.append('\n');
return this;
}
}

View file

@ -1,4 +1,4 @@
package com.jozufozu.flywheel.backend.pipeline.parse; package com.jozufozu.flywheel.backend.pipeline.error;
import com.jozufozu.flywheel.backend.pipeline.SourceFile; import com.jozufozu.flywheel.backend.pipeline.SourceFile;
import com.jozufozu.flywheel.backend.pipeline.span.Span; import com.jozufozu.flywheel.backend.pipeline.span.Span;
@ -9,6 +9,8 @@ public class ErrorReporter {
public String generateSpanError(Span span, String message) { public String generateSpanError(Span span, String message) {
SourceFile file = span.getSourceFile(); SourceFile file = span.getSourceFile();
return ""; return "";
} }
} }

View file

@ -1,5 +1,6 @@
package com.jozufozu.flywheel.backend.pipeline.parse; package com.jozufozu.flywheel.backend.pipeline.parse;
import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter;
import com.jozufozu.flywheel.backend.pipeline.span.Span; import com.jozufozu.flywheel.backend.pipeline.span.Span;
public abstract class AbstractShaderElement { public abstract class AbstractShaderElement {

View file

@ -3,6 +3,7 @@ package com.jozufozu.flywheel.backend.pipeline.parse;
import java.util.Optional; import java.util.Optional;
import com.jozufozu.flywheel.backend.ShaderSources; import com.jozufozu.flywheel.backend.ShaderSources;
import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter;
import com.jozufozu.flywheel.backend.pipeline.SourceFile; import com.jozufozu.flywheel.backend.pipeline.SourceFile;
import com.jozufozu.flywheel.backend.pipeline.span.Span; import com.jozufozu.flywheel.backend.pipeline.span.Span;

View file

@ -6,6 +6,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter;
import com.jozufozu.flywheel.backend.pipeline.span.Span; import com.jozufozu.flywheel.backend.pipeline.span.Span;
public class ShaderFunction extends AbstractShaderElement { public class ShaderFunction extends AbstractShaderElement {

View file

@ -1,9 +1,5 @@
package com.jozufozu.flywheel.backend.pipeline.parse; package com.jozufozu.flywheel.backend.pipeline.parse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -11,6 +7,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.jozufozu.flywheel.backend.loading.Program; import com.jozufozu.flywheel.backend.loading.Program;
import com.jozufozu.flywheel.backend.loading.TypeHelper; import com.jozufozu.flywheel.backend.loading.TypeHelper;
import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter;
import com.jozufozu.flywheel.backend.pipeline.span.Span; import com.jozufozu.flywheel.backend.pipeline.span.Span;
public class ShaderStruct extends AbstractShaderElement { public class ShaderStruct extends AbstractShaderElement {

View file

@ -1,9 +1,8 @@
package com.jozufozu.flywheel.backend.pipeline.parse; package com.jozufozu.flywheel.backend.pipeline.parse;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.jozufozu.flywheel.backend.loading.LayoutTag; import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter;
import com.jozufozu.flywheel.backend.pipeline.span.Span; import com.jozufozu.flywheel.backend.pipeline.span.Span;
public class StructField extends AbstractShaderElement { public class StructField extends AbstractShaderElement {

View file

@ -1,5 +1,6 @@
package com.jozufozu.flywheel.backend.pipeline.parse; package com.jozufozu.flywheel.backend.pipeline.parse;
import com.jozufozu.flywheel.backend.pipeline.error.ErrorReporter;
import com.jozufozu.flywheel.backend.pipeline.span.Span; import com.jozufozu.flywheel.backend.pipeline.span.Span;
public class Variable extends AbstractShaderElement { public class Variable extends AbstractShaderElement {

View file

@ -1,7 +1,8 @@
package com.jozufozu.flywheel.backend.pipeline.span; package com.jozufozu.flywheel.backend.pipeline.span;
import com.jozufozu.flywheel.backend.pipeline.SourceFile; /**
* A position in a file.
*/
public class CharPos { public class CharPos {
private final int idx; private final int idx;

View file

@ -2,6 +2,9 @@ package com.jozufozu.flywheel.backend.pipeline.span;
import com.jozufozu.flywheel.backend.pipeline.SourceFile; import com.jozufozu.flywheel.backend.pipeline.SourceFile;
/**
* Represents a (syntactically) malformed segment of code.
*/
public class ErrorSpan extends Span { public class ErrorSpan extends Span {
public ErrorSpan(SourceFile in, int loc) { public ErrorSpan(SourceFile in, int loc) {
super(in, loc, loc); super(in, loc, loc);

View file

@ -23,31 +23,49 @@ public abstract class Span implements CharSequence {
this.end = end; this.end = end;
} }
/**
* @return The file that contains this code segment.
*/
public SourceFile getSourceFile() { public SourceFile getSourceFile() {
return in; return in;
} }
public int getStart() { /**
* @return the string index at the (inclusive) beginning of this code segment.
*/
public int getStartPos() {
return start.getPos(); return start.getPos();
} }
public int getEnd() { /**
* @return the string index at the (exclusive) end of this code segment.
*/
public int getEndPos() {
return end.getPos(); return end.getPos();
} }
/**
* @return true if this span has no width.
*/
public boolean isEmpty() { public boolean isEmpty() {
return start == end; return start == end;
} }
/**
* Get a span referring to a code segment inside this code segment.
*/
public abstract Span subSpan(int from, int to); public abstract Span subSpan(int from, int to);
/**
* @return the portion of code represented by this span.
*/
public abstract String get(); public abstract String get();
public abstract boolean isErr(); public abstract boolean isErr();
@Override @Override
public int length() { public int length() {
return end.getPos() - start.getPos(); return getEndPos() - getStartPos();
} }
@Override @Override