Clean up character and string literals in the lexer

This commit is contained in:
Sam Harwell 2013-05-18 11:18:58 -05:00
parent c835fc9a79
commit 49f9e093e8
2 changed files with 78 additions and 22 deletions

View File

@ -1092,25 +1092,53 @@ BooleanLiteral
| 'false' | 'false'
; ;
CharacterLiteral // §3.10.4 Character Literals
: '\'' ( EscapeSequence | ~('\''|'\\') ) '\''
;
StringLiteral CharacterLiteral
: '"' ( EscapeSequence | ~('\\'|'"') )* '"' : '\'' SingleCharacter '\''
| '\'' EscapeSequence '\''
; ;
fragment
SingleCharacter
: ~['\\]
;
// §3.10.5 String Literals
StringLiteral
: '"' StringCharacters? '"'
;
fragment
StringCharacters
: StringCharacter+
;
fragment
StringCharacter
: ~["\\]
| EscapeSequence
;
// §3.10.6 Escape Sequences for Character and String Literals
fragment fragment
EscapeSequence EscapeSequence
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') : '\\' [btnfr"'\\]
| OctalEscape | OctalEscape
; ;
fragment fragment
OctalEscape OctalEscape
: '\\' ('0'..'3') ('0'..'7') ('0'..'7') : '\\' OctalDigit
| '\\' ('0'..'7') ('0'..'7') | '\\' OctalDigit OctalDigit
| '\\' ('0'..'7') | '\\' ZeroToThree OctalDigit OctalDigit
;
fragment
ZeroToThree
: [0-3]
; ;
// §3.10.7 The Null Literal // §3.10.7 The Null Literal

View File

@ -1176,25 +1176,53 @@ BooleanLiteral
| 'false' | 'false'
; ;
CharacterLiteral // §3.10.4 Character Literals
: '\'' ( EscapeSequence | ~('\''|'\\') ) '\''
;
StringLiteral CharacterLiteral
: '"' ( EscapeSequence | ~('\\'|'"') )* '"' : '\'' SingleCharacter '\''
| '\'' EscapeSequence '\''
; ;
fragment
SingleCharacter
: ~['\\]
;
// §3.10.5 String Literals
StringLiteral
: '"' StringCharacters? '"'
;
fragment
StringCharacters
: StringCharacter+
;
fragment
StringCharacter
: ~["\\]
| EscapeSequence
;
// §3.10.6 Escape Sequences for Character and String Literals
fragment fragment
EscapeSequence EscapeSequence
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') : '\\' [btnfr"'\\]
| OctalEscape | OctalEscape
; ;
fragment fragment
OctalEscape OctalEscape
: '\\' ('0'..'3') ('0'..'7') ('0'..'7') : '\\' OctalDigit
| '\\' ('0'..'7') ('0'..'7') | '\\' OctalDigit OctalDigit
| '\\' ('0'..'7') | '\\' ZeroToThree OctalDigit OctalDigit
;
fragment
ZeroToThree
: [0-3]
; ;
// §3.10.7 The Null Literal // §3.10.7 The Null Literal