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

Demo protobuf-gradle-plugin working with Scala and antlr #3

Open
wants to merge 3 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
28 changes: 17 additions & 11 deletions examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ plugins {
// Provide convenience executables for trying out the examples.
id 'application'
// ASSUMES GRADLE 5.6 OR HIGHER. Use plugin version 0.8.10 with earlier gradle versions
id 'com.google.protobuf' version '0.8.15'
id 'com.google.protobuf' version '0.8.16'
// Generate IntelliJ IDEA's .idea & .iml project files
id 'idea'
id 'scala'
id 'antlr'
}

repositories {
Expand All @@ -27,6 +29,8 @@ def protobufVersion = '3.12.0'
def protocVersion = protobufVersion

dependencies {
antlr "org.antlr:antlr4:4.7.1"
implementation 'org.scala-lang:scala-library:2.12.8'
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
implementation "io.grpc:grpc-stub:${grpcVersion}"
compileOnly "org.apache.tomcat:annotations-api:6.0.53"
Expand All @@ -41,22 +45,24 @@ dependencies {
testImplementation "org.mockito:mockito-core:3.4.0"
}

ext {
scalapbVersion = '0.10.10'
}

protobuf {
protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
scalapb {
artifact = (org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem().isWindows()) ?
"com.thesamet.scalapb:protoc-gen-scala:${scalapbVersion}:windows@bat" :
"com.thesamet.scalapb:protoc-gen-scala:${scalapbVersion}:unix@sh"
}
}
generateProtoTasks {
all()*.plugins { grpc {} }
}
}

// Inform IDEs like IntelliJ IDEA, Eclipse or NetBeans about the generated code.
sourceSets {
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/java'
all()*.plugins {
grpc {}
scalapb {}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
56 changes: 56 additions & 0 deletions examples/src/main/antlr/Chat.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
grammar Chat;

@header {
package net.davidesavazzi.mylanguage;
}

/**
* Parser Rules
*/

chat : line+ EOF ;

line : name command message NEWLINE ;

name : WORD WHITESPACE ;

command : (SAYS | SHOUTS) ':' WHITESPACE ;

message : (emoticon | link | color | mention | WORD | WHITESPACE)+ ;

emoticon : ':' '-'? ')'
| ':' '-'? '(' ;

link : '[' TEXT ']' '(' TEXT ')' ;

color : '/' WORD '/' message '/' ;

mention : '@' + WORD ;


/**
* Lexer Rules
*/

fragment A : ('A' | 'a') ;
fragment S : ('S' | 's') ;
fragment Y : ('Y' | 'y') ;
fragment H : ('H' | 'h') ;
fragment O : ('O' | 'o') ;
fragment U : ('U' | 'u') ;
fragment T : ('T' | 't') ;

fragment LOWERCASE : [a-z] ;
fragment UPPERCASE : [A-Z] ;

SAYS : S A Y S ;

SHOUTS : S H O U T S ;

WORD : (LOWERCASE | UPPERCASE | '_')+ ;

WHITESPACE : (' ' | '\t')+ ;

NEWLINE : ('\r'? '\n' | '\r')+ ;

TEXT : ('[' | '(') ~[\])]+ (']' | ')') ;
7 changes: 7 additions & 0 deletions examples/src/main/scala/Demo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


object Demo {
def main(args: Array[String]): Unit = {
println("hello world")
}
}