Skip to content

Commit

Permalink
almost no updates
Browse files Browse the repository at this point in the history
  • Loading branch information
elucash committed Jun 19, 2017
1 parent 3781860 commit 56199b2
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="buck-out/gen/lib/guava_jar/guava-21.0.jar" sourcepath="buck-out/gen/lib/guava_src/guava-21.0-sources.jar"/>
<classpathentry kind="lib" path="buck-out/gen/lib/guava_jar/guava-22.0.jar" sourcepath="buck-out/gen/lib/guava_src/guava-22.0-sources.jar"/>
<classpathentry kind="lib" path="buck-out/gen/lib/jsr305_jar/jsr305-3.0.1.jar" sourcepath="buck-out/gen/lib/jsr305_src/jsr305-3.0.1-sources.jar"/>
<classpathentry kind="lib" path="buck-out/gen/lib/junit_jar/junit-4.12.jar" sourcepath="buck-out/gen/lib/junit_src/junit-4.12-sources.jar"/>
<classpathentry kind="lib" path="buck-out/gen/lib/hamcrest_jar/hamcrest-core-1.3.jar" sourcepath="buck-out/gen/lib/hamcrest_src/hamcrest-core-1.3-sources.jar"/>
Expand Down
12 changes: 6 additions & 6 deletions lib/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ prebuilt_jar(

remote_file(
name = 'guava_jar',
out = 'guava-21.0.jar',
url = 'https://repo1.maven.org/maven2/com/google/guava/guava/21.0/guava-21.0.jar',
sha1 = '3a3d111be1be1b745edfa7d91678a12d7ed38709'
out = 'guava-22.0.jar',
url = 'https://repo1.maven.org/maven2/com/google/guava/guava/22.0/guava-22.0.jar',
sha1 = '3564ef3803de51fb0530a8377ec6100b33b0d073'
)

remote_file(
name = 'guava_src',
out = 'guava-21.0-sources.jar',
url = 'https://repo1.maven.org/maven2/com/google/guava/guava/21.0/guava-21.0-sources.jar',
sha1 = 'b9ed26b8c23fe7cd3e6b463b34e54e5c6d9536d5'
out = 'guava-22.0-sources.jar',
url = 'https://repo1.maven.org/maven2/com/google/guava/guava/22.0/guava-22.0-sources.jar',
sha1 = '55edc69e4fc937f4e58e577bb144b824c0ec7c55'
)

prebuilt_jar(
Expand Down
2 changes: 1 addition & 1 deletion prj.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let l = require('./.prj.lib')

l.project({
lib: {
guava: 'com.google.guava:guava:21.0',
guava: 'com.google.guava:guava:22.0',
jsr305: 'com.google.code.findbugs:jsr305:3.0.1',
junit: 'junit:junit:4.12',
hamcrest: 'org.hamcrest:hamcrest-core:1.3',
Expand Down
26 changes: 15 additions & 11 deletions src/io/immutables/grammar/Productions.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public enum At {

private At current = At.EOP;
private int position = -POSITION_INCREMENT;
private int[] stack = new int[0];
private int[] stack = new int[32]; // should be fine enouph to avoid initial reallocation.
private int stackPointer = -1;
private int prodEndCount = 0;

Expand Down Expand Up @@ -348,10 +348,10 @@ private final void markTermBegin() {
}

private final boolean markTerm(short part, int term) {
long l1 = 0, l2 = 0;
int p = position;
int index = terms.index();

long l1 = 0, l2 = 0;
l1 = encodePart(l1, part);
l1 = encodeKind(l1, Shorts.checkedCast(term)); // term is positive, productions negative
l1 = encodeNextSibling(l1, p + POSITION_INCREMENT);
Expand All @@ -372,13 +372,17 @@ public boolean ok() {
return terms.ok() && completed;
}

public CharSequence message() {
if (ok()) return "";
public String message() {
if (ok()) return "ok";
if (terms.hasUnexpected()) return buildUnexpectedMessage();
if (hasUnconsumed()) return buildUnconsumedMessage();
return buildMismatchMessage();
}

public String messageForFile(String file) {
return file + ":" + message();
}

@Override
public String toString() {
return getClass().getSimpleName();
Expand All @@ -397,23 +401,23 @@ private boolean hasUnconsumed() {
return mismatchAt >= 0 && mismatchProduction == 0;
}

private CharSequence buildUnconsumedMessage() {
private String buildUnconsumedMessage() {
Source.Range range = terms.range(mismatchAt);
return range.begin()
+ " Unexpected terms starting with `" + range.get() + "` "
+ "\n\t" + range.highlight().toString().replace("\n", "\n\t")
+ "Unconsumed terms which are not forming any construct";
}

private CharSequence buildUnexpectedMessage() {
private String buildUnexpectedMessage() {
Source.Range range = terms.firstUnexpectedRange();
return range.begin()
+ " Unexpected characters `" + range.get() + "`"
+ "\n\t" + range.highlight().toString().replace("\n", "\n\t")
+ "Characters are not forming any recognized token";
}

private CharSequence buildMismatchMessage() {
private String buildMismatchMessage() {
Source.Range range = terms.range(mismatchAt);
return range.begin()
+ " Stumbled on `" + range.get() + "`"
Expand All @@ -423,9 +427,6 @@ private CharSequence buildMismatchMessage() {
+ "Cannot parse production because of mismatched term";
}

public static final short ANY_PART = (short) 0xffff;
public static final short NO_PART = (short) 0x0000;

static int decodeNextSibling(long l1) {
return (int) l1;
}
Expand Down Expand Up @@ -467,5 +468,8 @@ static long encodeTermEnd(long l2, int tokenIndex) {
}

private static final int POSITION_INCREMENT = 2;
private static final long[] EMPTY_LONG_ARRAY = new long[0];
private static final long[] EMPTY_LONG_ARRAY = {};

protected static final short ANY_PART = (short) 0xffff;
protected static final short NO_PART = (short) 0x0000;
}
8 changes: 8 additions & 0 deletions src/io/immutables/grammar/Sterm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.immutables.grammar;

public interface Sterm {

public interface Factory {

}
}
1 change: 1 addition & 0 deletions src/io/immutables/grammar/TreeProduction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.immutables.value.Value.Auxiliary;

/**
* Syntax tree production, usually used for abstract syntax trees.
* @param <K> ast kind type used to for typesafe guarding, usually it's an umbrella top level type
* of generated nested ast classes.
*/
Expand Down
10 changes: 4 additions & 6 deletions src/io/immutables/grammar/processor/Generator.generator
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[let parserClass][name]Parser[/let]
[let productionsClass][name]Productions[/let]
[let treesClass][name]Trees[/let]
[let constructClass][name]Construct[/let]

[output.java pack termsClass]
[generateTerms termsClass]
Expand Down Expand Up @@ -295,12 +294,12 @@ public final class [className]<T extends [grmp].TreeProduction<[treesClass]>> ex
[let altVar]l[for.index][/let]
[if p.alwaysSucceedingAlternatives.empty]
[altVar]: {
[alternativeBodyProd p a altVar]
[alternativeBody p a altVar]
return [if p.ephemeral]true[else]end(part, p)[/if];
}
terms.reset(i); position = p;
[else]
[alternativeBodyProd p a altVar]
[alternativeBody p a altVar]
return [if p.ephemeral]true[else]end(part, p)[/if];
[/if]
[/for]
Expand Down Expand Up @@ -336,7 +335,7 @@ public final class [className]<T extends [grmp].TreeProduction<[treesClass]>> ex
}
[/template]

[template alternativeBodyProd Prod prod Alt alt String altVar]
[template alternativeBody Prod prod Alt alt String altVar]
[for part in alt.parts if part.mode.notConsume][if for.first]
int j;
[/if][/for]
Expand Down Expand Up @@ -437,8 +436,7 @@ package [pack];
@SuppressWarnings("all")
@javax.annotation.Generated({"[grmp].processor.Generator", "[name].grammar"})
public interface [className] {
[for p in productions if not p.ephemeral,
String type = asType p.id]
[for p in productions if not p.ephemeral, String type = asType p.id]
[if p.subtypes]
interface [type] extends [grmp].TreeProduction<[className]>[for s in p.supertypes], [asType s][/for] {
[taggedPartsAttributes p]
Expand Down
5 changes: 0 additions & 5 deletions src/io/immutables/lang/emit/BUCK

This file was deleted.

5 changes: 3 additions & 2 deletions src/io/immutables/lang/processor/Imc.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@

public class Imc {
public static void main(String... args) throws Exception {
String sourceName = "debug.im";
String sourceName = "/io/immutables/lang/fixture/debug.im";

String content = Resources.toString(
Resources.getResource(Imc.class, sourceName),
StandardCharsets.UTF_8);

SyntaxTerms terms = SyntaxTerms.from(content.toCharArray());
SyntaxProductions<Unit> productions = SyntaxProductions.unit(terms);
System.out.println(productions.show());
if (productions.ok()) {
System.out.println(productions.construct());
} else {
System.out.println(sourceName + ":" + productions.message());
System.out.println(productions.messageForFile(sourceName));
System.out.println(productions.show());
}
}
Expand Down
12 changes: 3 additions & 9 deletions src/io/immutables/lang/processor/SourceRuns.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,17 @@ void process(String name, String filename, String content) {
SyntaxTerms terms = SyntaxTerms.from(content.toCharArray());
SyntaxProductions<Unit> productions = SyntaxProductions.unit(terms);
if (productions.ok()) {
// this should not fail in theory, but any exceptions will be caught by exception
// handlers
// this should not fail in theory,
// but any exceptions will be caught by the exception handler
productions.construct();

sources.add(new Source(name, content, false, ""));
} else {
String message = formatMessage(filename, productions);
sources.add(new Source(name, content, true, message));
sources.add(new Source(name, content, true, productions.messageForFile(filename)));
}
} catch (Exception ex) {
sources.add(new Source(name, content, true, Throwables.getStackTraceAsString(ex)));
}
}

private String formatMessage(String filename, SyntaxProductions<Unit> productions) {
return filename + ":" + productions.message();
}

abstract Templates.Invokable generate();
}
57 changes: 14 additions & 43 deletions src/io/immutables/lang/type/Name.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,27 @@
package io.immutables.lang.type;

public final class Name implements CharSequence {
private final String string;
import org.immutables.value.Value.Default;
import org.immutables.value.Value.Immutable;
import org.immutables.value.Value.Parameter;

private Name(String string) {
this.string = string;
@Immutable(singleton = true, builder = false, copy = false)
public abstract class Name {
@Parameter
@Default
String value() {
return "";
}

public static Name empty() {
return EMPTY;
}

public static Name of(CharSequence name) {
if (name.length() == 0) return EMPTY;
return new Name(name.toString());
return ImmutableName.of();
}

@Override
public Name subSequence(int begin, int end) {
return of(string.substring(begin, end));
public static Name of(String value) {
return ImmutableName.of(value);
}

public boolean isEmpty() {
return this == EMPTY;
return value().isEmpty();
}

@Override
public String toString() {
return string;
}

@Override
public int length() {
return string.length();
return value();
}

@Override
public char charAt(int index) {
return string.charAt(index);
}

@Override
public boolean equals(Object other) {
return other instanceof Name
? ((Name) other).string.equals(string)
: false;
}

@Override
public int hashCode() {
return string.hashCode();
}

private static final Name EMPTY = new Name("");
}
22 changes: 22 additions & 0 deletions src/io/immutables/lang/type/Scope.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.immutables.lang.type;

import java.util.HashMap;
import java.util.Map;

public interface Scope {

class Builder {
private final Map<Name, Type> types = new HashMap<>();
private final Map<Name, Type.Concept> concepts = new HashMap<>();

public Builder put(Name name, Type type) {
types.put(name, type);
return this;
}

public Builder add(Name name, Type.Concept concept) {
concepts.put(name, concept);
return this;
}
}
}
10 changes: 10 additions & 0 deletions src/io/immutables/lang/type/TestType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.immutables.lang.type;

import org.junit.Test;

public class TestType {
@Test
public void test() {

}
}
Loading

0 comments on commit 56199b2

Please sign in to comment.