You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/using-gitbase/examples.md
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -142,7 +142,7 @@ SELECT file_path, uast(blob_content, language(file_path)) FROM files;
142
142
This function allows you to directly filter the retrieved UAST by performing a XPATH query on it:
143
143
144
144
```sql
145
-
SELECT file_path, uast(blob_content, language(file_path), "//FuncLit") FROM files;
145
+
SELECT file_path, uast(blob_content, language(file_path), "//uast:FunctionGroup") FROM files;
146
146
```
147
147
148
148
This UDF will give you `semantic` UASTs by default. To get some other type see the UDF [`uast_mode`](#retrieving-different-kinds-of-uasts-using-uast_mode).
@@ -162,39 +162,39 @@ SELECT file_path, uast_mode("native", blob_content, language(file_path)) FROM fi
162
162
## Filtering UASTs by XPath queries
163
163
164
164
```sql
165
-
SELECT file_path, uast_xpath(uast(blob_content, language(file_path)), "//FieldList") FROM files;
165
+
SELECT file_path, uast_xpath(uast(blob_content, language(file_path)), "//uast:Identifier") FROM files;
166
166
167
-
SELECT file_path, uast_xpath(uast_mode("annotated", blob_content, language(file_path)), "//*[@roleFunction]") FROM files;
167
+
SELECT file_path, uast_xpath(uast_mode("annotated", blob_content, language(file_path)), "//*[@role='Function']") FROM files;
168
168
```
169
169
170
170
## Extracting information from UAST nodes
171
171
172
-
You can retrieve information from the UAST nodes either through the special selectors `@type`, `@token`, `@role`, `@startpos`, `@endpos`:
172
+
You can retrieve information from the UAST nodes either through the special selectors `@type`, `@token`, `@role`, `@pos`:
173
173
174
174
```sql
175
-
SELECT file_path, uast_extract(uast(blob_content, language(file_path), "//FuncLit"), "@startpos") FROM files;
175
+
SELECT file_path, uast_extract(uast(blob_content, language(file_path), "//uast:Block"), "@pos") FROM files;
176
176
```
177
177
178
178
or through a specific property:
179
179
180
180
```sql
181
-
SELECT file_path, uast_extract(uast(blob_content, language(file_path), "//FuncLit"), "internalRole") FROM files;
181
+
SELECT file_path, uast_extract(uast(blob_content, language(file_path), "//uast:Identifier"), "Name") FROM files;
182
182
```
183
183
184
184
As result, you will get an array showing a list of the retrieved information. Each element in the list matches a node in the given sequence of nodes having a value for that property. It means that the length of the properties list may not be equal to the length of the given sequence of nodes:
Copy file name to clipboardExpand all lines: docs/using-gitbase/functions.md
+28-66Lines changed: 28 additions & 66 deletions
Original file line number
Diff line number
Diff line change
@@ -9,98 +9,61 @@ To make some common tasks easier for the user, there are some functions to inter
9
9
|is_remote(reference_name)bool| check if the given reference name is from a remote one |
10
10
|is_tag(reference_name)bool| check if the given reference name is a tag |
11
11
|language(path, [blob])text| gets the language of a file given its path and the optional content of the file |
12
-
|uast(blob, [lang, [xpath]]) blob| returns a sequence of serialized UAST nodes in semantic mode |
13
-
|uast_mode(mode, blob, lang) blob| returns a sequence of serialized UAST nodes specifying its language and mode (semantic, annotated or native) |
12
+
|uast(blob, [lang, [xpath]]) blob| returns a node array of UAST nodes in semantic mode|
13
+
|uast_mode(mode, blob, lang) blob| returns a node array of UAST nodes specifying its language and mode (semantic, annotated or native)|
14
14
|uast_xpath(blob, xpath) blob| performs an XPath query over the given UAST nodes |
15
15
|uast_extract(blob, key) text array| extracts information identified by the given key from the uast nodes |
16
-
|uast_children(blob) blob| returns a flattened array of the children UAST nodes from each one of the UAST nodes in the given sequence|
16
+
|uast_children(blob) blob| returns a flattened array of the children UAST nodes from each one of the UAST nodes in the given array |
17
17
18
18
19
19
## Note about uast, uast_mode, uast_xpath and uast_children functions
20
20
21
-
The data returned by these functions are a list of UAST nodes serialized as explained below.
21
+
These functions make use of [UAST version 2](https://docs.sourced.tech/babelfish/uast/uast-v2), so you should get familiar with the concepts explained in the bblfsh documentation.
22
22
23
-
Each node is serialized sequentially using [protobuf](https://developers.google.com/protocol-buffers/) and prefixed by an Int32 (in big endian byte order) specifying the length of the serialized node. The [bblfsh/sdk](https://github.com/bblfsh/sdk) contains the proto files and the tools to do it.
24
-
25
-
It results in a byte stream following this structure:
26
-
```
27
-
BigEndianInt32(len(marhsal(node))+marshal(node)+
28
-
BigEndianInt32(len(marhsal(node))+marshal(node)+
29
-
BigEndianInt32(len(marhsal(node))+marshal(node)+
30
-
...
31
-
```
23
+
The data returned by these functions is a serialized [array node](https://docs.sourced.tech/babelfish/uast/representation-v2#array) using [protobuf](https://developers.google.com/protocol-buffers/) which contains UAST [object nodes](https://docs.sourced.tech/babelfish/uast/representation-v2#object).
32
24
33
25
As an example of how to manage the serialized data programatically, checkout out the Go code below:
0 commit comments