Skip to content

Add Support For Registering Additional Languages - #57

Merged
williamfzc merged 1 commit into
opensibyl:masterfrom
cwarden:additional-languages
Feb 24, 2023
Merged

williamfzc merged 1 commit into
opensibyl:masterfrom
cwarden:additional-languages

Conversation

@cwarden

@cwarden cwarden commented Feb 24, 2023

Copy link
Copy Markdown
Contributor

I'd like to be able to use sibyl with additional languages. I started down the path of changing LangType to an interface and removing the coupling between the core package and the language packages, but it turned out to be quite an intrusive change.

So this presents a possible alternative solution, allowing packages to register languages with sibyl.

Here's an example of an extractor registering a language with sibyl:
https://github.com/octoberswimmer/sibyl-sfapex/blob/master/extractor/apex/extractor_apex.go

And an example of using this extractor:

package main

import (
        "fmt"
        "os"

        "github.com/octoberswimmer/sibyl-sfapex/extractor/apex"
        "github.com/opensibyl/sibyl2/pkg/core"
)

func main() {
        runner := &core.Runner{}
        path := "."
        if len(os.Args) > 1 {
                path = os.Args[1]
        }
        fmt.Println("path is", path)
        extractor := &apex.Extractor{}
        fileUnits, err := runner.File2Units(path, extractor.GetLang(), nil)

        if err != nil {
                panic(err)
        }
        for _, fu := range fileUnits {
                for _, u := range fu.Units {
                        // fmt.Printf("%s: %s\n", fu.Path, u.Kind)
                        _ = u
                }
                calls, err := extractor.ExtractCalls(fu.Units)
                if err != nil {
                        panic(err)
                }
                for _, call := range calls {
                        fmt.Println(fu.Path, call.Span, call.GetIndexName())
                        // fmt.Println(call.GetDesc())
                }
        }

}

@williamfzc
williamfzc self-requested a review February 24, 2023 02:05

@williamfzc williamfzc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Thanks for your interest! Seems like I can not leave some comments on draft PR I think. So I leave them here :)
Sorry for the lack of document about this segment. I would like to add some.

BTW, this link seems private? I got a 404
https://github.com/octoberswimmer/sibyl-sfapex/blob/master/extractor/apex/extractor_apex.go

@cwarden

cwarden commented Feb 24, 2023

Copy link
Copy Markdown
Contributor Author

image

Thanks for your interest! Seems like I can not leave some comments on draft PR I think. So I leave them here :) Sorry for the lack of document about this segment. I would like to add some.

BTW, this link seems private? I got a 404 https://github.com/octoberswimmer/sibyl-sfapex/blob/master/extractor/apex/extractor_apex.go

Sorry, I've changed updated it to public.

@cwarden
cwarden marked this pull request as ready for review February 24, 2023 12:08
@williamfzc
williamfzc merged commit f86f8c5 into opensibyl:master Feb 24, 2023
@williamfzc

Copy link
Copy Markdown
Collaborator

Thank you.
Happy to see this repository can help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址