Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Courier key type #61

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
courierVersion=2.0.10
courierVersion=2.1.0
scalaMajorVersion=2.11
5 changes: 4 additions & 1 deletion idea-plugin/src/org/coursera/courier/Courier.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ fullyQualifiedName ::= IDENTIFIER (DOT IDENTIFIER)*

typeDeclaration ::= namedTypeDeclaration | anonymousTypeDeclaration

namedTypeDeclaration ::= annotations? (recordDeclaration | enumDeclaration | typerefDeclaration | fixedDeclaration)
namedTypeDeclaration ::= annotations? (recordDeclaration | enumDeclaration | typerefDeclaration |
fixedDeclaration | keyDeclaration)

anonymousTypeDeclaration ::= unionDeclaration | arrayDeclaration | mapDeclaration

Expand All @@ -70,6 +71,8 @@ propJsonValueWithParams ::= OPEN_PAREN jsonValue CLOSE_PAREN {pin=1}

recordDeclaration ::= RECORD_KEYWORD typeNameDeclaration fieldSelection {pin=1}

keyDeclaration ::= KEY_KEYWORD typeNameDeclaration fieldSelection {pin=1}

enumDeclaration ::= ENUM_KEYWORD typeNameDeclaration enumSymbolDeclarations {pin=1}

enumSymbolDeclarations ::= OPEN_BRACE enumSymbolDeclaration* CLOSE_BRACE {pin=1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class CourierSyntaxHighlighter extends SyntaxHighlighterBase {
KEYWORDS.add(CourierTypes.ENUM_KEYWORD);
KEYWORDS.add(CourierTypes.FIXED_KEYWORD);
KEYWORDS.add(CourierTypes.RECORD_KEYWORD);
KEYWORDS.add(CourierTypes.KEY_KEYWORD);
KEYWORDS.add(CourierTypes.TYPEREF_KEYWORD);
KEYWORDS.add(CourierTypes.TRUE);
KEYWORDS.add(CourierTypes.FALSE);
Expand Down
1 change: 1 addition & 0 deletions idea-plugin/src/org/coursera/courier/psi/Courier.flex
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ StringLiteral = \" ( [^\"\\] | \\ ( [\"\\/bfnrt] | u[0-9]{4} ) )* \"
"namespace" { return CourierTypes.NAMESPACE_KEYWORD; }
"import" { return CourierTypes.IMPORT_KEYWORD; }
"record" { return CourierTypes.RECORD_KEYWORD; }
"key" { return CourierTypes.KEY_KEYWORD; }
"enum" { return CourierTypes.ENUM_KEYWORD; }
"fixed" { return CourierTypes.FIXED_KEYWORD; }
"typeref" { return CourierTypes.TYPEREF_KEYWORD; }
Expand Down
2 changes: 1 addition & 1 deletion maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scalaMajorVersion>2.11</scalaMajorVersion>
<scalaVersion>2.11.5</scalaVersion>
<courierVersion>2.0.10</courierVersion>
<courierVersion>2.1.0</courierVersion>
<javaVersion>1.7</javaVersion>
</properties>
<url>http://github.com/coursera/courier</url>
Expand Down
3 changes: 2 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ object Courier extends Build with OverridablePublishSettings {

override lazy val settings = super.settings ++ overridePublishSettings ++
Seq(
organization := "org.coursera.courier")
organization := "org.coursera.courier",
isSnapshot := true)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is important to ensure that all local changes are published for testing


//
// Cross building
Expand Down
8 changes: 7 additions & 1 deletion schema-language/src/main/antlr4/Courier.g4
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ typeReference returns [String value]: qualifiedIdentifier {
typeDeclaration: namedTypeDeclaration | anonymousTypeDeclaration;

namedTypeDeclaration: doc=schemadoc? props+=propDeclaration*
(recordDeclaration | enumDeclaration | typerefDeclaration | fixedDeclaration);
(recordDeclaration | keyDeclaration | enumDeclaration | typerefDeclaration |
fixedDeclaration);

anonymousTypeDeclaration: unionDeclaration | arrayDeclaration | mapDeclaration;

Expand All @@ -42,6 +43,10 @@ recordDeclaration returns [String name]: RECORD identifier recordDecl=fieldSelec
$name = $identifier.value;
};

keyDeclaration returns [String name]: KEY identifier keyDecl=fieldSelection {
$name = $identifier.value;
};

enumDeclaration returns [String name]: ENUM identifier enumDecl=enumSymbolDeclarations {
$name = $identifier.value;
};
Expand Down Expand Up @@ -138,6 +143,7 @@ NAMESPACE: 'namespace';
RECORD: 'record';
TYPEREF: 'typeref';
UNION: 'union';
KEY: 'key';

OPEN_PAREN: '(';
CLOSE_PAREN: ')';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.coursera.courier.grammar.CourierParser.ImportDeclarationContext;
import org.coursera.courier.grammar.CourierParser.ImportDeclarationsContext;
import org.coursera.courier.grammar.CourierParser.JsonValueContext;
import org.coursera.courier.grammar.CourierParser.KeyDeclarationContext;
import org.coursera.courier.grammar.CourierParser.MapDeclarationContext;
import org.coursera.courier.grammar.CourierParser.NamedTypeDeclarationContext;
import org.coursera.courier.grammar.CourierParser.ObjectEntryContext;
Expand Down Expand Up @@ -164,6 +165,7 @@ public void parse(Reader reader) {
parser.addErrorListener(errorRecorder);

DocumentContext antlrDocument = parser.document();
// System.out.println("\n!!!!!!!!\n"+antlrDocument.toStringTree()+"\n!!!!!!!!\n");
parse(antlrDocument);

if (errorRecorder.errors.size() > 0) {
Expand Down Expand Up @@ -326,6 +328,8 @@ private NamedDataSchema parseNamedType(
return parseFixed(namedType, namedType.fixedDeclaration());
} else if (namedType.enumDeclaration() != null) {
return parseEnum(namedType, namedType.enumDeclaration());
} else if (namedType.keyDeclaration() != null) {
return parseKey(namedType, namedType.keyDeclaration());
} else {
throw new ParseException(namedType,
"Unrecognized named type parse node: " + namedType.getText());
Expand Down Expand Up @@ -469,9 +473,24 @@ private UnionDataSchema parseUnion(
return schema;
}

private RecordDataSchema parseRecord(
private RecordDataSchema parseKey(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We likely have to copy RecordDataSchema since it's final or decorate it with additional annotations so we don't erase type information of the new key keyword. It's also one possible place we can add some validation to make sure the courier document conforms to spec

NamedTypeDeclarationContext context,
RecordDeclarationContext record) throws ParseException {
KeyDeclarationContext key) throws ParseException {
Name name = toName(key.name);
RecordDataSchema schema = new RecordDataSchema(name, RecordDataSchema.RecordType.RECORD);

bindNameToSchema(name, schema);
FieldsAndIncludes fieldsAndIncludes = parseFields(schema, key.keyDecl);
schema.setFields(fieldsAndIncludes.fields, errorMessageBuilder());
validateDefaults(schema);
schema.setInclude(fieldsAndIncludes.includes);
setProperties(context, schema);
return schema;
}

private RecordDataSchema parseRecord(
NamedTypeDeclarationContext context,
RecordDeclarationContext record) throws ParseException {
Name name = toName(record.name);
RecordDataSchema schema = new RecordDataSchema(name, RecordDataSchema.RecordType.RECORD);

Expand Down
12 changes: 6 additions & 6 deletions scripts/publish-local
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
sbt fullpublish-mavenlocal # publish courier to maven local so that the gradle build for gradle-plugin can depend on it
sbt fullpublish-ivylocal
(cd gradle-plugin; ./gradlew install)
if hash mvn 2>/dev/null; then
(cd maven-plugin; mvn clean install)
else
echo "mvn not install, skipping publish for maven-plugin"
fi
#(cd gradle-plugin; ./gradlew install)
#if hash mvn 2>/dev/null; then
# (cd maven-plugin; mvn clean install)
#else
# echo "mvn not install, skipping publish for maven-plugin"
#fi
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "2.0.10"
version in ThisBuild := "2.1.0"