Skip to content

A semantic search tool for Erlang that supports large code-bases.

License

Notifications You must be signed in to change notification settings

klarna-incubator/glass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Glass

A semantic search tool for Erlang that supports large code-bases.

Build Status License Developed at Klarna

Glass is a tool for semantically searching source code, currently focusing on Erlang. You can think of it as "grep, if grep could understand Erlang code". For more information, read the technical design documents.

Usage example

> glass:index(glass, "/path/to/glass").
> glass:search(glass, "maps:without([position], _)").

%% in glass_to_query/1 at ./_build/default/lib/glass_backend/ebin/glass_query.beam:25
30| maps:without([position], Attrs)

%% in minimal_attributes/1 at ./_build/default/lib/glass_backend/ebin/glass_query.beam:90
91| maps:without([position], Map)

For more examples and usage, please refer to the Docs.

Querying language

Glass uses a querying language based on pattern unification (and, in the future, possibly with more logical operators). In practice, this means that in order to query a codebase, you provide a piece of Erlang code that has variables where expressions can go.

The query:

maps:without([position], Arg)

Will match any maps:without call whose first argument is the exact list [position], and the second argument is any Erlang expression, which will be bound to Arg within this query.

Variables are unified, which means that, just like in regular Erlang pattern matching, you can use this to query pieces of code that have the same expression in different places. A query for the identity function is:

fun(A) -> A end

A query for taking the first element of a tuple would be:

fun({A, _}) -> A end

This provides a simple foundation for querying code that is at the same time very powerful. Particularly when extended for refactoring. A query like (syntax not final):

s/log(File, Format, [error])/log(error_log, Format ++ " file: ~p", [error, File])/

Could transform a piece of code like:

log(debug, "Failed, reason=~p", [error])

Into:

log(error_log, "Failed, reason=~p" ++ "file: ~p", [error, debug])

Development setup

Glass requires both OTP21+ and rebar3. rebar3 shell from the root will drop you into an Erlang shell for Glass.

Roadmap

The current focus is on making the query language feature-complete. And we have plans to work on optimisation, refactoring, and more advanced (incremental) static analysis in the future.

See our roadmap document for more details.

How to contribute

See our guide on contributing.

Release History

See our changelog.

Etymology

Glass (/glas/) means "ice cream" in Swedish. English has a homonym with close pronunciation that means "lens", in particular for the purpose of improving its user's eyesight. This sounded like a fun name for a project meant to improve a developer's understanding of their codebase by letting them "magnify" certain aspects and patterns that can happen in big codebases.

After deciding on the name, the acronym "Generic Language and Search System" was backfitted.

License

Copyright © 2020 Klarna Bank AB

For license details, see the LICENSE file in the root of this project.

About

A semantic search tool for Erlang that supports large code-bases.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published