diff --git a/documentation/current/eiffelstudio/eiffelstudio-guided-tour/handling-syntax-and-validity-errors.wiki b/documentation/current/eiffelstudio/eiffelstudio-guided-tour/handling-syntax-and-validity-errors.wiki index 035d5752..fb0fc980 100644 --- a/documentation/current/eiffelstudio/eiffelstudio-guided-tour/handling-syntax-and-validity-errors.wiki +++ b/documentation/current/eiffelstudio/eiffelstudio-guided-tour/handling-syntax-and-validity-errors.wiki @@ -7,60 +7,60 @@ So far we have tried to make sure that everything went smoothly. But in actual s ==Levels of language description== Let's remind ourselves first of how the language is specified. The book [http://www.eiffel.com/doc/ Eiffel: The Language] , the language reference, carefully distinguishes between three levels of description: '''syntax''', '''validity''' and '''semantics'''. Their roles are clearly distinct: -* Syntax defines the structure of software texts. A typical syntax rule states that an assignment starts with a Writable entity, continues with the symbol := , and ends with an Expression . This is a purely structural specification, saying nothing for example about the types of the Writable and the Expression . -* Validity, applicable only to syntactically legal texts, defines required consistency conditions. A typical validity rule states that in an assignment the right-hand-side Expression must conform -- a property of its type, defined rigorously on the basis of inheritance -- to the left-hand-side Writable . Eiffel has about 75 validity rules; part of the language's originality is that these rules are of the " if and only if " form, not only telling you individual error cases ("this is valid only if ... ") but also reassuring you that your text will in fact be valid if it satisfies the conditions listed exhaustively. -* Semantics, applicable only to valid texts, defines the software's expected run-time behavior. A typical semantic rule states that an assignment replaces the value of its left-hand-side Writable by the value of the right-hand-side Expression at the time the assignment is executed, with precise rules on the different possible cases involving references, objects and simple values. +* Syntax defines the structure of software texts. A typical syntax rule states that an assignment starts with a Writable entity, continues with the symbol :=, and ends with an Expression. This is a purely structural specification, saying nothing for example about the types of the Writable and the Expression. +* Validity, applicable only to syntactically legal texts, defines required consistency conditions. A typical validity rule states that in an assignment the right-hand-side Expression must conform -- a property of its type, defined rigorously on the basis of inheritance -- to the left-hand-side Writable. Eiffel has about 75 validity rules; part of the language's originality is that these rules are of the " if and only if " form, not only telling you individual error cases ("this is valid only if ... ") but also reassuring you that your text will in fact be valid if it satisfies the conditions listed exhaustively. +* Semantics, applicable only to valid texts, defines the software's expected run-time behavior. A typical semantic rule states that an assignment replaces the value of its left-hand-side Writable by the value of the right-hand-side Expression at the time the assignment is executed, with precise rules on the different possible cases involving references, objects and simple values. You may make an error at any of these levels: -* Writing = instead of := for the assignment symbol is a syntax error. -* Writing your_integer := your_real , with the types suggested by the names, is a validity error. +* Writing = instead of := for the assignment symbol is a syntax error. +* Writing your_integer := your_real, with the types suggested by the names, is a validity error. * Calling a feature on a void target, violating a precondition, causing a division by zero, are semantic errors. Syntax and validity errors will be detected by the compilation process. For semantic errors, you will rely on contract checking and on the debugging tools described later. Let's look now at examples of the first two cases.
==A syntax error== -To see what happens for a syntax error, replace the keyword is by ist in the first line of routine display of class PARENT (click the position immediately after the s and type a t .). Save the file by clicking the Save button or using CTRL- S and then compile the system. +To see what happens for a syntax error, replace the keyword is by ist in the first line of routine display of class PARENT (click the position immediately after the s and type a t.). Save the file by clicking the Save button or using CTRL- S and then compile the system. [[Image:index-75]] -To correct the error, just bring the mouse back to its location, remove the spurious t , and click Save again; also click Compile to make sure that the project is recompiled up-to-date. +To correct the error, just bring the mouse back to its location, remove the spurious t, and click Save again; also click Compile to make sure that the project is recompiled up-to-date. -You may wonder why the syntax error messages are not a little more verbose than just Syntax error . The reason is merely that Eiffel's syntax, being simple and regular, does not require sophisticated error messages; syntax errors usually result from trivial oversights. If you make a syntax error and the reason is not immediately clear, check the syntax summary in the appendix of [http://www.eiffel.com/doc/ Eiffel: The Language] . +You may wonder why the syntax error messages are not a little more verbose than just Syntax error. The reason is merely that Eiffel's syntax, being simple and regular, does not require sophisticated error messages; syntax errors usually result from trivial oversights. If you make a syntax error and the reason is not immediately clear, check the syntax summary in the appendix of [http://www.eiffel.com/doc/ Eiffel: The Language] .
==A validity error== -A validity error is a violation of one of the validity constraints given in [http://www.eiffel.com/doc/ Eiffel: The Language] . Every such constraint is identified by a four-letter code of the form V XXX (the first letter is always V ). +A validity error is a violation of one of the validity constraints given in [http://www.eiffel.com/doc/ Eiffel: The Language] . Every such constraint is identified by a four-letter code of the form V XXX (the first letter is always V). A validity error will produce a precise error message, which includes the validity code. Although short, the error message is usually sufficient to find out what the error is. If not, you can get the complete rule, straight from the book. -To see this mechanism at work, let us introduce a validity error. There is in fact one ready for you in class TESTROOT . Target a Development Window to this class; at the end of its text, just before the final end , you will find the following comment line: +To see this mechanism at work, let us introduce a validity error. There is in fact one ready for you in class TESTROOT. Target a Development Window to this class; at the end of its text, just before the final end, you will find the following comment line: -- inv: INVALID; -If uncommented, this is a declaration of a feature of type INVALID . A class called INVALID indeed exists in file invalid.e of the root cluster, but it contains a validity error. To see what it is, remove the initial double-dash -- in the above line from class TESTROOT so that it is not a comment any more. +If uncommented, this is a declaration of a feature of type INVALID. A class called INVALID indeed exists in file invalid.e of the root cluster, but it contains a validity error. To see what it is, remove the initial double-dash -- in the above line from class TESTROOT so that it is not a comment any more. [[Image:index-76]] -Click Save , then Compile . Compilation starts but after a few degrees it stops with an error message that appears in the bottom Context Tool (you may have to do some resizing to see it in its entirety): +Click Save, then Compile. Compilation starts but after a few degrees it stops with an error message that appears in the bottom Context Tool (you may have to do some resizing to see it in its entirety): [[Image:index-77]] -As the error message indicates, you have (shame on you) violated the validity rule VUAR , which requires the number and types of actual arguments in a routine call to match the number and types of formal arguments declared in the routine. +As the error message indicates, you have (shame on you) violated the validity rule VUAR, which requires the number and types of actual arguments in a routine call to match the number and types of formal arguments declared in the routine. One of the interesting properties of the error message is that everything in color is '''clickable''' : class name, feature name, but also the error code. This means that you can start a Pick-and-Drop on any of these elements to find out more. -For example, to see the exact context of the error, pick-and-drop the name of the affected feature, display -- appearing on the fifth non-blank line, after Feature: -- and pick-and-drop it to the top Text window. (As you remember this means: right-click on it and release; move the mouse to the text window, without clicking any button; right-click again. During the move the cursor shows a cross, the symbol for features.) This displays the erroneous feature: +For example, to see the exact context of the error, pick-and-drop the name of the affected feature, display -- appearing on the fifth non-blank line, after Feature: -- and pick-and-drop it to the top Text window. (As you remember this means: right-click on it and release; move the mouse to the text window, without clicking any button; right-click again. During the move the cursor shows a cross, the symbol for features.) This displays the erroneous feature: [[Image:index-78]] Note on this display a special property of Pick-and-Drop when its source is a feature name appearing in a validity error message: the instruction that causes the error is highlighted. -In the error message in the Context Tool, the error code itself, VUAR , is also clickable. Assuming the message was not sufficient to understand the error, you can use it to start a Pick-and-Drop. Do this now, by picking that code and starting to move the mouse, but not dropping yet: +In the error message in the Context Tool, the error code itself, VUAR, is also clickable. Assuming the message was not sufficient to understand the error, you can use it to start a Pick-and-Drop. Do this now, by picking that code and starting to move the mouse, but not dropping yet: [[Image:index-79]] -The icon shape for such information elements is a question mark ? . If it is not on a droppable target, as in the bottom Context Tool, that icon will be crossed. In principle the place to drop is the Explanation hole in the Project toolbar, the only one that remains highlighted during the Move step of Pick-and-Drop: +The icon shape for such information elements is a question mark ?. If it is not on a droppable target, as in the bottom Context Tool, that icon will be crossed. In principle the place to drop is the Explanation hole in the Project toolbar, the only one that remains highlighted during the Move step of Pick-and-Drop: [[Image:index-80]] @@ -70,8 +70,8 @@ As is often the case when dropping into a specific hole, you don't need to shoot The result is to display the complete text of the violated rule, straight from the pages of [http://www.eiffel.com/doc/ Eiffel: The Language] . -The rule has several clauses, numbered. Since the error message showed the error code as VUAR(1) , the violated clause is the first; this convention of showing the clause number in parentheses applies to all multi-clause validity constraints. +The rule has several clauses, numbered. Since the error message showed the error code as VUAR(1), the violated clause is the first; this convention of showing the clause number in parentheses applies to all multi-clause validity constraints. -To correct the error the easiest is to go back to class TESTROOT and reinstate the comment symbol -- (two consecutive dashes) on the erroneous line. Save and compile to continue with a valid system. +To correct the error the easiest is to go back to class TESTROOT and reinstate the comment symbol -- (two consecutive dashes) on the erroneous line. Save and compile to continue with a valid system.
diff --git a/documentation/current/eiffelstudio/eiffelstudio-guided-tour/recompiling-and-editing.wiki b/documentation/current/eiffelstudio/eiffelstudio-guided-tour/recompiling-and-editing.wiki index 6cefea19..3a4b018e 100644 --- a/documentation/current/eiffelstudio/eiffelstudio-guided-tour/recompiling-and-editing.wiki +++ b/documentation/current/eiffelstudio/eiffelstudio-guided-tour/recompiling-and-editing.wiki @@ -18,15 +18,15 @@ Make sure that the Editing Tool is big enough to display the text of the class: The Editing Tool hosts a text editor which you can use to change the class text. Here the routine display starts by outputting a simple message; let's precede it by another line of display to check that we affected the outcome. We'll want to add the following two lines just after the do, before the first two instructions of the routine: - io.put_string ("This is some more added text") - io.new_line + io.put_string ("This is some more added text") + io.new_line -They are very similar to the current first two lines of the routine, so you can just use copy-paste: select the first two lines with the mouse, copy them using CTRL- C (or Copy from the Edit menu), then paste them just after the do using CTRL- V (or Paste from the Edit menu). Add or remove tabs to align with the rest of the routine, and change the string to THIS IS SOME MORE ADDED TEXT so that the result will look like what's shown on the next figure. This is all there is to change; the second line remains untouched. Please check the result and be careful not to introduce any mistakes; in the next section we'll study how EiffelStudio will report syntax and other errors, but right now we want to see what happens when everything is right! +They are very similar to the current first two lines of the routine, so you can just use copy-paste: select the first two lines with the mouse, copy them using CTRL-C (or Copy from the Edit menu), then paste them just after the do using CTRL-V (or Paste from the Edit menu). Add or remove tabs to align with the rest of the routine, and change the string to THIS IS SOME MORE ADDED TEXT so that the result will look like what's shown on the next figure. This is all there is to change; the second line remains untouched. Please check the result and be careful not to introduce any mistakes; in the next section we'll study how EiffelStudio will report syntax and other errors, but right now we want to see what happens when everything is right! [[Image:index-67]] -Now save your changes; you may indifferently use CTRL- S, the Save entry from the Edit menu, or the Save button highlighted on the figure. (If you forget to save, the next compilation will tell you so, and ask you if from now on you want all non-saved class edits to be saved automatically.) +Now save your changes; you may indifferently use CTRL-S, the Save entry from the Edit menu, or the Save button highlighted on the figure. (If you forget to save, the next compilation will tell you so, and ask you if from now on you want all non-saved class edits to be saved automatically.)
==Recompiling and executing after a change== @@ -46,34 +46,44 @@ The editing facilities in the Editing Tool are provided by the EiffelStudio Edit The online documentation provides many more details about editing functions. Here are the essentials. -First, the key property of any interactive system: '''Undo'''. You can cancel the latest editing command, or any earlier one performed during the current session, by choosing Undo from the Edit menu, or typing CTRL- Z. To cancel more than one command, apply Undo repetitively; there is no limit to the number of undoable commands within a session. (When you exit EiffelStudio, however, the editing history is lost.) To redo an undone command, use Redo from the Edit menu or CTRL- Y. +First, the key property of any interactive system: '''Undo'''. You can cancel the latest editing command, or any earlier one performed during the current session, by choosing Undo from the Edit menu, or typing CTRL-Z. To cancel more than one command, apply Undo repetitively; there is no limit to the number of undoable commands within a session. (When you exit EiffelStudio, however, the editing history is lost.) To redo an undone command, use Redo from the Edit menu or CTRL-Y. {{note|Since right now we don't need to do any actual editing to continue this Guided Tour, we suggest that you don't change the text of class PARENT but simply look up the menu entries described next, without actually selecting them. If you do make a change, voluntary or not, you should at the end of this editor discussion perform enough Undo commands to get the text of class PARENT back to its original state. }} -To '''copy''', '''cut''' and '''paste''' use the corresponding entries in the Edit menu or the familiar keyboard shortcuts CTRL- C, CTRL- X and CTRL- V. +To '''copy''', '''cut''' and '''paste''' use the corresponding entries in the Edit menu or the familiar keyboard shortcuts CTRL-C, CTRL-X and CTRL-V. -When you edit text, it will be automatically '''indented''' according to standard Eiffel style rules. If you prefer to remain in charge of your own indenting, you can disable this facility through Tools --> Preferences --> Editor. +When you edit text, it will be automatically '''indented''' according to standard Eiffel style rules. If you prefer to remain in charge of your own indenting, you can disable this facility through + +Tools --> Preferences --> Editor -To indent a sequence of lines, select the lines, then use Edit --> Advanced --> Indent selection. You can also use the Tab key, but only if the selection consists of one or more entire lines; otherwise typing Tab will simply replace the selected text with a Tab character. Shift-Tab will similarly decrease indentation by one step. +To indent a sequence of lines, select the lines, then use + +Edit --> Advanced --> Indent selection +You can also use the Tab key, but only if the selection consists of one or more entire lines; otherwise typing Tab will simply replace the selected text with a Tab character. Shift-Tab will similarly decrease indentation by one step. -To '''comment out''' a sequence of lines, select them and use Edit --> Advanced --> Comment or CTRL- K. Conversely, CTRL-Shift- K will uncomment. Also in the Edit --> Advanced menu are "set to upper case", with the keyboard shortcut CTRL- U, and to lower case, CTRL-Shift- U. +To '''comment out''' a sequence of lines, select them and use + +Edit --> Advanced --> Comment +or CTRL-K. Conversely, CTRL-Shift-K will uncomment. Also in the Edit --> Advanced menu are "set to upper case", with the keyboard shortcut CTRL-U, and to lower case, CTRL-Shift-U. -Other useful facilities of the Edit --> Advanced menu are: -* Embed in "if", or CTRL- I, which will create a conditional instruction and include the selected instructions in it. -* Embed in "debug", CTRL- D, which will include the selected instructions in a debug ... end instruction, so that their execution becomes conditional on a Debug compilation option. +Other useful facilities of the Edit --> Advanced menu are: +* Embed in "if", or CTRL-I, which will create a conditional instruction and include the selected instructions in it. +* Embed in "debug", CTRL-D, which will include the selected instructions in a debug ... end instruction, so that their execution becomes conditional on a Debug compilation option.
==Search and replace== The editor lets you search for text and replace occurrences, individually or globally. We assume you have seen a text search facility before, so we'll just emphasize some of the less obvious features. -To start a search, make sure the Search Tool is active by clicking the Search button in the top toolbar (this one we'll let you find) or using the Edit --> Find menu entry. +To start a search, make sure the Search Tool is active by clicking the Search button in the top toolbar (this one we'll let you find) or using the Edit --> Find menu entry. {{note|that although we are studying Search as part of the Editor, this function also applies to any textual form displayed in the Context Tool; make sure to start a Search from the tool that you want to search.'' }} -{{note|If you press CTRL - F in a tool you will get a quick search bar that quickly allows to search for something in the current text.}} +{{note|If you press CTRL-F in a tool you will get a quick search bar that quickly allows to search for something in the current text.}} The Search Tool presents a number of self-explanatory options: + + [[Image:index-69]] You can enter a term to replace your search term in the Replace with box. @@ -84,7 +94,10 @@ The Search for field has an associated drop-down list, so that you
==Let the editor do the typing== -Particularly interesting are the editor's '''automatic completion''' facilities. Well, particularly interesting for most people: maybe you like your editor to do the grunt work for you, or maybe you don't. In the latter case -- if you prefer to be in control of all the details -- don't worry: through Tools --> Preferences --> Editor you can easily disable any facility that you don't like. The behavior described here is the default. +Particularly interesting are the editor's '''automatic completion''' facilities. Well, particularly interesting for most people: maybe you like your editor to do the grunt work for you, or maybe you don't. In the latter case -- if you prefer to be in control of all the details -- don't worry: through + +Tools --> Preferences --> Editor +you can easily disable any facility that you don't like. The behavior described here is the default. The EiffelStudio Editor knows about Eiffel syntax and will recognize syntactic elements as you type them. It will color them according to standard conventions: basic elements in black, keywords in blue, comments in dark red. You can change these conventions through Preferences. @@ -100,35 +113,41 @@ To start a routine, type the routine name followed by the keyword isthinks of writing a feature without a header comment). At the end of the header comment, type Return if the header comment continues, otherwise type a down arrow to continue with the indentation for the beginning of the routine, with one of the keywords require, local, do, external, once. Once you type do, followed by a Return or space, the completion mechanism will insert the appropriate end, but other than that it doesn't try to produce an entire routine structure because there are too many syntactical choices (precondition or not, postcondition or not, locals or not etc.). -Also interesting is '''feature completion''', using the '''CTRL-SPACE''' key. It works at two levels: -* You can type the beginning of the name of a feature of the current class, then CTRL-SPACE to get possible completions. -* Once you have typed the name of a query (attribute or function), either all by yourself or aided by the previous completion technique, you can type a period followed by CTRL-SPACE to get the list of possible features to be applied, deduced from the list of features in the corresponding class (the type of the query). +Also interesting is '''feature completion''', using the CTRL-SPACE key. It works at two levels: +* You can type the beginning of the name of a feature of the current class, then CTRL-SPACE to get possible completions. +* Once you have typed the name of a query (attribute or function), either all by yourself or aided by the previous completion technique, you can type a period followed by CTRL-SPACE to get the list of possible features to be applied, deduced from the list of features in the corresponding class (the type of the query). In both cases, if more than one completion is possible, you will get a menu of the possibilities. You can scroll through it with the up and down arrow keys, or the mouse, and select one through Enter or double-click. You can also or give up through the Escape key. -Here for example is the menu you will see in the body of our example routine if you type io . followed by CTRL-SPACE, where io is the feature, coming from class ANY, that provides access to standard input and output facilities: +Here for example is the menu you will see in the body of our example routine if you type io. followed by CTRL-SPACE, where io is the feature, coming from class ANY, that provides access to standard input and output facilities: [[Image:index-73]] The following properties enhance the convenience of the completion mechanisms: * If only one completion is possible, no menu appears; the completion is selected. -* If the cursor is just after the name of a query (which you have fully typed, or obtained through completion), typing CTRL-SPACE once more will produce a period, as if you had typed it. -* When a menu of possible completions is displayed, typing CTRL-SPACE will select the first of them. +* If the cursor is just after the name of a query (which you have fully typed, or obtained through completion), typing CTRL-SPACE once more will produce a period, as if you had typed it. +* When a menu of possible completions is displayed, typing CTRL-SPACE will select the first of them. The combination of these facilities means that you can often obtain what you want simply by typing CTRL-SPACE repeatedly. Also note the following properties of automatic feature completion: -* The mechanism will only work for queries that were present at the time of the last successful compilation. So if you add an attribute, say attr, to the current class, and do not recompile, typing a -CTRL-SPACE will not display attr. To make sure that it's included in completion proposals, save and recompile. (Remember, incremental compilation is fast in EiffelStudio, so there is nothing wrong in compiling early and often.) The same rule holds for features of other classes, those that will appear in proposed completions after a period. +* The mechanism will only work for queries that were present at the time of the last successful compilation. So if you add an attribute, say attr, to the current class, and do not recompile, typing a then CTRL-SPACE will not display attr. To make sure that it's included in completion proposals, save and recompile. (Remember, incremental compilation is fast in EiffelStudio, so there is nothing wrong in compiling early and often.) The same rule holds for features of other classes, those that will appear in proposed completions after a period. * Automatic completion is applicable to features, not local entities or formal arguments. -* The features proposed for automatic completion include all features of the class: those declared in the class itself, or immediate features, and those inherited from proper ancestors, direct or indirect, with one exception: by default the list will not include features from the universal class ANY, which serves as ancestor to all classes and provides many features for comparison, copying, input-output, reflection etc. Including ANY's features would clutter all menus with too many features. So for example typing i followed by CTRL-SPACE will not suggest io among the possible completions. You can change this policy through Preferences. The policy does not apply to remote feature completion for an entity x declared of type ANY : typing CTRL-SPACE after x . will produce the list of ANY 's features. +* The features proposed for automatic completion include all features of the class: those declared in the class itself, or immediate features, and those inherited from proper ancestors, direct or indirect, with one exception: by default the list will not include features from the universal class ANY, which serves as ancestor to all classes and provides many features for comparison, copying, input-output, reflection etc. Including ANY's features would clutter all menus with too many features. So for example typing i followed by CTRL-SPACE will not suggest io among the possible completions. You can change this policy through Preferences. The policy does not apply to remote feature completion for an entity x declared of type ANY : typing CTRL-SPACE after x. will produce the list of ANY's features. ==Using your own editor== You may have a favorite editor and prefer to use it, at least in some cases. The EiffelStudio incremental compilation mechanism, to be studied shortly, recognizes that files have been modified outside of EiffelStudio (by checking their time stamps) and will without any fuss take their modified versions into account. -You can also call an outside editor on a class from within EiffelStudio. Just use File --> External editor or the corresponding button in the top toolbar. +You can also call an outside editor on a class from within EiffelStudio. Just use + +File --> External editor +or the corresponding button in the top toolbar. -This will call the editor of your choice. The default is Notepad on Windows and Vi on Unix and Linux. You can easily change this to any editor by entering the desired editor command in Tools --> Preferences --> Global Preferences. In this command text you can use the two special notations $target and $line ; when EiffelStudio calls the selected command, it will replace any occurrence of $target by the name of the file where the current class resides, and $line by the line number at which the Editing Tool is currently scrolled. If you include one or both of these markers at the appropriate argument positions for the command, this will enable you -- assuming the editor supports the appropriate options -- to make sure it starts at exactly the right place. For example the default editor command under Unix is +This will call the editor of your choice. The default is Notepad on Windows and Vi on Unix and Linux. You can easily change this to any editor by entering the desired editor command in + +Tools --> Preferences --> Global Preferences +In this command text you can use the two special notations $target and $line ; when EiffelStudio calls the selected command, it will replace any occurrence of $target by the name of the file where the current class resides, and $line by the line number at which the Editing Tool is currently scrolled. If you include one or both of these markers at the appropriate argument positions for the command, this will enable you -- assuming the editor supports the appropriate options -- to make sure it starts at exactly the right place. For example the default editor command under Unix is vi +$line $target