From 87b433e83c28721ef98ae8a49cb4b1e08e8a8f81 Mon Sep 17 00:00:00 2001 From: Caleb Meurer Date: Mon, 8 Aug 2022 23:36:23 -0700 Subject: [PATCH] Character Literals --- proposals/p1964.md | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 proposals/p1964.md diff --git a/proposals/p1964.md b/proposals/p1964.md new file mode 100644 index 0000000000000..92c5b160b6689 --- /dev/null +++ b/proposals/p1964.md @@ -0,0 +1,81 @@ +# Character literals + + + +[Pull request](https://github.com/carbon-language/carbon-lang/pull/1964) + + + +## Table of contents + +- [Problem](#problem) +- [Background](#background) +- [Proposal](#proposal) +- [Details](#details) +- [Rationale](#rationale) +- [Alternatives considered](#alternatives-considered) + + + +## Problem + +This proposal specifies lexical rules for constant characters in Carbon. + +## Background + +We wish to provide a distinct lexical syntax for character literals versus +string literals. + +In theory we could just reuse string literals for the purpose of character +literals. However, it could benefit the readablity of our code if we had a +distinct lexical syntax for character literals versus string literals. + +## Proposal + +The idea is to create and manage a character literal the same we would as a +string, but using the single quote (') compared to the string double quote ("). + +As with string literals, each character literal would have a different type. + + var Character: w = 'w'; + +We will not support: + +- Multi-line literals +- "raw" literals (using #'x'#) +- Empty character literals (''') + +## Details + +TODO: Fully explain the details of the proposed solution. + +## Rationale + +TODO: How does this proposal effectively advance Carbon's goals? Rather than +re-stating the full motivation, this should connect that motivation back to +Carbon's stated goals and principles. This may evolve during review. Use links +to appropriate sections of [`/docs/project/goals.md`](/docs/project/goals.md), +and/or to documents in [`/docs/project/principles`](/docs/project/principles). +For example: + +- [Community and culture](/docs/project/goals.md#community-and-culture) +- [Language tools and ecosystem](/docs/project/goals.md#language-tools-and-ecosystem) +- [Performance-critical software](/docs/project/goals.md#performance-critical-software) +- [Software and language evolution](/docs/project/goals.md#software-and-language-evolution) +- [Code that is easy to read, understand, and write](/docs/project/goals.md#code-that-is-easy-to-read-understand-and-write) +- [Practical safety and testing mechanisms](/docs/project/goals.md#practical-safety-and-testing-mechanisms) +- [Fast and scalable development](/docs/project/goals.md#fast-and-scalable-development) +- [Modern OS platforms, hardware architectures, and environments](/docs/project/goals.md#modern-os-platforms-hardware-architectures-and-environments) +- [Interoperability with and migration from existing C++ code](/docs/project/goals.md#interoperability-with-and-migration-from-existing-c-code) + +## Alternatives considered + +TODO: What alternative solutions have you considered? + +``` + +```