deniable_encryption
deniable_encryption

Reputation: 149

Single-quoted chars and double-quoted strings

I am studying parsers and lexers with ANTLR4. I wanna keep chars (single chars) single quoted and strings (more than one char) double-quoted, but I am kinda new into regex and I cannot do this, so I would like some examples, also, I am having some problems with quotes inside my regex statements in ANTLR4.

For example, it should accept only the following regarding strings and chars:

mychar = 'a'; // Chars single-quoted and single-char'd.
mystring = "test"; // Strings with MORE THAN ONE CHARS and double-quoted.

Upvotes: 0

Views: 153

Answers (1)

Bart Kiers
Bart Kiers

Reputation: 170148

Something like this for a single quoted char:

CHAR
 : '\'' ( '\\' ~[\r\n] | ~[\\'\r\n] ) '\''
 ;

where '\\' ~[\r\n] matches an escaped char (but not an escaped line break char) and ~[\\'\r\n] matches a char other than \\, ' and a line break char.

And a pretty similar double quoted rule:

STRING
 : '"' ( '\\' ~[\r\n] | ~[\\"\r\n] )* '"'
 ;

Upvotes: 1

Related Questions