aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/shedlang/compiler/sources
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-04-04 08:35:40 +0100
committerMichael Williamson <mike@zwobble.org>2026-04-04 08:35:40 +0100
commit4c7b8473d21ac7ddad0cb3d56eed2c4b09231d6d (patch)
tree886f3e591f513c72b1e4393453d628700c91d235 /src/main/java/org/shedlang/compiler/sources
parent97073855402b799644bfe23b6a10db51919d6757 (diff)
Remove protobuf
Diffstat (limited to 'src/main/java/org/shedlang/compiler/sources')
-rw-r--r--src/main/java/org/shedlang/compiler/sources/serialization/SourceToProtobuf.java128
1 files changed, 0 insertions, 128 deletions
diff --git a/src/main/java/org/shedlang/compiler/sources/serialization/SourceToProtobuf.java b/src/main/java/org/shedlang/compiler/sources/serialization/SourceToProtobuf.java
deleted file mode 100644
index 91a1464c..00000000
--- a/src/main/java/org/shedlang/compiler/sources/serialization/SourceToProtobuf.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package org.shedlang.compiler.sources.serialization;
-
-import org.shedlang.compiler.sources.*;
-import org.shedlang.compiler.sources.protobuf.SourcesProtobuf;
-import org.zwobble.sourcetext.SourcePosition;
-import org.zwobble.sourcetext.SourceRange;
-import org.zwobble.sourcetext.SourceText;
-
-import java.util.Optional;
-
-public class SourceToProtobuf {
- private SourceToProtobuf() {
- }
-
- public static SourcesProtobuf.Source serializeSource(
- Source source,
- Source parentSource
- ) {
- return serializeSource(source, Optional.of(parentSource));
- }
-
- public static SourcesProtobuf.Source serializeSource(
- Source source,
- Optional<Source> parentSource
- ) {
- var builder = SourcesProtobuf.Source.newBuilder();
-
- switch (source) {
- case NullSource nullSource -> {
- builder.setNullSource(
- SourcesProtobuf.NullSource.newBuilder().build()
- );
- }
- case RuntimeSource runtimeSource -> {
- builder.setRuntimeSource(
- SourcesProtobuf.RuntimeSource.newBuilder().build()
- );
- }
- case FileFragmentSource fileFragmentSource -> {
- builder.setFileFragmentSource(
- serializeFileFragmentSource(fileFragmentSource, parentSource)
- );
- }
- default -> {
- throw new UnsupportedOperationException("Unhandled source: " + source);
- }
- }
-
- return builder.build();
- }
-
- public static Source deserializeSource(
- SourcesProtobuf.Source sourceProtobuf,
- Source parentSource
- ) {
- return deserializeSource(sourceProtobuf, Optional.of(parentSource));
- }
-
- public static Source deserializeSource(
- SourcesProtobuf.Source sourceProtobuf,
- Optional<Source> parentSource
- ) {
- return switch (sourceProtobuf.getValueCase()) {
- case NULL_SOURCE ->
- Sources.NULL;
-
- case RUNTIME_SOURCE ->
- Sources.RUNTIME;
-
- case FILE_FRAGMENT_SOURCE ->
- deserializeFileFragmentSource(
- sourceProtobuf.getFileFragmentSource(),
- parentSource
- );
-
- case VALUE_NOT_SET -> {
- throw new UnsupportedOperationException("TODO");
- }
- };
- }
-
- private static SourcesProtobuf.FileFragmentSource serializeFileFragmentSource(
- FileFragmentSource source,
- Optional<Source> parentSource
- ) {
- var builder = SourcesProtobuf.FileFragmentSource.newBuilder();
-
- var sourceTextName = source.sourceRange().sourceText().name();
- if (!(
- parentSource.isPresent() &&
- parentSource.get() instanceof FileFragmentSource(
- SourceRange parentSourceRange) &&
- parentSourceRange.sourceText().name().equals(sourceTextName)
- )) {
- builder.setSourceText(
- SourcesProtobuf.SourceText.newBuilder()
- .setName(sourceTextName)
- .setContents(source.sourceRange().sourceText().charSequence().toString())
- .build()
- );
- }
-
- builder.setStartCharacterIndex(source.sourceRange().start().characterIndex());
- builder.setEndCharacterIndex(source.sourceRange().end().characterIndex());
-
- return builder.build();
- }
-
- private static FileFragmentSource deserializeFileFragmentSource(
- SourcesProtobuf.FileFragmentSource sourceProtobuf,
- Optional<Source> parentSource
- ) {
- SourceText sourceText;
- if (sourceProtobuf.hasSourceText()) {
- sourceText = SourceText.fromString(
- sourceProtobuf.getSourceText().getName(),
- sourceProtobuf.getSourceText().getContents()
- );
- } else {
- // TODO: handle missing parent
- sourceText = ((FileFragmentSource) parentSource.orElseThrow()).sourceRange().sourceText();
- }
-
- var start = new SourcePosition(sourceText, sourceProtobuf.getStartCharacterIndex());
- var end = new SourcePosition(sourceText, sourceProtobuf.getEndCharacterIndex());
- return new FileFragmentSource(new SourceRange(sourceText, start, end));
- }
-}