From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id 54BB73858C27 for ; Wed, 9 Dec 2020 02:32:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 54BB73858C27 Received: by mail-lj1-x236.google.com with SMTP id y16so920073ljk.1 for ; Tue, 08 Dec 2020 18:32:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=pA50lkdI99/iGscGp+sjIEZVoAgL8wjyRCmVZ0HdHx8=; b=Ht2fEEvqk+uBuHQrhqJ8hfs/66BulF0xc18e24Gzk0je85EwxRdAOFzeZfoSe9jl1R Af6uJYPhc+TpY5+87dTLl+cKvvUwhW45EHRrAiyjlM+dgJ8uyrXVcBkPn9Qx75qPlO4h +RZMHF2kKjEtRz49Gt/89LLhOP0R13eQFAiqfPhYRo0GiB3GE5oLFcRyMBYS/9T/LJcK VmFRZkIiqJXRJ+RKyD6PKpqwgZe4dIpILp4IU70UyF4UGJ1QEBH9HObNBfsgfs7k7K99 WbRj/ykhdGR2/6KigxLVXx9BGWzSlaxXaUvZ4YU2vx6fjA0Fmy8++7kylypaEGX9OfOn iBHw== X-Gm-Message-State: AOAM531AEFpj0IDU7uHqJIwnsrTemujHkSV9SXqU3qA6dwbGcg0vqd8G F/839IEAXAbdJ8MlEXu5JfpY2z3CTN7aeSEscEbRCHs2Ns0zJw== X-Google-Smtp-Source: ABdhPJwFgmwYupXL92fLohNYMEDuhdbHJZQ3iIVmDBEy8GMUG+jH6evYeif9uHdiIeTgup9g2uiyYzrpjPmjRiXHgTo= X-Received: by 2002:a2e:b1c8:: with SMTP id e8mr81987lja.198.1607481157250; Tue, 08 Dec 2020 18:32:37 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Duncan Mak Date: Tue, 8 Dec 2020 21:32:00 -0500 Message-ID: Subject: Re: Analyzing Scheme source code To: kawa mailing list X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: kawa@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Kawa mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Dec 2020 02:32:41 -0000 I played around some more and this now prints out all the declarations in a file: (import (class gnu.expr Declaration Language ModuleExp ModuleManager NameLookup) (class gnu.kawa.io InPort) (class gnu.text Lexer SourceMessages) (class kawa.lang Translator)) (define (print-decls filename) (let* ((language (Language:getDefaultLanguage)) (port (InPort:openFile filename)) (lexer (language:getLexer port (SourceMessages))) (manager (ModuleManager:getInstance)) (minfo (manager:findWithSourcePath port:name)) (translator (language:parse lexer Language:PARSE_IMMEDIATE minfo)) (module ::ModuleExp (translator:currentModule))) (let loop ((decl ::Declaration (module:firstDecl))) (unless (eq? #!null decl) (format #t "~A~%" decl) (loop (decl:nextDecl)))))) On Tue, Dec 8, 2020 at 6:49 PM Duncan Mak wrote: > Hello all, > > I'm interested in running an analysis of some Scheme source code, > specifically, I'm looking to find what's defined in each file and what > references each file takes on. > > I started writing my own analyzer with the match macro, and it looks > something like this: > > (define (process-form form) > (match form > (['define [name @args] @body] > (cons name (map process-form body))) > (['define name value] > value) > (['let [[foo bar] ...] @body] > (map process-form body)) > (['if test then else] > (list (process-form test) > (process-form then) > (process-form else))) > ([procedure @args] > (cons procedure (map process-form args))))) > > Thinking a bit more, rather than doing it myself, I thought maybe I could > reuse the existing machinery that's in Kawa already, i.e. > https://www.gnu.org/software/kawa/internals/semantic-analysis.html > > I think the trick is to get an instance of a Translator for a particular > file, and then call `rewrite` and possibly inspect the resulting Expression > (which ought to be an instance of a ModuleExp?) > > (import (class gnu.expr Language NameLookup) > (class gnu.kawa.io InPort) > (class gnu.text Lexer) > (class kawa.lang Translator)) > > (define (process-file filename) > (let ((lang (Language:getDefaultLanguage)) > (lexer (language:getLexer (InPort:openFile filename) > (SourceMessages)))) > (Translator lang lexer:messages (NameLookup lang)))) > > What I have above seems to only result in an empty Translator. > > What's the right way to set up the environment? > > > -- > Duncan. > -- Duncan.