mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 23:47:09 +01:00
Sporadic work done in an airport
- Initial ErrorBuilder class - Random documentation
This commit is contained in:
parent
865926e783
commit
8c470f3158
12 changed files with 68 additions and 14 deletions
|
@ -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());
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 "";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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 {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue