aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.cpp
AgeCommit message (Collapse)AuthorFilesLines
2015-03-17fixed invalid memory accesses in the expression stack and reworked ↵Robin Haberkorn1-8/+8
expression stack this was probably a regression from d94b18819ad4ee3237c46ad43a962d0121f0c3fe and should not be in v0.5. The return value of Expressions::find_op() must always be checked since it might not find the operator, returning 0 (it used to be 0). A zero index pointed to uninitialized memory - in the worst case it pointed to invalid memory resulting in segfaults. Too large indices were also not handled. This was probably responsible for recent PPA build issues. Valgrind/memcheck reports this error but I misread it as a bogus warning. I took the opportunity to clean up the ValueStack implementation and made it more robust by adding a few assertions. ValueStacks now grow from large to small addresses (like stack data structures usually do). This means, there is no need to work with negative indices into the stack pointer. To reduce the potential for invalid stack accesses, stack indices are now unsigned and have origin 0. Previously, all indices < 1 were faulty but weren't checked. Also, I added some minor optimizations.
2015-03-16documented the automatic EOL translation featureRobin Haberkorn1-3/+8
2015-03-16added EL command for setting/getting the EOL modeRobin Haberkorn1-0/+89
2015-03-10added the <"I> conditional for checking a directory separatorRobin Haberkorn1-0/+4
* It is still useful to have this in macros since you may want to work with non-normalized file names. For instance, env variables (including $SCITECOPATH and $SCITECOCONFIG) may (and will probably) include backward-slash separators on Windows
2015-03-07cleaned up usage of the escape control character: introduced CTL_KEY_ESC and ↵Robin Haberkorn1-5/+5
CTL_KEY_ESC_STR * the reason for the CTL_KEY() macro is to get the control character resulting from a CTRL+Key press -- at least this is how SciTECO presents these key presses. It is also a macro and may be resolved to a constant expression, so it can be used in switch-case statements. Sometimes it is clearer to use standard C escape sequences (like '\t'). * CTL_KEY('[') for escape is hard to read, so I always used '\x1B' which is even more cryptic.
2015-03-02minor optimization: no need to check for NULL when using C++ delete operatorRobin Haberkorn1-2/+1
2015-03-01keep rubbed out command line for later re-insertion and massive Cmdline ↵Robin Haberkorn1-7/+9
cleanup/refactoring * characters rubbed out are not totally removed from the command line, but only from the *effective* command line. * The rubbed out command line is displayed after the command line cursor. On Curses it is grey and underlined. * When characters are inserted that are on the rubbed out part of the command line, the cursor simply moves forward. NOTE: There's currently no immediate editing command for reinserting the next character/word from the rubbed out command line. * Characters resulting in errors are no longer simply discarded but rubbed out, so they will stay in the rubbed out part of the command line, reminding you which character caused the error. * Improved Cmdline formatting on Curses UI: * Asterisk is printed bold * Control characters are printed in REVERSE style, similar to what Scinterm does. The controll character formatting has thus been moved from macro_echo() in cmdline.cpp to the UI implementations. * Updated the GTK+ UI (UNTESTED): I did only, the most important API adaptions. The command line still does not use any colors. * Refactored entire command line handling: * The command line is now a class (Cmdline), and most functions in cmdline.cpp have been converted to methods. * Esp. process_edit_cmd() (now Cmdline::process_edit_cmd()) has been simplified. There is no longer the possibility of a buffer overflow because of static insertion buffer sizes * Cleaned up usage of the cmdline_pos variable (now Cmdline::pc) which is really a program counter that used a different origin as macro_pc which was really confusing. * The new Cmdline class is theoretically 8-bit clean. However all of this will change again when we introduce Scintilla views for the command line. * Added 8-bit clean (null-byte aware) versions of QRegisterData::set_string() and QRegisterData::append_string()
2015-03-01moved String helper functions from sciteco.h and main.cpp to ↵Robin Haberkorn1-0/+1
string-utils.cpp and string-utils.h * also improved performance of String::append() by using g_realloc() * added String::append() variant for non-null-terminated strings
2015-02-23implemented to undo stack memory limitingRobin Haberkorn1-7/+49
* acts as a safe-guard against uninterrupted infinite loops or other operations that are costly to undo in interactive mode. If we're out of memory, it is usually too late to react properly. This implementation tries to avoid OOMs due to SciTECO behaviour. We cannot fully exclude the chance of an OOM error. * The undo stack size is only approximated using the UndoToken::get_size() method. Other ways to measure the exact amount of allocated heap (including size fields in every heap object or using sbrk(0) and similar) are either costly in terms of memory or platform-specific. This implementation does not need any additional memory per heap object or undo token but exploits the fact that undo tokens are virtual already. The size of an undo token is determined at compile time. * Default memory limit of 500mb should be OK for most people. * The current limit can be queried with "2EJ" and set with <x>,2EJ. This also works interactively (a bit tricky!) * Limiting can be disabled. In this case, undo token processing is a bit faster. * closes #3
2015-02-21throw error instead of assertion when loop is closed (>) or continued (F>) ↵Robin Haberkorn1-2/+9
without a corresponding loop start (<) * assertions were introduced very early when there was no proper error handling in SciTECO. However it points to a macro programming error instead of a SciTECO programming error and should not crash the editor. * Perhaps it would be best to check for this kind of "syntax" error also in parse-only modes. This is not done currently. * part of the solution to issue #3
2015-02-14updated Scintilla submodule: fixed tab stop calculation on CursesRobin Haberkorn1-1/+1
* also did some whitespace cleanup in SciTECO now that tabs are displayed properly
2015-02-11updated copyright to 2015Robin Haberkorn1-1/+1
2015-02-11implemented support for different indention stylesRobin Haberkorn1-21/+69
* the ^I command was altered to insert indention characters rather than plain tabs always. * The <TAB> immediate editing command was added for all insertion arguments (I, ^I but also FR and FS) * documentation was extended for a discussion of indention
2014-12-15fixed remaining reference to register "0" in the documentationRobin Haberkorn1-1/+1
2014-11-24implemented pQq and :Qq commandsRobin Haberkorn1-1/+1
2014-11-24Q-Register loading and saving using the IOView classRobin Haberkorn1-0/+1
* EW can save Q-Registers now * the new E% may be used to save a q-register without making it the current document
2014-11-22added EI as non-string-building variant of IRobin Haberkorn1-6/+24
this is analoguous to EU as the string-build equivalent of ^U.
2014-11-22added variant of the ^U command with string building: the EU commandRobin Haberkorn1-0/+1
it became apparent, that something like this is very useful, when constructing the contents of a q-register without editing it. I have decided against introducing another modifier for toggling string building. Most commands have string building enabled and it doesn't hurt. For the few exceptions, an alternative variant can be introduced.
2014-11-22added EJ command: return runtime propertiesRobin Haberkorn1-0/+57
* main motivation is to have a way of getting the number of buffers in the ring. "EJ" or "1EJ" will do that. This simplifies macros that will have to iterate all the buffers. They no longer have to close the existing buffers to do that. * "0EJ" will get the current user interface. This is useful to select a different color scheme in the startup profile depending on the UI, for instance.
2014-11-22added globbing command ENRobin Haberkorn1-0/+2
* implements the same globbing as the EB command already did * uses Globber helper class that behaves more like UNIX glob(). glib only has a glob-style pattern matcher. * The Globber class may be extended later to provide more UNIX-like globbing. * lexer.tes has been updated to make use of globbing. Now, lexers can be automatically loaded and registered at startup. To install a new lexer, it's sufficient to copy a file to the lexers/ directory.
2014-11-21updated documentation on ED (buffer editing) hooksRobin Haberkorn1-1/+2
2014-11-20simplified attaching errors to a position in a macroRobin Haberkorn1-7/+4
introduced Error::set_coord()
2014-11-20Throw error when a macro terminates while a local q-reg is edited.Robin Haberkorn1-14/+26
This is only a problem if the macro created the local Q-Register table (i.e. not when called with ":M") but resulted in segfaults. Since we do not want to save in a Q-Reg whether it is local (and that wouldn't suffice anyway), we do it in the Q-Register table cleanup. The corresponding QRegisterTable::clear() must be called explicitly, since the RBTree::clear() called on destruction does not and cannot throw errors. If QRegisterTable::clear() has been called successfully, the default object destructor will not do much. If it has thrown an error, the destructor will clean up the remaining Q-Registers.
2014-11-20throw error when macro returns with an unterminated commandRobin Haberkorn1-0/+13
it was not possible to inherit the parser state of the last command in a macro. However, it was possible to exit the macro when its last command was not properly terminated. There is no useful conscious application of this behaviour. * If something like an uncomplete E-Command was last in the macro, there was absolutely no effect. However this points to a macro programming error. * If the last command started a string parameter but did not terminate it, the command might be (partially) executed. However the State's done() method wasn't called, which means that some commands will not execute at all. Again there's no useful application of this. When on the other hand, the last command was not terminated by accident, this was not reported to the user.
2014-11-20allow a current buffer if we're editing a Q-RegisterRobin Haberkorn1-2/+2
this eases handling of the "*" register
2014-11-16cleaned up Scintilla document "updating"Robin Haberkorn1-4/+1
* allowed me to remove some obscure global functions and methods like QRegister::update_string(). * Document updating is concentrated in qregisters.cpp now * also fixes some bugs introduced earlier, like undo tokens being generated for non-undo registers (resulting in segfaults on rubout)
2014-11-16rewritten View and Interface base classes using the Curiously Recurring ↵Robin Haberkorn1-1/+2
Template Pattern. * without the one-view-per-buffer designs, many Scintilla send message (SSM) calls could be inlined * with the new design, this was no longer possible using the abstract base classes. the CRT pattern allows inlining again but introduces a strange level of code obscurity. * tests suggest that at high optimization levels, the one-view-per-buffer design and the CRT pattern reduces typical macro runtimes by 30% (e.g. for symbols-extract.tes). * only updated the NCurses UI for the time being
2014-11-16first working version of the one-view-per-buffer designRobin Haberkorn1-13/+13
The user interface provides a Scintilla view abstraction and every buffer is based on a view. All Q-Register strings use a single dedicated view to save memory and initialization time when using many string registers. * this means we can finally implement a working lexer configuration and it only has to be done once when the buffer is first added to the ring. It is unnecessary to magically restore the lexer styles upon rubout of EB (very hard to implement anyway). It is also not necessary to rerun the lexer configuration macro upon rubout which would be hard to reconcile with SciTECO's basic design since every side-effect should be attached to a character. * this means that opening buffers is slightly slower now because of the view initialization * on the other hand, macros with many string q-reg operations are faster now, since the document must no longer be changed on the buffer's view and restored later on. * also now we can make a difference between editing a document in a view and changing the current view, which reduces UI calls * the Document class has been retained as an abstraction about Scintilla documents, used by QRegister Strings. It had to be made virtual, so the view on which the document is created can be specified by a virtual function. There is no additional space overhead for Documents.
2014-11-14added ^# (XOR) operatorRobin Haberkorn1-0/+5
also changed precedence of + operator (higher than minus). the effects of this should be minimal
2014-11-11refactored SciTECO runtime errors: moved from parser.cpp to error.cppRobin Haberkorn1-84/+12
* the GError expection has been renamed to GlibError, to avoid nameclashes when working from the SciTECO namespace
2014-11-11added all of SciTECO's declarations to the "SciTECO" namespaceRobin Haberkorn1-0/+4
normally, since SciTECO is not a library, this is not strictly necessary since every library should use proper name prefixes or namespaces for all global declarations to avoid name clashes. However * you cannot always rely on that * Scintilla does violate the practice of using prefixes or namespaces. The public APIs are OK, but it does define global functions/methods, e.g. for "Document" that clashed with SciTECO's "TECODocument" class at link-time. Scintilla can put its definitions in a namespace, but this feature cannot be easily enabled without patching Scintilla. * a "SciTECO" namespace will be necessary if "SciTECO" is ever to be turned into a library. Even if this library will have only a C-linkage API, it must ensure it doesn't clutter the global namespace. So the old "TECODocument" class was renamed back to "Document" (SciTECO::Document).
2014-11-10clarified conditions when <;> should yield an errorRobin Haberkorn1-2/+11
2014-11-10support new "~" conditional: useful for implying default parameters in macrosRobin Haberkorn1-6/+17
2014-11-09current_doc_must_undo(): check for undo-necessity when operating on the ↵Robin Haberkorn1-12/+25
current document if the current document is a local q-register from a macro call, we must not generate undo tokens, since the local documents are discarded on macro termination.
2014-11-09documented EC and EG commandsRobin Haberkorn1-0/+3
2014-11-09added EG command: pipe from buffer into Q-RegisterRobin Haberkorn1-0/+1
2014-11-09implemented EC command (execute operating system command) in spawn.cppRobin Haberkorn1-0/+2
powerful command for filtering a SciTECO buffer through an external program. It will be described in the sciteco(7) man pages. The implementation uses an asynchronous background process with pipes but is platform independant thanks to glib's g_spawn functions, GIOChannels and event loops. There are however platform differences in how the operating system command is interpreted/parsed.
2014-08-02don't abort on unexpected semicolon (break from loop)Robin Haberkorn1-1/+3
the question remains what to do then. FIXME: consult TECO standard
2014-02-18removed unreliable CHR2STR() macroRobin Haberkorn1-7/+13
* referencing temporaries is unreliable/buggy in GNU C++, at least since v4.7 * in higher optimization levels it resulted in massive memory corruptions * this is responsible for the build issues (PPA build issues) * instead, always declare a buffer on the stack which guarantees that the variable lives long enough * the g_strdup(CHR2STR(x)) idiom has been replaced with String::chrdup(x)
2014-02-15updated Copyright to year 2014Robin Haberkorn1-1/+1
2014-02-15added State::StdError class for constructing errors from std::exception objectsRobin Haberkorn1-5/+7
2014-02-15use GLib's GError information to yield errorsRobin Haberkorn1-2/+3
* results in better error messages, e.g. when opening files * the case that a file to be opened (EB) exists but is not readably is handled for the first time
2014-02-15fixed Execute::macro() and Execute::file() exceptionsRobin Haberkorn1-4/+29
* might throw other exceptions that must be associated with the parent macro level's (stack frame) * add position information to "label not found" errors * Error copy constructors
2014-02-15removed most exception specifications: allow bad_allocs to propagateRobin Haberkorn1-15/+15
* specifications resulted in runtime errors (unexpected exception) when bad_alloc ocurred * specs should be used scarcely: only when the errors that may be thrown are all known and for documentary purposes
2014-02-15glib allocation functions throw std::bad_alloc exceptions now; catch all ↵Robin Haberkorn1-4/+11
bad_allocs and convert them to State::Error * will allow some degree of OOM handling * currently does not work since the exception specifications prevent bad_allocs from propagating. exception specification usage must be completely revised
2014-02-15String::get_coord() calculates line and column of a string positionRobin Haberkorn1-1/+16
* use to get line and column into a stack frame
2014-02-15added support for TECO stack tracingRobin Haberkorn1-14/+57
* when an error is thrown, stack frames are collected on clean up, up to the toplevel macro * the toplevel macro decides how to display the error * now errors in interactive and batch mode are displayed differently * in batch mode, a backtrace is displayed as a sequence of messages * Execute::file() forwards errors correctly * the correct error in the file is displayed in interactive mode * necessary to build the stack trace
2013-07-05only allow command-line replacements when actually editing the replacement ↵Robin Haberkorn1-0/+7
register I felt the urge to implement that after accidentally rubbing out my entire commandline (the work of an hour) just by pressing "}"...
2013-03-19rewritten CHR2STR() using compound statementRobin Haberkorn1-2/+2
* fixes compilation on g++ 4.7 where compound literals are suddenly temporaries (from which you cannot get a pointer) * the compound statement (also GCC extension) should ensure that the string is allocated on the stack with automatic lifetime
2013-03-18explicitly instantiate MicroStateMachine: fixes compilation with gcc-4.4Robin Haberkorn1-1/+1