Skip to content

Commit 97d3a2f

Browse files
committed
gitbase, function: change order of uast_mode params
Now uses (mode, blob, lang). This way we can make language optional without breaking back compatibiliy. Signed-off-by: Javi Fontan <[email protected]>
1 parent 52014be commit 97d3a2f

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

docs/using-gitbase/functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To make some common tasks easier for the user, there are some functions to inter
1010
|is_tag(reference_name)bool| check if the given reference name is a tag |
1111
|language(path, [blob])text| gets the language of a file given its path and the optional content of the file |
1212
|uast(blob, [lang, [xpath]])json_blob| returns an array of UAST nodes as blobs in semantic mode |
13-
|uast_mode(blob, lang, mode)json_blob| returns an array of UAST nodes as blobs specifying its language and mode (semantic, annotated or native) |
13+
|uast_mode(mode, blob, lang)json_blob| returns an array of UAST nodes as blobs specifying its language and mode (semantic, annotated or native) |
1414
|uast_xpath(json_blob, xpath)| performs an XPath query over the given UAST nodes |
1515

1616
## Standard functions

integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,19 @@ func TestUastQueries(t *testing.T) {
274274
INNER JOIN blobs b
275275
ON b.blob_hash = te.blob_hash
276276
WHERE te.tree_entry_name = 'example.go'`, 1},
277-
{`SELECT uast_xpath(uast_mode(blob_content, language(tree_entry_name, blob_content), 'semantic'), '//Identifier') as uast,
277+
{`SELECT uast_xpath(uast_mode('semantic', blob_content, language(tree_entry_name, blob_content)), '//Identifier') as uast,
278278
tree_entry_name
279279
FROM tree_entries te
280280
INNER JOIN blobs b
281281
ON b.blob_hash = te.blob_hash
282282
WHERE te.tree_entry_name = 'example.go'`, 1},
283-
{`SELECT uast_xpath(uast_mode(blob_content, language(tree_entry_name, blob_content), 'annotated'), '//*[@roleIdentifier]') as uast,
283+
{`SELECT uast_xpath(uast_mode('annotated', blob_content, language(tree_entry_name, blob_content)), '//*[@roleIdentifier]') as uast,
284284
tree_entry_name
285285
FROM tree_entries te
286286
INNER JOIN blobs b
287287
ON b.blob_hash = te.blob_hash
288288
WHERE te.tree_entry_name = 'example.go'`, 1},
289-
{`SELECT uast_xpath(uast_mode(blob_content, language(tree_entry_name, blob_content), 'native'), '//*[@ast_type=\'FunctionDef\']') as uast,
289+
{`SELECT uast_xpath(uast_mode('native', blob_content, language(tree_entry_name, blob_content)), '//*[@ast_type=\'FunctionDef\']') as uast,
290290
tree_entry_name
291291
FROM tree_entries te
292292
INNER JOIN blobs b

internal/function/uast.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ func (f UAST) Eval(ctx *sql.Context, row sql.Row) (out interface{}, err error) {
159159

160160
// UASTMode returns an array of UAST nodes as blobs.
161161
type UASTMode struct {
162+
Mode sql.Expression
162163
Blob sql.Expression
163164
Lang sql.Expression
164-
Mode sql.Expression
165165
}
166166

167167
// NewUASTMode creates a new UASTMode UDF.
168-
func NewUASTMode(blob, lang, xpath sql.Expression) sql.Expression {
169-
return &UASTMode{blob, lang, xpath}
168+
func NewUASTMode(mode, blob, lang sql.Expression) sql.Expression {
169+
return &UASTMode{mode, blob, lang}
170170
}
171171

172172
// IsNullable implements the Expression interface.
@@ -219,7 +219,7 @@ func (f UASTMode) TransformUp(fn sql.TransformExprFunc) (sql.Expression, error)
219219

220220
// String implements the Expression interface.
221221
func (f UASTMode) String() string {
222-
return fmt.Sprintf("uast_mode(%s, %s, %s)", f.Blob, f.Lang, f.Mode)
222+
return fmt.Sprintf("uast_mode(%s, %s, %s)", f.Mode, f.Blob, f.Lang)
223223
}
224224

225225
// Eval implements the Expression interface.

internal/function/uast_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ func TestUASTMode(t *testing.T) {
3434
defer cleanup()
3535

3636
mode := &UASTMode{
37-
Blob: expression.NewGetField(0, sql.Blob, "", false),
38-
Lang: expression.NewGetField(1, sql.Text, "", false),
39-
Mode: expression.NewGetField(2, sql.Text, "", false),
37+
Mode: expression.NewGetField(0, sql.Text, "", false),
38+
Blob: expression.NewGetField(1, sql.Blob, "", false),
39+
Lang: expression.NewGetField(2, sql.Text, "", false),
4040
}
4141

4242
u, _ := bblfshFixtures(t, ctx)
@@ -47,9 +47,9 @@ func TestUASTMode(t *testing.T) {
4747
row sql.Row
4848
expected interface{}
4949
}{
50-
{"annotated", mode, sql.NewRow([]byte(testCode), "Python", "annotated"), u["annotated"]},
51-
{"semantic", mode, sql.NewRow([]byte(testCode), "Python", "semantic"), u["semantic"]},
52-
{"native", mode, sql.NewRow([]byte(testCode), "Python", "native"), u["native"]},
50+
{"annotated", mode, sql.NewRow("annotated", []byte(testCode), "Python"), u["annotated"]},
51+
{"semantic", mode, sql.NewRow("semantic", []byte(testCode), "Python"), u["semantic"]},
52+
{"native", mode, sql.NewRow("native", []byte(testCode), "Python"), u["native"]},
5353
}
5454

5555
for _, tt := range testCases {

0 commit comments

Comments
 (0)