Write briefly about syntax extension in the syntax section

The currently existing syntax extension facilities don't really merit
their own section.
This commit is contained in:
Marijn Haverbeke 2011-11-02 09:43:49 +01:00
parent 5b0c103b39
commit 769e9b669b
4 changed files with 27 additions and 9 deletions

View File

@ -61,9 +61,10 @@ name as the field.
{x, y} { /* Simply bind the fields */ }
}
When you are not interested in all the fields of a record, a record
pattern may end with `, _` (as in `{field1, _}`) to indicate that
you're ignoring all other fields.
The field names of a record do not have to appear in a pattern in the
same order they appear in the type. When you are not interested in all
the fields of a record, a record pattern may end with `, _` (as in
`{field1, _}`) to indicate that you're ignoring all other fields.
## Tags

View File

@ -1,3 +0,0 @@
# Syntax extension
FIXME to be written

View File

@ -8,6 +8,5 @@ args
generic
mod
ffi
ext
task
test

View File

@ -1,7 +1,5 @@
# Syntax Basics
FIXME: briefly mention syntax extentions, #fmt
## Braces
Assuming you've programmed in any C-family language (C++, Java,
@ -307,3 +305,26 @@ written like this:
#[cfg(target_os = "win32")];
/* ... */
}
## Syntax extensions
There are plans to support user-defined syntax (macros) in Rust. This
currently only exists in very limited form.
The compiler defines a few built-in syntax extensions. The most useful
one is `#fmt`, a printf-style text formatting macro that is expanded
at compile time.
std::io::writeln(#fmt("%s is %d", "the answer", 42));
`#fmt` supports most of the directives that [printf][pf] supports, but
will give you a compile-time error when the types of the directives
don't match the types of the arguments.
[pf]: http://en.cppreference.com/w/cpp/io/c/fprintf
All syntax extensions look like `#word`. Another built-in one is
`#env`, which will look up its argument as an environment variable at
compile-time.
std::io::writeln(#env("PATH"));