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
11 changes: 11 additions & 0 deletions docs/languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Article:

Recognizes PHP open tags, variables (`$name`), declaration names, class/interface names, keywords, common builtin functions, property access (`->name`, `::name`), strings, comments, and numbers.

Heredocs and nowdocs (`<<<EOT`, `<<<'EOT'`) run from their opening line to the closing word, which may be indented and may carry a trailing `;`. A `//` or `#` inside the body is text, not a comment.

```php
<?php
function render_code($code) {
Expand Down Expand Up @@ -129,6 +131,8 @@ Recognizes common keywords, class/type declarations, function declarations, func

Multi-line and raw literals are matched whole rather than closing at the first inner quote: Java text blocks and C# raw strings (`"""`), C++ `R"tag(...)tag"`, and Rust `r#"..."#` — the last two carry a counted or named delimiter, so a quote inside the body does not end the literal. In Rust a leading apostrophe is read as a lifetime and typed as the type parameter it stands in for, not as the opening of a character literal.

Ruby heredocs (`<<~SQL`, `<<-EOS`, `<<EOT`) run to the word their own opening line named, and open only on an uppercase word so that `items << thing` stays the append operator. Its percent literals — `%w[…]`, `%i(…)`, `%q{…}`, `%Q<…>` and the `%r{…}` regex — end at the delimiter matching the one that opened them, counting depth so an inner pair does not close the literal early.

```rust
fn main() {
let mut count = 1;
Expand Down Expand Up @@ -207,6 +211,9 @@ Recognizes:
- 70+ common commands as builtin functions: `grep`, `git`, `npm`, `docker`, `kubectl`, ...
- Variables: `$VAR`, `${VAR}`, `$@`, `$?`
- Strings (double-quoted strings support `$` interpolation)
- Heredocs: `<<EOF`, `<<-EOF` with an indented terminator, `<<'EOF'` without
interpolation. The body is one string through its closing word, and a
redirect on the opening line — `cat <<EOF > out.txt` — stays shell.
- Command-line options `-x`, `--foo`

```bash
Expand Down Expand Up @@ -302,6 +309,8 @@ print(square(4))

Recognizes POD doc blocks (`=head1 ... =cut`), `sub` declarations, `$scalar` / `@array` / `%hash` sigil variables, special variables (`$_`, `@ARGV`), regex binds (`=~ /.../`), and list builtins.

The quoting operators `q{…}`, `qq{…}`, `qw(…)` and `qr{…}` end at the delimiter matching their opener, so a `#` inside one is text rather than a comment.

```perl
use strict;
my $name = "world";
Expand All @@ -328,6 +337,8 @@ function Get-Greeting { Write-Host "hi $Name" }

Recognizes `defmodule` / `def` / `defp` declarations, `:atoms`, module attributes (`@doc` colored as doc when followed by `"""`), capitalized module names, string interpolation `#{...}`, and the `|>` pipe.

Sigils close on the delimiter matching their opener: `~s{…}`, `~w[…]`, and `~r//` as a regex. A `"` delimiter is left to the ordinary string rules, so that `~s"""…"""` is not cut at its second quote.

```elixir
defmodule Greeter do
def hello(name), do: IO.puts("hi " <> name)
Expand Down
11 changes: 11 additions & 0 deletions docs/languages.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Article:

识别 PHP 起始标签、变量(`$name`)、声明名、类/接口名、关键字、常见内置函数、属性访问(`->name`, `::name`)、字符串、注释和数字。

heredoc 与 nowdoc(`<<<EOT`、`<<<'EOT'`)从开头行一直匹配到结束词,结束词可以缩进,后面也可以跟一个 `;`。正文里的 `//` 或 `#` 是文本,不是注释。

```php
<?php
function render_code($code) {
Expand Down Expand Up @@ -129,6 +131,8 @@ end

多行与原始字面量整体匹配,不会在第一个内部引号处提前闭合:Java 文本块与 C# 原始字符串(`"""`)、C++ 的 `R"tag(...)tag"`、Rust 的 `r#"..."#` —— 后两者的分隔符带计数或命名,正文里的引号不会结束字面量。Rust 中前导撇号按生命周期识别,着色为它所占据的类型参数,而不是字符字面量的开头。

Ruby 的 heredoc(`<<~SQL`、`<<-EOS`、`<<EOT`)一直延伸到它自己开头行所指定的那个词,并且只在大写词上开启,好让 `items << thing` 保持为追加运算符。它的百分号字面量 —— `%w[…]`、`%i(…)`、`%q{…}`、`%Q<…>` 以及正则 `%r{…}` —— 结束于与开启字符配对的那个定界符,并会计数嵌套深度,因此内层的一对不会让字面量提前闭合。

```rust
fn main() {
let mut count = 1;
Expand Down Expand Up @@ -207,6 +211,9 @@ fn main() {
- 70+ 常用命令作为内置函数:`grep`, `git`, `npm`, `docker`, `kubectl`, ...
- 变量:`$VAR`, `${VAR}`, `$@`, `$?`
- 字符串(双引号支持 `$` 内插)
- heredoc:`<<EOF`、允许缩进结束符的 `<<-EOF`、不做内插的 `<<'EOF'`。正文直到结束词
为止整体作为一个字符串,而开头行上的重定向 —— `cat <<EOF > out.txt` —— 仍留在
shell 一侧。
- 命令行选项 `-x`, `--foo`

```bash
Expand Down Expand Up @@ -302,6 +309,8 @@ print(square(4))

识别 POD 文档块(`=head1 ... =cut`)、`sub` 声明、`$标量` / `@数组` / `%哈希` 符号变量、特殊变量(`$_`、`@ARGV`)、正则绑定(`=~ /.../`)和列表内建函数。

引用运算符 `q{…}`、`qq{…}`、`qw(…)`、`qr{…}` 结束于与开启字符配对的定界符,因此其中的 `#` 是文本而不是注释。

```perl
use strict;
my $name = "world";
Expand All @@ -328,6 +337,8 @@ function Get-Greeting { Write-Host "hi $Name" }

识别 `defmodule` / `def` / `defp` 声明、`:atom` 原子、模块属性(后接 `"""` 的 `@doc` 按文档注释着色)、大写模块名、字符串插值 `#{...}` 和 `|>` 管道。

sigil 结束于与开启字符配对的定界符:`~s{…}`、`~w[…]`,以及作为正则的 `~r//`。`"` 不被当作 sigil 定界符,交回给普通字符串规则处理,这样 `~s"""…"""` 才不会在第二个引号处被截断。

```elixir
defmodule Greeter do
def hello(name), do: IO.puts("hi " <> name)
Expand Down
Loading