6 ms·
Neat, Though it does make me wonder if a python parser wont soon become standard in editors. Its just too damned convenient for many things, sure you might be
by midjji 5y ago
Neat,
Though it does make me wonder if a python parser wont soon become standard in editors. Its just too damned convenient for many things, sure you might be able to come up with a regexp search and replace that does the same thing, but odds are it will take longer than coding a few loops. BASH sucked far too much, and C++ and most languages lacked the convenient filesystem libs required, but python just works and is easy to read and modify. The downsides of python, like the atrocious speed and low maintainability dont matter for scripts you will use just once.
- tjoff 5y agoPython just works... Every now and then I'm still bitten by the 2->3 transition. And I'd very much not like it to be a required dependency in my systems either. And no, regexps get a bad rep but they are for the easy 99% and insanely quick to come up with. Learn basic syntax and you'll be thankful for decades to come.
- kadoban 5y agoLearn basic syntax and you'll spend the next few decades wondering each time _which_ basic syntax is expected because none of them ever say.
- metalliqaz 5y agoI know the basic syntax and I never have that problem. Perhaps you mean the advanced syntax? However I don't see the problem, there either. I usually don't need it, and to be honest, when I do, I find it more maintainable to use multiple simpler expressions combined with some programming.
- kadoban 5y agoSome by "regex" mean "globs" and you can just use "*" and "?" for stand-ins for some number of characters. Some allow "|", some allow backrefs, some allow "()", or require them escaped with \, or allow them but not with * after. Some are case insensitive, some not. Some allow "{0-5}", some allow "[0-9]", some have handy things like "\w". It's just the guessing game of exactly what they want. It should be required that each regex box has an example next to it using as many allowed features as possible.
- _jal 5y agoLook for 'pcre' on the label. Accept no substitutes and you'll be fine.
- hexane360 5y ago*almost always: https://blog.cloudflare.com/details-of-the-cloudflare-outage-on-july-2-2019/ https://blog.cloudflare.com/details-of-the-cloudflare-outage... >The Lua WAF uses PCRE internally and it uses backtracking for matching and has no mechanism to protect against a runaway expression. https://blog.cloudflare.com/making-the-waf-40-faster/ https://blog.cloudflare.com/making-the-waf-40-faster/ >Back in July 2019, the WAF transitioned from using a regular expression engine based on PCRE to one inspired by RE2, which is based around using a deterministic finite automaton (DFA) instead of backtracking algorithms. This change came as a result of an outage where an update added a regular expression which backtracked enormously on certain HTTP requests, resulting in exponential execution time. >After the migration was finished, we saw no measurable difference in CPU consumption at the edge, but noticed execution time outliers in the 95th and 99th percentiles decreased, something we expected given RE2's guarantees of a linear time execution with the size of the input.
- Semaphor 5y ago> Some by "regex" mean "globs" and you can just use "*" and "?" for stand-ins for some number of characters. What kind of scary tool is that?
- pstoll 5y agoYou must not have suffered enough, I mean used regexs widely enough. He meant “syntax” in the sense that different regex engines have different syntax and capabilities - can I do a negative look ahead assertion in engines Z, how do I do a zero width lookaround in pcre, gnu, python, posix, etc. Depending how far down the rabbit hole you want to go, start here: https://swtch.com/~rsc/regexp/regexp1.html https://swtch.com/~rsc/regexp/regexp1.html
- midjji 5y agoOh and dont forget that just because the documentation says it uses a specific regex syntax, that does not mean its correctly implemented. It gets worse when an application examples specify a specific syntax but what happens in the background is that it will use the default reg exp engine, which can be system or enviroment specified.
- metalliqaz 5y agoI just don't count those cases as 'basic' syntax.
- pstoll 5y agoBasic - naming a capture group. Awk / posix - \1 Perl - $1. Python - (?P<name>). I’d find it hard to ignore the specifics. I mean if you only ever use one tool and were never exposed to other regex engines I guess.
- aasasd 5y agoQuick: which programs use ‘|’ and which use ‘\|’?
- vidarh 5y agoI wouldn't be happy with Python, but I do agree with the general premise that extensibility or automation ought to be expected of editors. My own editor is written in Ruby, and so all extension is done by loading Ruby code into the running process, and I can drop into the Pry debugger with a keypress, or another keypress gives me a prompt to enter a single-line expression instead. The latter is literally a one-line method. Adding a binding to eval() a whole buffer would be equally trivial... Being able to extend everything trivially in a language I'm comfortable with (so not Emacs lisp) makes such a difference to usability. Incidentally, the ability to interact with the open buffers using a script also from outside the editor is another thing I love as an extension mechanism for editors - an idea I first saw in FrexxEd (co-written by the founder of Curl) for the Amiga, which exposed the open buffers in the filesystem (think the Amiga equivalent of a FUSE filesystem), which would have the added benefit of not being language specific. It doesn't need to involve any FUSE-like stuff either - just a command line utility to "cat" an open buffer and to replace the open buffer from stdin would be sufficient.
- midjji 5y agoYeah it does not need to be python, I dropped emacs lisp due to (pain), never liked bash, or perl. Java like in matlab isnt nice either, too damned verbose. Ruby might work, most webstuff is great at showing stuff, but I havent tried it. The generic variant would be to make it modular and replaceable, but that would be a mistake, I would much rather have a tool good at a specific subset of jobs than a config heavy tool which is medicore at all. Perhaps advanced search and replace fits that, but I think its a fundamental aspect of editing. Thats a good idea!
- virchau13 5y agoOut of curiosity, what do you actually use the Ruby liveloading feature for? I use Neovim, which has a similar (but less powerful) feature that allows one to live-execute Lua code (or Vimscript, I suppose). But I almost never use it outside of testing code for my configuration, because the rest of the editor's feature set suffices fairly well for text editing.
- vidarh 5y ago
- oldsecondhand 5y agoYou can record and edit beanshell macros in JEdit. It does exactly what you described but you also have access to all the Java Standard Library (including regex).
- badsectoracula 5y agoI've needed such functionality often enough that i wrote a small utility[0] that uses my LIL scripting language[1] (similar to Tcl) to process some text and have its output. A couple of examples are in the shots [2][3] (note that as this is written in Lazarus it also works under Linux and Mac too, though the site only has a Windows executable). Before that i used to write scripts or even full programs (in Free Pascal which has some simple string handling) to do similar processing and i did find it much more cumbersome to go through that route. Of course this only works for editing/generated/transforming text pieces (and i pretty much always use it via clipboard), for processing files i still end up writing full scripts or programs (depending on the case, if i need to preprocess stuff i use another LIL-based tool, lip[4]). [0] http://runtimeterror.com/tools/liteproc/ http://runtimeterror.com/tools/liteproc/ [1] http://runtimeterror.com/tech/lil/ http://runtimeterror.com/tech/lil/ [2] http://runtimeterror.com/tools/liteproc/shot.png http://runtimeterror.com/tools/liteproc/shot.png [3] http://runtimeterror.com/tools/liteproc/shot2.png http://runtimeterror.com/tools/liteproc/shot2.png [4] http://runtimeterror.com/tools/lip/ http://runtimeterror.com/tools/lip/
- throwanem 5y agoI used to have a Perl script, bound to a key chord, that would pop a dialog box prompting for a s/// regexp-replace expression and apply it to the clipboard contents. Never got around to making it properly interactive, because I stopped needing it when I switched to Emacs and had both its native capabilities and C-u M-| available.
- vesinisa 5y agoThat sounds like a felony abuse of Python. Despite, wasn't perl originally a tragic attempt at such language? :)
- 29athrowaway 5y agoHow do you sandbox python?
- 30f0fn 5y agoHow about elisp?
- aasasd 5y agoIf anyone whose life line says ‘makes an editor’ is reading the above: I beg you to use Lua instead of Python. It's a lot faster, and that matters in productivity apps. Speed can be the difference between ‘I wrote a script’ and ‘I could write a script but didn't’.