Skip to content

Commit

Permalink
add ProtoBufs
Browse files Browse the repository at this point in the history
  • Loading branch information
lytefast committed Oct 30, 2020
1 parent af5f644 commit 5918d34
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
46 changes: 46 additions & 0 deletions app/src/main/java/com/discord/simpleast/sample/SampleTexts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,51 @@ object SampleTexts {
```
"""

private const val CODE_BLOCK_PROTO_BUFFERS = """
ProtoBuffers code block:
```pb
package com.discord.test
import "google/protobuf/descriptor.proto";
extend google.protobuf.MessageOptions {
optional int32 my_message_option = 50001;
}
message MyMessage {
option (my_message_option) = 1234;
optional string bar = 1 [default = "Test"];
oneof qux {
option (my_oneof_option) = 42;
required string quux = 3;
}
repeated in64 ids = 4;
}
enum MyEnum {
option (my_enum_option) = true;
FOO = 1 [(my_enum_value_option) = 321];
BAR = 2;
}
message RequestType {}
message ResponseType {}
service MyService {
option (my_service_option) = FOO;
rpc MyMethod(RequestType) returns(ResponseType) {
// Note: my_method_option has type MyMessage. We can set each field
// within it using a separate "option" line.
option (my_method_option).bar = "Some string";
}
}
```
"""

private const val CODE_BLOCK_PYTHON = """
Python code block:
```py
Expand Down Expand Up @@ -150,6 +195,7 @@ object SampleTexts {
}```
$CODE_BLOCK_KOTLIN
$CODE_BLOCK_PROTO_BUFFERS
$CODE_BLOCK_PYTHON
$CODE_BLOCK_RUST
$CODE_BLOCK_XML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ object CodeRules {
builtIns = Kotlin.BUILT_INS,
keywords = Kotlin.KEYWORDS)

val protoRules = createGenericCodeRules<R, S>(
codeStyleProviders,
additionalRules = listOf(
createSingleLineCommentPattern("//")
.toMatchGroupRule(stylesProvider = codeStyleProviders.commentStyleProvider),
Pattern.compile("""^"[\s\S]*?(?<!\\)"(?=\W|\s|$)""")
.toMatchGroupRule(stylesProvider = codeStyleProviders.literalStyleProvider),
),
definitions = arrayOf("message|enum|extend|service"),
builtIns = arrayOf("true|false",
"string|bool|double|float|bytes",
"int32|uint32|sint32|int64|unit64|sint64",
"map"),
"required|repeated|optional|option|oneof|default|reserved",
"package|import",
"rpc|returns")

val pythonRules = createGenericCodeRules<R, S>(
codeStyleProviders,
Expand Down Expand Up @@ -159,6 +175,10 @@ object CodeRules {
"kt" to kotlinRules,
"kotlin" to kotlinRules,

"protobuf" to protoRules,
"proto" to protoRules,
"pb" to protoRules,

"py" to pythonRules,
"python" to pythonRules,

Expand Down

0 comments on commit 5918d34

Please sign in to comment.