Skip to content

Commit

Permalink
Update parser for SpatialOS 8.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
grandseiken committed Aug 4, 2016
1 parent 71cf635 commit 644a518
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class SchemaBlock implements Block {
SchemaParser.ENUM_DEFINITION, SchemaParser.TYPE_DEFINITION, SchemaParser.COMPONENT_DEFINITION);
private static final List<IElementType> CONTINUATION_BLOCKS = Arrays.asList(
SchemaParser.PACKAGE_DEFINITION, SchemaParser.IMPORT_DEFINITION, SchemaParser.OPTION_DEFINITION,
SchemaParser.FIELD_DEFINITION, SchemaParser.FIELD_TYPE,
SchemaParser.ENUM_VALUE_DEFINITION, SchemaParser.COMPONENT_ID_DEFINITION);
SchemaParser.FIELD_DEFINITION, SchemaParser.DATA_DEFINITION, SchemaParser.EVENT_DEFINITION,
SchemaParser.FIELD_TYPE, SchemaParser.ENUM_VALUE_DEFINITION, SchemaParser.COMPONENT_ID_DEFINITION);

private static final Spacing NO_SPACING = Spacing.createSpacing(0, 0, 0, false, 0);
private static final Spacing ONE_SPACE = Spacing.createSpacing(1, 1, 0, false, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class SchemaParser implements PsiParser {
public static final String KEYWORD_COMPONENT = "component";
public static final String KEYWORD_OPTION = "option";
public static final String KEYWORD_ID = "id";
public static final String KEYWORD_DATA = "data";
public static final String KEYWORD_EVENT = "event";

public static final IFileElementType SCHEMA_FILE = new IFileElementType(SchemaLanguage.SCHEMA_LANGUAGE);

Expand All @@ -45,9 +47,11 @@ public class SchemaParser implements PsiParser {
public static final IElementType ENUM_DEFINITION = new Node("Enum Definition");
public static final IElementType ENUM_VALUE_DEFINITION = new Node("Enum Value Definition");

public static final IElementType TYPE_DEFINITION = new Node("Type Definition");
public static final IElementType DATA_DEFINITION = new Node("Data Definition");
public static final IElementType FIELD_DEFINITION = new Node("Field Definition");
public static final IElementType EVENT_DEFINITION = new Node("Event Definition");

public static final IElementType TYPE_DEFINITION = new Node("Type Definition");
public static final IElementType COMPONENT_DEFINITION = new Node("Component Definition");
public static final IElementType COMPONENT_ID_DEFINITION = new Node("Component ID Definition");

Expand Down Expand Up @@ -264,26 +268,15 @@ private void parseFieldDefinition() {
if (typeName == null) {
return;
}
if (isToken(SchemaLexer.SEMICOLON)) {
consumeTokenAs(null);
marker.done(FIELD_DEFINITION);
return;
}
if (!isToken(SchemaLexer.IDENTIFIER)) {
error(marker, FIELD_DEFINITION, Construct.STATEMENT,
"Expected ';' or field name after '%s'.", typeName);
error(marker, FIELD_DEFINITION, Construct.STATEMENT, "Expected field name after '%s'.", typeName);
return;
}
String fieldName = getIdentifier();
consumeTokenAs(FIELD_NAME);
if (isToken(SchemaLexer.SEMICOLON)) {
consumeTokenAs(null);
marker.done(FIELD_DEFINITION);
return;
}
if (!isToken(SchemaLexer.EQUALS)) {
error(marker, FIELD_DEFINITION, Construct.STATEMENT,
"Expected ';' or '=' after '%s %s'.", typeName, fieldName);
"Expected '=' after '%s %s'.", typeName, fieldName);
return;
}
consumeTokenAs(null);
Expand Down Expand Up @@ -383,6 +376,53 @@ private void parseComponentIdDefinition() {
marker.done(COMPONENT_ID_DEFINITION);
}

private void parseDataDefinition() {
PsiBuilder.Marker marker = builder.mark();
consumeTokenAs(KEYWORD);
if (!isToken(SchemaLexer.IDENTIFIER)) {
error(marker, DATA_DEFINITION, Construct.STATEMENT, "Expected typename after '%s'.", KEYWORD_DATA);
return;
}
String typeName = parseTypeName(marker);
if (typeName == null) {
return;
}
if (!isToken(SchemaLexer.SEMICOLON)) {
error(marker, DATA_DEFINITION, Construct.STATEMENT,
"Expected ';' after '%s %s'.", KEYWORD_DATA, typeName);
return;
}
consumeTokenAs(null);
marker.done(DATA_DEFINITION);
}

private void parseEventDefinition() {
PsiBuilder.Marker marker = builder.mark();
consumeTokenAs(KEYWORD);
if (!isToken(SchemaLexer.IDENTIFIER)) {
error(marker, EVENT_DEFINITION, Construct.STATEMENT, "Expected typename after '%s'.", KEYWORD_EVENT);
return;
}
String typeName = parseTypeName(marker);
if (typeName == null) {
return;
}
if (!isToken(SchemaLexer.IDENTIFIER)) {
error(marker, EVENT_DEFINITION, Construct.STATEMENT,
"Expected field name after '%s %s'.", KEYWORD_EVENT, typeName);
return;
}
String fieldName = getIdentifier();
consumeTokenAs(FIELD_NAME);
if (!isToken(SchemaLexer.SEMICOLON)) {
error(marker, EVENT_DEFINITION, Construct.STATEMENT,
"Expected ';' after '%s %s %s'.", KEYWORD_EVENT, typeName, fieldName);
return;
}
consumeTokenAs(null);
marker.done(EVENT_DEFINITION);
}

private void parseComponentContents() {
while (true) {
if (isIdentifier(KEYWORD_OPTION)) {
Expand All @@ -399,6 +439,14 @@ private void parseComponentContents() {
parseComponentIdDefinition();
continue;
}
if (isIdentifier(KEYWORD_DATA)) {
parseDataDefinition();
continue;
}
if (isIdentifier(KEYWORD_EVENT)) {
parseEventDefinition();
continue;
}
if (isToken(SchemaLexer.IDENTIFIER)) {
parseFieldDefinition();
continue;
Expand Down

0 comments on commit 644a518

Please sign in to comment.