I want to use "." in message field name of .proto file - protocol-buffers

I defined .proto file like:
syntax = "proto3";
message networkSliceArray
{
int32 DRB.UEThpDl.SNSSAI = 1;
int32 DRB.UEThpUl.SNSSAI = 2;
string networkSliceIdentifier = 3;
}
I want to parse such type of file. is it possible?
or if not possible is there any reference where i can find out why "." we can not used in protobuf. OR list of character that we can not defined in .proto file.

Your question is not really clear but I think you are asking why protoc outputs an error when processing the .proto file in your question.
The language specification sets out what constitutes a valid proto3 file. Your question is about field names so the relevant parts are:
field = [ "repeated" ] type fieldName "=" fieldNumber [ "[" fieldOptions "]" ] ";"
fieldName = ident
ident = letter { letter | decimalDigit | "_" }
This shows that a field name must start with a letter which can be followed by a combination of letters, digits and underscores. A period (.) is not valid.

Related

Is it mandatory to capitalize the enum variables in .proto files?

I want to create a enum of the following format but my proto extension throws an error, is it mandatory to capitalise enums and use only underscores ?
enum Language {
en = 0;
en-uk =1;
en-gb =2;
en-au =3;
en-us =4;
fil-en =5;
en-in =6;
fr =7;
}
According to the proto3 language specification, identifiers (including enums) must begin with a letter and then can contain only letters, decimal digits and underscores.
ident = letter { letter | decimalDigit | "_" }
Here's what Google's developer style guide recommends for enums. While the style guide is technically not mandatory, you should take care to conform to naming conventions in most situations, unless you have a compelling reason to depart from them.
Use CamelCase (with an initial capital) for enum type names and CAPITALS_WITH_UNDERSCORES for value names:
enum FooBar {
FOO_BAR_UNSPECIFIED = 0;
FOO_BAR_FIRST_VALUE = 1;
FOO_BAR_SECOND_VALUE = 2;
}

Antlr weird parentheses syntax

Cant understand this round bracket meaning.
Its not necessary to write it, but sometimes it can produce left-recursion error. Where should we use it in grammar rules?
Its not necessary to write it,
That is correct, it is not necessary. Just remove them.
but sometimes it can produce left-recursion error.
If that really is the case, you can open an issue here: https://github.com/antlr/antlr4/issues
EDIT
Seeing kaby76's comment, just to make sure: you cannot just remove them from a grammar file regardless. They can be removed from your example rule.
When used like this:
rule
: ID '=' ( NUMBER | STRING ) // match either `ID '=' NUMBER`
// or `ID '=' STRING`
;
they cannot be removed because removing them wold result in:
rule
: ID '=' NUMBER | STRING // match either `ID '=' NUMBER`
// or `STRING`
;
Or with repetition:
rule
: ( ID STRING )+ // match: `ID STRING ID STRING ID STRING ...`
;
and this:
rule
: ID STRING+ // match: `ID STRING STRING STRING ...`
;

Text On Either Side of Colon

Let's say I had someone enter the text 'Name: Bob'
Is there any way I can extract the right side of the colon if I know what's on the left?
For example, if I knew that the left side of the colon was 'Name,' could I extract 'Bob' and how would I do that?
Just by knowing that the string contains a colon, you can separate the string into two parts with the parts containing the string on each side of the colon.
let str = "Name: Bob"
let comp = str.components(separatedBy: ":") //returns an array of strings
let name = comp[1] //returns "Bob"
If you also want to remove the whitespace before the name, you can either do let comp = str.components(separatedBy: ": ") or if you want to be more generic, let name = comp[1].replacingOccurrences(of: " ", with: "")

How to print/scan Underscores in Numeric Literals

Team,
I am not able to use the Java 7 Underscores in Numeric Literals feature for getting the input from user and printing out in same format as declared. Please help in doing that? OR Is this feature is incomplete?
Scanner input = new Scanner( System.in );
int x = 1_00_000;
System.out.print( "Enter numeric literals with underscores: " ); //2_00_000
x = input.nextInt(); //java.util.InputMismatchException
System.out.println(x); // Prints in normal format, but want to be in 2_00_000.
NOTE: In Eclipse; I am able to change the value of numeric literal with Underscored numeric literal in runtime. This may be hack, but this is needed feature to input Underscored numeric literal in runtime rit?.
http://www.eclipse.org/jdt/ui/r3_8/Java7news/whats-new-java-7.html#miscellaneous
if you want maintain the underscores you can use String:
Scanner input = new Scanner( System.in );
System.out.print( "Enter numeric literals with underscores: " ); //2_00_000
String stringLiterals = input.nextLine();
System.out.println(stringLiterals); // Prints 2_00_000.

Remove email address from string in Ruby

I have the following code which is supposed to be removing a particular email address from a string if it exists. The problem is i get the error "invalid range "y-d" in string transliteration (ArgumentError)" which I assume is because it's treating my input as a regex. I will need to do this delete by a variable in the actual code, not a string literal but this is a simplified version of the problem.
So how do I properly perform this operation?
myvar = "test1#my-domain.com test2#my-domain.com"
myvar = myvar.delete("test1#my-domain.com")
Try
myvar = "test1#my-domain.com test2#my-domain.com"
myvar = myvar.gsub("test1#my-domain.com", '').strip
String#delete(str) does not delete the literal string str but builds a set out of individual characters of str and deletes all occurrences of these characters. try this:
"sets".delete("test")
=> ""
"sets".delete("est")
=> ""
The hyphen has a special meaning, it defines a range of characters. String#delete("a-d") will delete all occurrences of a,b,c and d characters. Range boundary characters should be given in ascending order: you should write "a-d" but not "d-a".
In your original example, ruby tries to build a character range from y-d substring and fails.
Use String#gsub method instead.
You can do it like this
myvar = "test1#my-domain.com test2#my-domain.com"
remove = "test1#my-domain.com"
myvar.gsub!(remove, "")

Resources