Skip to content
Merged
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
8 changes: 4 additions & 4 deletions src/Compiler/Service/ServiceLexing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module FSharpTokenTag =
let INTERP_STRING_BEGIN_PART =
tagOfToken (INTERP_STRING_BEGIN_PART("a", SynStringKind.Regular, LexCont.Default))

let INTERP_STRING_PART = tagOfToken (INTERP_STRING_PART("a", None, LexCont.Default))
let INTERP_STRING_END = tagOfToken (INTERP_STRING_END("a", None, LexCont.Default))
let INTERP_STRING_PART = tagOfToken (INTERP_STRING_PART("a", LexCont.Default))
let INTERP_STRING_END = tagOfToken (INTERP_STRING_END("a", LexCont.Default))
let LPAREN = tagOfToken LPAREN
let RPAREN = tagOfToken RPAREN
let LBRACK = tagOfToken LBRACK
Expand Down Expand Up @@ -491,9 +491,9 @@ module internal LexerStateEncoding =
| STRING_TEXT cont
| EOF cont
| INTERP_STRING_BEGIN_PART(_, _, cont)
| INTERP_STRING_PART(_, _, cont)
| INTERP_STRING_PART(_, cont)
| INTERP_STRING_BEGIN_END(_, _, cont)
| INTERP_STRING_END(_, _, cont)
| INTERP_STRING_END(_, cont)
| LBRACE cont
| RBRACE cont
| BYTEARRAY(_, _, cont)
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/SyntaxTree/LexHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ type LexerStringFinisher =
else
INTERP_STRING_BEGIN_END(s, synStringKind, cont)
else if isPart then
INTERP_STRING_PART(s, None, cont)
INTERP_STRING_PART(s, cont)
else
INTERP_STRING_END(s, None, cont)
INTERP_STRING_END(s, cont)
elif kind.IsByteString then
let synByteStringKind =
if isVerbatim then
Expand Down
26 changes: 15 additions & 11 deletions src/Compiler/lex.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ let checkExprGreaterColonOp (lexbuf:UnicodeLexing.Lexbuf) =
let unexpectedChar lexbuf =
LEX_FAILURE (FSComp.SR.lexUnexpectedChar(lexeme lexbuf))

let startString args (lexbuf: UnicodeLexing.Lexbuf) altStartForStringPartOrEnd =
let startString args (lexbuf: UnicodeLexing.Lexbuf) =
let buf = ByteBuffer.Create StringCapacity
let m = lexbuf.LexemeRange
let startp = lexbuf.StartPos
Expand Down Expand Up @@ -158,9 +158,9 @@ let startString args (lexbuf: UnicodeLexing.Lexbuf) altStartForStringPartOrEnd =
INTERP_STRING_BEGIN_END (s, synStringKind, cont)
else
if isPart then
INTERP_STRING_PART (s, altStartForStringPartOrEnd, cont)
INTERP_STRING_PART (s, cont)
else
INTERP_STRING_END (s, altStartForStringPartOrEnd, cont)
INTERP_STRING_END (s, cont)
else
let s = Lexhelp.stringBufferAsString buf
let synStringKind =
Expand Down Expand Up @@ -587,7 +587,7 @@ rule token (args: LexArgs) (skip: bool) = parse
else mlOnly m args skip lexbuf }

| '"'
{ let buf, fin, m = startString args lexbuf None
{ let buf, fin, m = startString args lexbuf

// Single quote in triple quote ok, others disallowed
match args.stringNest with
Expand All @@ -600,7 +600,7 @@ rule token (args: LexArgs) (skip: bool) = parse
else singleQuoteString (buf, fin, m, LexerStringKind.String, args) skip lexbuf }

| '$' '"' '"' '"'
{ let buf, fin, m = startString args lexbuf None
{ let buf, fin, m = startString args lexbuf

// Single quote in triple quote ok, others disallowed
match args.stringNest with
Expand All @@ -612,7 +612,7 @@ rule token (args: LexArgs) (skip: bool) = parse
else tripleQuoteString (buf, fin, m, LexerStringKind.InterpolatedStringFirst, args) skip lexbuf }

| ('$'+) '"' '"' '"'
{ let buf, fin, m = startString args lexbuf None
{ let buf, fin, m = startString args lexbuf

if lexbuf.SupportsFeature LanguageFeature.ExtendedStringInterpolation then
// Single quote in triple quote ok, others disallowed
Expand All @@ -635,7 +635,7 @@ rule token (args: LexArgs) (skip: bool) = parse
}

| '$' '"'
{ let buf,fin,m = startString args lexbuf None
{ let buf,fin,m = startString args lexbuf

// Single quote in triple quote ok, others disallowed
match args.stringNest with
Expand All @@ -649,7 +649,7 @@ rule token (args: LexArgs) (skip: bool) = parse
singleQuoteString (buf, fin, m, LexerStringKind.InterpolatedStringFirst, args) skip lexbuf }

| '"' '"' '"'
{ let buf, fin, m = startString args lexbuf None
{ let buf, fin, m = startString args lexbuf

args.interpolationDelimiterLength <- 0

Expand All @@ -664,7 +664,7 @@ rule token (args: LexArgs) (skip: bool) = parse
tripleQuoteString (buf, fin, m, LexerStringKind.String, args) skip lexbuf }

| '@' '"'
{ let buf, fin, m = startString args lexbuf None
{ let buf, fin, m = startString args lexbuf

// Single quote in triple quote ok, others disallowed
match args.stringNest with
Expand All @@ -679,7 +679,7 @@ rule token (args: LexArgs) (skip: bool) = parse
verbatimString (buf, fin, m, LexerStringKind.String, args) skip lexbuf }

| ("$@" | "@$") '"'
{ let buf, fin, m = startString args lexbuf None
{ let buf, fin, m = startString args lexbuf

// Single quote in triple quote ok, others disallowed
match args.stringNest with
Expand Down Expand Up @@ -914,7 +914,11 @@ rule token (args: LexArgs) (skip: bool) = parse
token args skip lexbuf
| (1, style, _, altR, _r) :: rest ->
args.stringNest <- rest
let buf, fin, m = startString args lexbuf altR
altR
|> Option.iter (fun r ->
let n = r.StartColumn - lexbuf.StartPos.Column
lexbuf.StartPos <- lexbuf.StartPos.ShiftColumnBy(n))
let buf, fin, m = startString args lexbuf
if not skip then
STRING_TEXT (LexCont.String(args.ifdefStack, args.stringNest, style, LexerStringKind.InterpolatedStringPart, args.interpolationDelimiterLength, m))
else
Expand Down
29 changes: 5 additions & 24 deletions src/Compiler/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ let parse_error_rich = Some(fun (ctxt: ParseErrorContext<_>) ->
%token <string * SynStringKind * ParseHelpers.LexerContinuation> STRING
%token <string * SynStringKind * ParseHelpers.LexerContinuation> INTERP_STRING_BEGIN_END
%token <string * SynStringKind * ParseHelpers.LexerContinuation> INTERP_STRING_BEGIN_PART
%token <string * range option * ParseHelpers.LexerContinuation> INTERP_STRING_PART
%token <string * range option * ParseHelpers.LexerContinuation> INTERP_STRING_END
%token <string * ParseHelpers.LexerContinuation> INTERP_STRING_PART
%token <string * ParseHelpers.LexerContinuation> INTERP_STRING_END
%token <ParseHelpers.LexerContinuation> LBRACE RBRACE

%token <string * string> KEYWORD_STRING // Like __SOURCE_DIRECTORY__
Expand Down Expand Up @@ -6774,35 +6774,16 @@ interpolatedStringFill:

interpolatedStringParts:
| INTERP_STRING_END
{
let (s, altStart, _) = $1
let mOrig = rhs parseState 1
let m =
match altStart with
| Some r -> unionRanges r mOrig
| None -> mOrig
[ SynInterpolatedStringPart.String(s, m) ] }
{ [ SynInterpolatedStringPart.String(fst $1, rhs parseState 1) ] }

| INTERP_STRING_PART interpolatedStringFill interpolatedStringParts
{ let (s, altStart, _) = $1
let mOrig = rhs parseState 1
let m =
match altStart with
| Some r -> unionRanges r mOrig
| None -> mOrig
SynInterpolatedStringPart.String(s, m) :: SynInterpolatedStringPart.FillExpr $2 :: $3 }
{ SynInterpolatedStringPart.String(fst $1, rhs parseState 1) :: SynInterpolatedStringPart.FillExpr $2 :: $3 }

| INTERP_STRING_PART interpolatedStringParts
{ let rbrace = parseState.InputEndPosition 1
let lbrace = parseState.InputStartPosition 2
reportParseErrorAt (mkSynRange rbrace lbrace) (FSComp.SR.parsEmptyFillInInterpolatedString())
let (s, altStart, _) = $1
let mOrig = rhs parseState 1
let m =
match altStart with
| Some r -> unionRanges r mOrig
| None -> mOrig
SynInterpolatedStringPart.String(s, m) :: $2 }
SynInterpolatedStringPart.String(fst $1, rhs parseState 1) :: $2 }

/* INTERP_STRING_BEGIN_END */
/* INTERP_STRING_BEGIN_PART int32 INTERP_STRING_END */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ printfn \"%s\" s"
|> withLangVersion80
|> compile
|> shouldFail
|> withSingleDiagnostic (Error 1249, Line 1, Col 15, Line 1, Col 21, "The interpolated string contains unmatched closing braces.")
|> withSingleDiagnostic (Error 1249, Line 1, Col 14, Line 1, Col 21, "The interpolated string contains unmatched closing braces.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm counting correctly, this also starts now at the correct position.


[<Fact>]
let ``Percent sign characters in interpolated strings`` () =
Expand Down