I often use mixtures of code and non-code blocks. If there are different kinds of code blocks, though, there can be problems if you want to execute them. If you execute each code block with a different language processor, you each block has to be independent of the others. They can't share constants, function returns, class definitions, etc. If that's the case, you might as well put each block of a different programming language into a different node, and not mix them.
Also, you couldn't break code in the same language across several code blocks, because how could the processor know if you want one to extend the previous one or be independent? I had to face this issue as I worked on Viewrendered3. Currently, you can render mix and colorize blocks with different languages, but for execution, all the code blocks need to be for the same language (right now limited to only python, but that should be changed in the future). My desire was to support literate programming (that is, to be able to insert commentary in a nicely readable way), so I also had to provide for mixing code and non-code blocks in a node. I also wanted the code to be executable. In the current implementation of VR3, all code blocks in a node or subtree get merged before execution. I would be willing to entertain requests to change this behavior, but I'd have to be convinced that it would be worth the effort! On Monday, March 23, 2020 at 12:09:30 PM UTC-4, Marcel Franke wrote: > > > Am Montag, 23. März 2020 16:49:08 UTC+1 schrieb Edward K. Ream: > > This post >> <https://groups.google.com/d/msg/leo-editor/QBvmeT0zQyM/I4jYcZmiAgAJ> >> shows a button that sends code to rust. Thomas adapted it for Graal/JS >> here >> <https://groups.google.com/d/msg/leo-editor/hweJvjeYiEM/bdNoNWniAwAJ>. >> >> My original code contained a hack, which Thomas naturally used. The hack >> just removes @language directives. >> >> My example was misleading. There is a much better way. Instead of the >> hack: >> >> lines = p.b.split('\n') >> prog = '\n'.join([ >> line for line in lines if not line.startswith('@language') >> ]) >> >> scripts should do this instead: >> >> s = c.atFileCommands.stringToString( >> p, p.b, forcePythonSentinels=False, sentinels=False) >> prog = s.replace("\r\n", "\n") # Use brute force. >> >> This removes all Leo directives and *also* supports @language and >> section references. >> >> I found this code in one of the helpers of g.getScript. It's not so easy >> to use g.getScript directly, as you can see for yourself if you are >> interested. >> >> > Both solutions seems to be flawed as none of them is filtering by language. > Is this uncommon in leo-community? I often have nodes with multiple mixed > languages or mixed plaintext and code. > Both of those solutions would mix this plaintext with code or code of > different languages together it seems. > -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/7a6d712f-f8b6-49db-92c3-702084eb8b6d%40googlegroups.com.
