Thanks. Using STClassLoader to load the class and then walking the AST of the class is the way to go! Done!
On Sun, Apr 12, 2015 at 1:34 PM, Holger Freyther <hol...@freyther.de> wrote: > > > On 12 Apr 2015, at 16:56, Junsong Li <ljs.darkf...@gmail.com> wrote: > > > > Thanks. Basically what I want is just a method that compile the .st > file, give me the root node of the AST, then I can traverse the AST and > print out each kind of expression. I have tried _various_ classes in > STInST, none of them works. Here is what I got. There are basically Drivers > and Parsers for parsing: > > The general approach is to look at the testcases. E.g. to parse a class the > first thing I found is: > > > (STInST.STParsingDriver new parseSmalltalkStream: 'Object subclass: Test > [ method [ ^1 ] ]' readStream > > with: STInST.GSTFileInParser) parser > > Did you have a look at the test cases? E.g. the STClassLoader? And did you > look > at scripts/Convert.st which is using STInST to parse and re-format? At the > same > also at the STCompiler which inherits from the RBProgramNodeVisitor? > > The STInST.STParsingDriver hierarchy will load the code and call > >>#evaluate: > on each node. So you don’t get an AST of ASTs with this. > > But if you start the other way around. E.g. with the RBParser you can > parse simple > expressions like STInST.RBParser parseExpression: '3+3’ or even entire > methods > using STInST.RBBracketedMethodParser parseMethod: 'abc [ ^ 3]’ which will > give > you RBMethodNode. > > But starting from the STFileInparser subclass you need to provide a driver > that > will be called whenever something has been parsed. It is then up to you to > decide > what to do with the RB nodes. > > > > > > > Then I am stuck on getting AST out. It appears to having no methods to > return the AST node. Anything wrong with it? > > You looked at the driver. IIRC they go through the classes but don’t store > them. E.g. the > STClassLoader loads a class and you can access a representation of the > class then. > > > _______________________________________________ help-smalltalk mailing list help-smalltalk@gnu.org https://lists.gnu.org/mailman/listinfo/help-smalltalk