Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/main/antlr/com/sleekbyte/tailor/antlr/Swift.g4
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ selectorExpression
// GRAMMAR OF A KEY PATH EXPRESSION

keyPathExpression
: '#keyPath' '(' expression ')'
: '#keyPath' '(' expression ')'
| '\\' expression
;

Expand Down Expand Up @@ -899,7 +899,7 @@ swiftVersion: FloatingPointLiteral ;
lineControlStatement: '#sourceLocation' '(' 'file' ':' fileName ',' 'line' ':' lineNumber ')'
| '#sourceLocation' '(' ')' ;
lineNumber: integerLiteral ;
fileName: StringLiteral ;
fileName: SingleStringLiteral ;

// ---------- Lexical Structure -----------

Expand Down Expand Up @@ -1009,7 +1009,7 @@ ImplicitParameterName : '$' DecimalLiteral ; // TODO: don't allow '_' here
// GRAMMAR OF A LITERAL

booleanLiteral: BooleanLiteral ;
literal : numericLiteral | StringLiteral | BooleanLiteral | NilLiteral ;
literal : numericLiteral | MultiStringLiteral | SingleStringLiteral | BooleanLiteral | NilLiteral ;

// GRAMMAR OF AN INTEGER LITERAL

Expand Down Expand Up @@ -1060,13 +1060,24 @@ VersionLiteral: DecimalLiteral DecimalFraction DecimalFraction ;

// GRAMMAR OF A STRING LITERAL

StringLiteral : '"' QuotedText? '"' ;
TRIPLEDQUOTES : '"""' ;

MultiStringLiteral : TRIPLEDQUOTES '\n' .*? '\n' TRIPLEDQUOTES ;
fragment MultiQuotedText : MultiQuotedTextItem+ ;
fragment MultiQuotedTextItem : MultiInterpolatedString
| ~[\\\u000A\u000D]
;
fragment MultiInterpolatedString: '\\(' (MultiQuotedTextItem | SingleStringLiteral)* ')';

// StringLiteral : '"' QuotedText? '"' ;
SingleStringLiteral : '"' QuotedText? '"' ;
fragment SingleDoubleQuote : '"' | ~["] ;
fragment QuotedText : QuotedTextItem+ ;
fragment QuotedTextItem : EscapedCharacter | InterpolatedString
// | '\\(' expression ')'
| ~["\\\u000A\u000D]
;
fragment InterpolatedString: '\\(' (QuotedTextItem | StringLiteral)* ')';
fragment InterpolatedString: '\\(' (QuotedTextItem | SingleStringLiteral)* ')';

EscapedCharacter : '\\' [0\\tnr"']
| '\\x' HexadecimalDigit HexadecimalDigit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ let someString = "Some string literal value"
var emptyString = "" // empty string literal
var anotherEmptyString = String() // initializer syntax

let star = "⭐️"

let multilineString = """
multiline
text
"""

let multilineStringWithVar = """
multiline
text
with a star \(star)
"""

let multilineStringWithEscaped = """
You could write multi-lined strings
without "escaping" single quotes.
"""



if emptyString.isEmpty {
print("Nothing to see here")
}
Expand Down