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'
;
CharacterLiteral
: '\'' ( EscapeSequence | ~('\''|'\\') ) '\''
;
// §3.10.4 Character Literals
StringLiteral
: '"' ( EscapeSequence | ~('\\'|'"') )* '"'
CharacterLiteral
: '\'' 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
EscapeSequence
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
: '\\' [btnfr"'\\]
| OctalEscape
;
fragment
OctalEscape
: '\\' ('0'..'3') ('0'..'7') ('0'..'7')
| '\\' ('0'..'7') ('0'..'7')
| '\\' ('0'..'7')
: '\\' OctalDigit
| '\\' OctalDigit OctalDigit
| '\\' ZeroToThree OctalDigit OctalDigit
;
fragment
ZeroToThree
: [0-3]
;
// §3.10.7 The Null Literal

View File

@ -1176,25 +1176,53 @@ BooleanLiteral
| 'false'
;
CharacterLiteral
: '\'' ( EscapeSequence | ~('\''|'\\') ) '\''
;
// §3.10.4 Character Literals
StringLiteral
: '"' ( EscapeSequence | ~('\\'|'"') )* '"'
CharacterLiteral
: '\'' 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
EscapeSequence
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
: '\\' [btnfr"'\\]
| OctalEscape
;
fragment
OctalEscape
: '\\' ('0'..'3') ('0'..'7') ('0'..'7')
| '\\' ('0'..'7') ('0'..'7')
| '\\' ('0'..'7')
: '\\' OctalDigit
| '\\' OctalDigit OctalDigit
| '\\' ZeroToThree OctalDigit OctalDigit
;
fragment
ZeroToThree
: [0-3]
;
// §3.10.7 The Null Literal