Harmonia-Mode utilizes source code analyses to provide many of its services. This section describes these analyses and how they affect the user.
The Three Phases of Analysis
Harmonia has three phases of analysis: Lexical, Syntax, and Semantic. After every user-edit, Harmonia-Mode initializes three "idle timers" (described below) that wait for specified amounts of idle time to pass before executing each of the three analyses.
Lexical Analysis: The Lexer
Lexical analysis is the most lightweight of the three analyses. It organizes character-sequences into separate words, and uncovers most of the information used for syntax-highlighting.
For instance, if a user were to type
"private int x;" then the lexer would break it up into the words
"private" "space" "int" "space" "x" ";" and would determine that "private" is a keyword to be bold-blue, that "int" is a type to be italicized-grey, and that "x" is an object identifier.
Syntax Analysis: The Parser
The job of the parser is to uncover the structure of programs. For example, it determines, in Java, that the sequence of words
"private" "space" "int" "space" "x" ";" is a variable declaration.
Syntax analysis is needed for most Harmonia-Mode features (those that contain "structure" in their names). It also is needed for the syntax-highlighting of a few constructs, like function names.
The main job of semantic analysis is to determine the names and types of program structures, and to verify their correctness. Consequently, this is the phase of analysis which will uncover type and name errors.
The implementation of semantic analysis varies
considerably among the supported languages (since every programming language has a unique definition), so it is important to understand its features and limitations for the language in which you are working. See the Languages section for more information.
The current state of the analyses is visible on the XEmacs mode-line. A program can be in any one of four analyzed states:
||Lexical, Syntactic, Semantic
Some languages in Harmonia do not currently support semantic analysis. Files in these languages have shorter analysis indicators, like this: .
Semantic Context Menus
You can browse Harmonia-Mode's semantic information by right-clicking on function names, class names, variables and constants that you're interested in. Doing so invokes a contextual menu that displays information about the code you clicked on and gives you links to semantically related sections of the program.
For instance, in a Java program containing the statement return x + 3;, you could right-click on x to invoke the following menu:
In this case, clicking on "Show variable declaration" would open the file containing the definition of the variable x and put the cursor on it.
Harmonia-Mode re-analyzes after each keystroke, once a specified amount of time has passed (usually less than a second). This per-keystroke analysis would be too slow on large files if Harmonia-Mode's analyses were not incremental. To retain snappy response times, Harmonia-Mode only re-analyzes the portions of the program which have changed.
The most fundamental analyses, lexical analysis and syntax analysis (parsing), are both fully incremental. Semantic analysis, unfortunately, is usually not incremental, since a change in one region of a file might potentially impact the analysis of code in any other region. For example, renaming a variable declaration can cause errors in any region of code that references the changed variable. Therefore, semantic analysis may be somewhat slow on larger files.
Scheduling the Analyses during Interactive Use
Analysis results beyong lexing are not very useful to display while the user is actively typing, so we delay running the analysis on the assumption that a pause in typing indicates a logical time to run the analysis.Each of the three analyses each have customizable idle times that delay their execution. The analyses run in sequence after every user-edit, pausing between each analysis until the user has been idle for a the specified amount of time.
Here are the default idle times for each analysis:
If the execution of Harmonia-Mode analyses are causing unwanted pauses, increasing the values of these idle times will probably improve things. For more information on how to do so, see the settings section.