aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parser.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-01-28updated copyright to 2016Robin Haberkorn1-1/+1
2015-07-14fixed <nA> for n pointing to the buffer endRobin Haberkorn1-1/+5
* throws an error now instead of returning 0 * for <A> positions referring to the buffer end are invalid (unlike many other commands). * has been broken for a very long time (possibly always?)
2015-07-14curses UI: support terminal palette restoration on PDCurses/win32 and xtermRobin Haberkorn1-11/+8
* palette changes are persistent on PDCurses/win32, too. Fortunately, on this port we can reliably query the console palette. This is done ONLY on PDcurses/win32 since on other ports (notably ncurses), this can cause more harm than it helps. * support palette restoration on xterm by hardcoding the appropriate escape sequence. $TERM cannot be used to identify xterm, but looking at $XTERM_VERSION is sufficient hopefully.
2015-07-14programmable terminal color redefinition and theming SciTECO curses UI based ↵Robin Haberkorn1-3/+60
on Scintilla styles * The first 16 colors of the terminal palette can be redefined using the 3EJ property - with all restrictions that ncurses and UNIX terminals impose on us. It is still important to be able to redefine the palette for some color schemes like Solarized since it may be difficult for users to set up the terminal emulator's palette manually. Also when using PDCurses, setting the palette is port-specific or only possible using init_color(). In order to allow color redefinitions across all curses ports it makes sense if SciTECO gives access to the color initialization of curses even if it can guarantee very little about its semantics in general. * 3EJ is completely ignored for GTK+ * use the STYLE_DEFAULT of the current document to style the message line. Fg and bg colors are reversed to guarantee a good contrast to the Scintilla view. Errors are still hardcoded to a red background, warnings to yellow and info messages to green. This allows color-scheming more of SciTECO given that the red, yellow and green terminal colors are not changed fundamentally in the terminal's palette. * info line is now also styled using STYLE_DEFAULT (reverse colors). The Q-Register and buffer names are now written out using format_str() which means that control characters are written out in REVERSE just like in the command line. String::canonicalize_ctl() is still used to canonicalize window titles. * Command line is now modelled as a curses Pad and "blitted" to the command line window. This allowed simplification of the command line drawing code and introduction of format_str(). The command line is now styled according to STYLE_DEFAULT (original fg and bg colors). The rubbed-out part of the command line can now longer be shown in bold black - or even bold light black - since that is not visible in all color themes. Instead it is now only shown in bold. Command line theming problems will be gone once we use a Scintilla view for the command line. * The popup widget is now styled according to STYLE_CALLTIP. * This means that all relevant parts of SciTECO's user interface can now be themed. This allows the creation of themes that redefine the terminal palette radically (e.g. Solarized) and the creation of "bright" themes (e.g. Solarized/bright). * theming of the non-scintilla-view parts of SciTECO is currently unsupported on GTK+. The reason is that both the popup widget and command line widgets have to be rewritten completely in GTK+ and are work in progress, so adapting the current code would be a waste of time. * Added a manual section about the UI and theming.
2015-06-29MicroStateMachine::input() returns whether a result was set nowRobin Haberkorn1-33/+36
* this means that QRegSpecMachine::input() no longer has to return a dummy QRegister in parse-only mode. This saves an unnecessary QRegister table lookup and speeds up parsing. * QRegSpecMachine can now be easily extended to behave differently when returning a Q-Register, e.g. simply returning NULL if a register does not exist, or returning a register by prefix. This is important for some planned commands. * StateExpectQReg::got_register() now gets a QRegister *. It can theoretically be NULL - still we don't have to check for NULL in most cases since NULL is only passed in parse-only mode.
2015-06-27do not imply values for the "=" command but fail instead if argument is missingRobin Haberkorn1-1/+4
* this turned out to be a totally-useless and confusing feature. In general values should only be implied for commands if the advantages of implying values (i.e. if you will often want to imply a certain value) outweigh the reduced error checking. * this was one of the bugs discussed in #4.
2015-06-14handle environment variables more consistentlyRobin Haberkorn1-10/+18
* the registers beginning with "$" are exported into sub-process environments. Therefore macros can now modify the environment (variables) of commands executed via EC/EG. A variable can be modified temporarily, e.g.: [[$FOO] ^U[$FOO]bar$ EC...$ ][$FOO] * SciTECO accesses the global environment registers instead of using g_getenv(). Therefore now, tilde-expansion will always use the current value of the "$HOME" register. Previously, both register and environment variable could diverge. * This effectively fully maps the process environment to a subset of Q-Registers beginning with "$". * This hasn't been implemented by mapping those registers to special implementations that updates the process environment directly, since g_setenv() is non-thread-safe on UNIX and we're expected to have threads soon - at least in the GTK+ UI.
2015-06-12support UNIX-shell-like tilde-expansions in file names and directoriesRobin Haberkorn1-7/+27
* expands to the value of $HOME (the env variable instead of the register which currently makes a slight difference). * supported for tab-completions * supported for all file-name accepting commands. The expansion is done centrally in StateExpectFile::done(). A new virtual method StateExpectFile::got_file() has been introduced to pass the expanded/processed file name to command implementations. * sciteco(7) has been updated: There is now a separate section on file name arguments and file name handling in SciTECO. This information is important but has been scattered across the document previously. * optimized is_glob_pattern() in glob.h
2015-06-02added <FG> command and special Q-Register "$" to set and get the current ↵Robin Haberkorn1-0/+56
working directory * FG stands for "Folder Go" * FG behaves similar to a Unix shell `cd`. Without arguments, it changes to the $HOME directory. * The $HOME directory was previously only used by $SCITECOCONFIG on Unix. Now it is documented on its own, since the HOME directory should also be configurable on Windows - e.g. to adapt SciTECO to a MinGW or Cygwin installation. HOME is initialized just like the other environment variables. This also means that now, the $HOME Q-Register is always defined and can be used by platform-agnostic macros. * FG uses a new kind of tab-completion: for directories only. It would be annoying to complete the FG command after every directory, so this tab-completion does not close the command automatically. Theoretically, it would be possible to close the command after completing a directory with no subdirectories, but this is not supported currently. * Filename arguments are no longer completed with " " if {} escaping is in place as this brings no benefit. Instead no completion character is inserted for this escape mode. * "$" was mapped to the current directory to support an elegant way to insert/get the current directory. Also this allows the idiom "[$ FG...new_dir...$ ]$" for changing the current directory temporarily. * The Q-Register stack was extended to support restoring the string part of special Q-Registers (that overwrite the default functionality) when using the "[$" and "]$" commands. * fixed minor typos (american spelling)
2015-05-25extended <EN> command and used it to optimize "lexer.test..." macrosRobin Haberkorn1-1/+1
* EN may now be used for matching file names (similar to fnmatch(3)). This is used to check the current buffers file extension in the lexer configuration macros instead of using expensive Q-Register manipulations. This halves the overall startup time - it is now acceptable even with the current amount of lexer configurations. * EN may now be used for checking file types. session.tes has been simplified. * BREAKS macro portability (EN now has 2 string arguments). * The Globber class has been extended to allow filtering of glob results by file type.
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