Shift + Return在python中插入换行符(Shift + Return to insert linebreak in python)
我试图获得使用
Return
发送文本并按Shift + Return
插入换行符的典型IM客户端的行为。 有没有一种方法可以在Python中以最少的努力实现这一点,例如使用readline和raw_input
?I'm trying to get the behaviour of typical IM clients that use
Return
to send a text andShift + Return
to insert a linebreak. Is there a way to achieve that with minimal effort in Python, using e.g. readline andraw_input
?
原文:https://stackoverflow.com/questions/11343317
最满意答案
事实证明,据我所知,不可能在python中使用不同版本的AST解析器。 (仍然可以通过每次使用不同的版本AST执行多次迭代来单独解析它们)
Turns out it is not possible to use different versions of AST parsers in python to the best of my knowledge. (It is still possible to parse them separately by carrying out multiple iterations each time using a different version AST)
相关问答
更多-
Python解析异常(Python ast parsing exception)[2023-05-07]
事实证明,据我所知,不可能在python中使用不同版本的AST解析器。 (仍然可以通过每次使用不同的版本AST执行多次迭代来单独解析它们) Turns out it is not possible to use different versions of AST parsers in python to the best of my knowledge. (It is still possible to parse them separately by carrying out multiple itera ... -
如何手动构建AST?(How to manually construct an AST?)[2022-04-05]
您需要将您匹配的每个符号与构建树的一小部分的回调关联起来。 例如,让我们来看一个相当常见的结构:嵌套函数调用。 a(b()) 您的终端令牌如下所示: L_PAREN ='(' R_PAREN =')' IDENTIFIER = [az] + 你的非终端符号是这样的: FUNCTION_CALL = IDENTIFIER,L_PAREN,R_PAREN 要么; FUNCTION_CALL = IDENTIFIER,L_PAREN,FUNCTION_CALL,R_PAREN 很明显,规则FUNCTION_CA ... -
当然,所有中间AST节点也可以移动/复制。 例如,如果您了解当x_rule解析为X然后解析x_rule % ','时会发生什么,这一点非常清楚。 向量(或其他容器)将移动/复制X in,并且所有其他元素可能由于重新分配而移动。 如果目标是在树外附加一些数据,而不过多地增加AST节点,则可以考虑单独存储信息并引用它(通过id,指针或某种类型的引用)。 在这种情况下,您可能只需要“垃圾收集”您单独存储的数据(并防止在重回溯的情况下失控累积)。 使用shared_ptr可以以更多开销为代价方便地使用它。 Of c ...
-
使用AST解析所选代码(Parsing selected code with AST)[2024-01-12]
ASTParser.setResolveBindings()的javadoc说: 绑定信息从Java模型获得。 这意味着编译单元必须相对于Java模型。 当源代码来自setSource(ICompilationUnit)或setSource(IClassFile)时,会自动发生这种情况。 当source由setSource(char [])提供时,必须通过调用setProject(IJavaProject)和setUnitName(String)显式地创建该位置。 请注意,影响doc注释检查的编译器选项也可 ... -
这条线是非常错误的 : for line in temp_file.read(): temp_file.read()返回完整的文件内容 。 现在line是一个字符,这解释了为什么literal_eval在第一个[单独打印语法错误。 你想在线上迭代,简单地说: for line in temp_file: line = literal_eval(line) 我知道,我必须小心ast.literal_eval。 是否有比ast.literal_eval更适合的工具? 你将它与eval()混合,这是不 ...
-
启动Devmode时构造Java AST异常时出错(Error constructing Java AST Exception while launching Devmode)[2021-10-07]
看起来它已在2.7中修复 请参阅https://github.com/gwtproject/gwt/issues/8714 Looks like it's fixed in 2.7 See https://github.com/gwtproject/gwt/issues/8714 -
使用PS3.0 + 语言命名空间 AST解析器: $text = Get-Content 'pester-script.ps1' -Raw # text is a multiline string, not an array! $tokens = $null $errors = $null [Management.Automation.Language.Parser]::ParseInput($text, [ref]$tokens, [ref]$errors). FindAll([Func[Man ...
-
好的,这是: pStmt = pFoo <|> pBar pWhiteStmt = do many whitespace p <- pStmt many whitespace return p pTest = do many semi pS <- sepEndBy pWhiteStm (some semi) eof return pS 并测试它: > parse pTest "" ";;foo;bar;\nfoo;; foo;bar;ba ...
-
我不是特别了解Rhino所以我不知道它是否为此提供了具体的帮助。 但总的来说,你可以通过跟踪你所做的改变来直接做到这一点,作为“反改变”。 此方案适用于任何AST系统,而不仅仅是Rhino。 树由节点以及节点与其子节点之间的关系组成。 要构造树,您可以执行命令来创建节点,创建其子节点并将它们链接在一起。 当然,Rhino API为此提供了原始支持。 为了在以后重新构建树,我们仅根据节点构造和子连接/断开来制定要完成的动作列表。 想象一下下面的树: 1:* / \ ...
-
从AST生成字节码(Generate Bytecode from AST)[2022-04-10]
所以事实证明你无法使用com.sun.source.tree。*的任意实现编译用户创建的树。 但是可以做的是将AST打印到字符串并使用Java 6 Compiler API在内存中编译字符串。 So it turns out you cannot compile a tree created by the user using the arbitrary implementations of com.sun.source.tree.*. What can be done though is to print ...