mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:50:14 +01:00
Switch some codeblocks to recognized languages. (#4811)
Fix syntax highlighting for these code blocks.
This commit is contained in:
+3
-3
@@ -315,7 +315,7 @@ the semantic analysis and the specification of runtime behavior.
|
||||
|
||||
#### Abstract Syntax for Expressions
|
||||
|
||||
```C++
|
||||
```c++
|
||||
enum ExpressionKind { Variable, PatternVariable, Int, Bool,
|
||||
PrimitiveOp, Call, Tuple, Index, GetField,
|
||||
IntT, BoolT, TypeT, FunctionT, AutoT };
|
||||
@@ -384,7 +384,7 @@ alternative: identifier tuple ';'
|
||||
|
||||
#### Abstract Syntax for Statements
|
||||
|
||||
```C++
|
||||
```c++
|
||||
enum StatementKind { ExpressionStatement, Assign, VariableDefinition,
|
||||
If, Return, Sequence, Block, While, Break, Continue,
|
||||
Match };
|
||||
@@ -410,7 +410,7 @@ struct Statement {
|
||||
|
||||
#### Abstract Syntax for Declarations
|
||||
|
||||
```C++
|
||||
```c++
|
||||
struct FunctionDefinition {
|
||||
string name;
|
||||
Expression* param_pattern;
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ A few syntaxes that are likely to influence `if`/`else` are:
|
||||
|
||||
- C++
|
||||
|
||||
```cc
|
||||
```c++
|
||||
if (x) {
|
||||
printf("x is true");
|
||||
} else if (y) {
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ Variables are standard in many languages. Some various forms to consider are:
|
||||
|
||||
- C++:
|
||||
|
||||
```cc
|
||||
```c++
|
||||
int x;
|
||||
int y = 0;
|
||||
bool a = true, *b = nullptr, c;
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ similar in many languages, even if details may change.
|
||||
- C++: A couple example languages following C++'s syntax closely are Java and
|
||||
TypeScript.
|
||||
|
||||
```cc
|
||||
```c++
|
||||
while (x) {
|
||||
DoSomething();
|
||||
}
|
||||
@@ -221,7 +221,7 @@ This proposal does not offer a way to initialize variables in the `while`.
|
||||
|
||||
For comparison, C++ does allow declaring a variable in the condition, such as:
|
||||
|
||||
```cc
|
||||
```c++
|
||||
while (optional<T> next = get_next()) { ... }
|
||||
```
|
||||
|
||||
|
||||
+4
-4
@@ -56,7 +56,7 @@ Semisemi `for` loops have been around for a long time, and are in C. Range-based
|
||||
|
||||
For example, here is a basic semisemi:
|
||||
|
||||
```cc
|
||||
```c++
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
printf("List at %d: %s\n", i, list[i].name);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ for (int i = 0; i < list.size(); ++i) {
|
||||
|
||||
An equivalent semisemi using iterators and the comma operator may look like:
|
||||
|
||||
```cc
|
||||
```c++
|
||||
int i = 0;
|
||||
for (auto it = list.begin(); it != list.end(); ++it, ++i) {
|
||||
printf("List at %d: %s\n", i, it->name);
|
||||
@@ -74,7 +74,7 @@ for (auto it = list.begin(); it != list.end(); ++it, ++i) {
|
||||
Range-based syntax can be simpler, but can also make it more difficult if there
|
||||
are multiple pieces of interesting information:
|
||||
|
||||
```cc
|
||||
```c++
|
||||
int i = 0;
|
||||
for (const auto& x : list) {
|
||||
printf("List at %d: %s\n", i, x.name);
|
||||
@@ -253,7 +253,7 @@ section of the semisemi. The inter-loop evaluation of the third section is
|
||||
important given how it interacts with `continue`. In particular, consider the
|
||||
loops:
|
||||
|
||||
```cc
|
||||
```c++
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (i == 1) continue;
|
||||
printf("%d\n", i);
|
||||
|
||||
Reference in New Issue
Block a user