Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Smalltalk中访问消息文档_Smalltalk_Gnu Smalltalk - Fatal编程技术网

在Smalltalk中访问消息文档

在Smalltalk中访问消息文档,smalltalk,gnu-smalltalk,Smalltalk,Gnu Smalltalk,在Smalltalk中定义类时,可以访问文档注释,如下所示: st> Integer comment 'I am the abstract integer class of the GNU Smalltalk system. My subclasses'' instances can represent signed integers of various sizes (a subclass is picked according to the size), with varying e

在Smalltalk中定义类时,可以访问文档注释,如下所示:

st> Integer comment
'I am the abstract integer class of the GNU Smalltalk system.  My
subclasses'' instances can represent signed integers of various
sizes (a subclass is picked according to the size), with varying
efficiency.'

但也许,我是Smalltalk的新手,但我找不到如何访问方法/消息文档。即

让我们考虑下面的方法

SomeClass >> #msg: arg
  "This is a comment"
  ^self doThisTo: arg
String >> #doubleQuoted
  ^'"', self , '"'
很容易实现用于提取注释的服务,例如:

commentOf: aCompiledMethod
  ^method sourceCode readStream upTo: $"; upTo: $"
事实上,在上面的示例中,我们将得到字符串
“这是一条注释”
。但是,问题是双引号字符并不总是注释分隔符。例如,考虑下面的方法< /P>
SomeClass >> #msg: arg
  "This is a comment"
  ^self doThisTo: arg
String >> #doubleQuoted
  ^'"', self , '"'
如果我们尝试使用上面的方法
#commentOf:
从这个方法中提取注释,我们会得到

' , self, '
这没有任何意义

这意味着我们的解析应该不那么幼稚。因此,我们应该问自己的问题是,使用我们环境中的Smalltalk解析器是否更好。我不知道如何在gnu smalltalk中做到这一点,所以让我在这里展示(作为示例)我们如何在Pharo中继续:

aCompiledMethod ast comments

#ast
消息使用该方法的抽象语法树(也称为解析树)进行应答,该树公开了该方法源代码的语法结构。特别是,它以
CommentNode
对象的形式检测所有注释,这就是为什么
#comments
方法只包括在收集注释时枚举所有解析节点。

方法注释(如果存在)内联在方法体中,通常位于签名的正下方。因此,要获得它们,你应该自己解析方法,或者获取解析树(又称ast)并查找注释节点?一些实现(例如Smalltalk/X)附带了使用该类的示例。在Gnu smalltalk中,我认为在web上查看文档更容易。基础:;对于LIB: