Skip to content

Dialect setting: disallow newlines in single-quoted strings #97

@tmteam

Description

@tmteam

Problem

Currently NFun accidentally allows newlines inside single-quoted strings. QuotationReader scans until a closing quote and doesn't check for \n (0x0A), so multiline content silently passes through.

This is undocumented and inconsistent — NFun is an expression-per-line language where \n is an expression separator.

Proposal

Add a dialect enum:

enum SingleLineString
{
    DenyLineBreak,    // '...' with real \n → compile error (recommended)
    AllowLineBreak,   // '...' with real \n → legacy behavior
}

Default: DenyLineBreak for new code. AllowLineBreak for backward compatibility.

This is needed before introducing triple-quoted strings ('''...''') so that single-quoted strings have well-defined single-line semantics.

Implementation notes

  • QuotationReader.ReadQuotation() — add check: if current == '\n' and SingleLineString.DenyLineBreak → return error
  • Tokenizer — pass dialect flag to ReadText / QuotationReader
  • Escape \n and \r inside single-quoted strings remain valid (they produce the character, not a real newline)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApiNfun syntax is not changed, but C# syntax isSyntaxSyntactic and semantic improvements and sugars

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions