Книга: Learning GNU Emacs, 3rd Edition

9.2.1.1 Syntax

9.2.1.1 Syntax

Although language modes differ in exact functionality, they all support the same basic concepts. The most important of these involves knowledge of the syntax of the language in question—its characters, vocabulary, and certain aspects of its grammar. We have already seen that Emacs handles some syntactic aspects of human language. When you edit regular text, Emacs knows about words, sentences, and paragraphs: you can move the cursor and delete text with respect to those units. It also knows about certain kinds of punctuation, such as parentheses: when you type a right parenthesis, it "flashes" the matching left parenthesis by moving the cursor there for a second and then returning.[59] This is a convenient way of ensuring that your parentheses match correctly.

Emacs has knowledge about programming language syntax that is analogous to its knowledge of human language syntax. In general, it keeps track of the following basic syntactic elements:

• Words, which correspond to identifiers and numbers in most programming languages.

• Punctuation, which includes such things as operators (e.g., +, -, <, and >) and statement separators (e.g., semicolons).

• Strings, which are strings of characters to be taken literally and surrounded by delimiters (such as quotation marks).

• Parentheses, which can include such things as square brackets ([ and ]) and curly braces ({ and }) as well as regular parentheses.

• Whitespace, such as spaces and tabs, which are to be ignored.

• Comments, which are strings of characters to be ignored and surrounded by delimiters that depend on the language (e.g., /* and */ for C, // and a newline for C++ and Java, or semicolon (;) and a newline for Lisp).

Emacs keeps this information internally in the form of syntax tables; like keymaps (as described in Chapter 10), Emacs has a global syntax table used for all buffers, as well a local table for each buffer, which varies according to the mode the buffer is in. You can view the syntax table for the current buffer by typing C-h s (for describe-syntax). In addition, language modes know about more advanced language-dependent syntactic concepts like statements, statement blocks, functions, subroutines, Lisp syntactic expressions, and so on.

Оглавление книги

Оглавление статьи/книги

Генерация: 0.085. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз