Skip to content

Commit db748fa

Browse files
committed
QL: Integrate blame parser into extractor
1 parent 59c1cfb commit db748fa

File tree

7 files changed

+196
-1
lines changed

7 files changed

+196
-1
lines changed

ql/autobuilder/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn main() -> std::io::Result<()> {
1919
.arg("--include-extension=.qll")
2020
.arg("--include-extension=.dbscheme")
2121
.arg("--include=**/qlpack.yml")
22+
.arg("--include=deprecated.blame")
2223
.arg("--size-limit=5m")
2324
.arg("--language=ql")
2425
.arg("--working-dir=.")

ql/extractor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tree-sitter = ">= 0.20, < 0.21"
1313
tree-sitter-ql = { git = "https://github.com/tree-sitter/tree-sitter-ql.git", rev = "d08db734f8dc52f6bc04db53a966603122bc6985"}
1414
tree-sitter-ql-dbscheme = { git = "https://github.com/erik-krogh/tree-sitter-ql-dbscheme.git", rev = "63e1344353f63931e88bfbc2faa2e78e1421b213"}
1515
tree-sitter-ql-yaml = {git = "https://github.com/erik-krogh/tree-sitter-ql.git", rev = "cf704bf3671e1ae148e173464fb65a4d2bbf5f99"}
16+
tree-sitter-blame = {path = "../buramu/tree-sitter-blame"}
1617
clap = "2.33"
1718
tracing = "0.1"
1819
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }

ql/extractor/src/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ fn main() -> std::io::Result<()> {
8787
let language = tree_sitter_ql::language();
8888
let dbscheme = tree_sitter_ql_dbscheme::language();
8989
let yaml = tree_sitter_ql_yaml::language();
90+
let blame = tree_sitter_blame::language();
9091
let schema = node_types::read_node_types_str("ql", tree_sitter_ql::NODE_TYPES)?;
9192
let dbscheme_schema =
9293
node_types::read_node_types_str("dbscheme", tree_sitter_ql_dbscheme::NODE_TYPES)?;
9394
let yaml_schema = node_types::read_node_types_str("yaml", tree_sitter_ql_yaml::NODE_TYPES)?;
95+
let blame_schema = node_types::read_node_types_str("blame", tree_sitter_blame::NODE_TYPES)?;
9496

9597
let lines: std::io::Result<Vec<String>> = std::io::BufReader::new(file_list).lines().collect();
9698
let lines = lines?;
@@ -103,6 +105,7 @@ fn main() -> std::io::Result<()> {
103105
&& !line.ends_with(".qll")
104106
&& !line.ends_with(".dbscheme")
105107
&& !line.ends_with("qlpack.yml")
108+
&& !line.ends_with(".blame")
106109
{
107110
return Ok(());
108111
}
@@ -131,6 +134,16 @@ fn main() -> std::io::Result<()> {
131134
&source,
132135
&code_ranges,
133136
)?
137+
} else if line.ends_with(".blame") {
138+
extractor::extract(
139+
blame,
140+
"blame",
141+
&blame_schema,
142+
&mut trap_writer,
143+
&path,
144+
&source,
145+
&code_ranges,
146+
)?
134147
} else {
135148
extractor::extract(
136149
language,

ql/generator/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ tracing = "0.1"
1313
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
1414
tree-sitter-ql = { git = "https://github.com/tree-sitter/tree-sitter-ql.git", rev = "d08db734f8dc52f6bc04db53a966603122bc6985"}
1515
tree-sitter-ql-dbscheme = { git = "https://github.com/erik-krogh/tree-sitter-ql-dbscheme.git", rev = "63e1344353f63931e88bfbc2faa2e78e1421b213"}
16-
tree-sitter-ql-yaml = {git = "https://github.com/erik-krogh/tree-sitter-ql.git", rev = "cf704bf3671e1ae148e173464fb65a4d2bbf5f99"}
16+
tree-sitter-ql-yaml = {git = "https://github.com/erik-krogh/tree-sitter-ql.git", rev = "cf704bf3671e1ae148e173464fb65a4d2bbf5f99"}
17+
tree-sitter-blame = {path = "../buramu/tree-sitter-blame"}

ql/generator/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@ fn main() -> std::io::Result<()> {
577577
name: "Yaml".to_owned(),
578578
node_types: tree_sitter_ql_yaml::NODE_TYPES,
579579
},
580+
Language {
581+
name: "Blame".to_owned(),
582+
node_types: tree_sitter_blame::NODE_TYPES,
583+
},
580584
];
581585
let mut dbscheme_writer = LineWriter::new(File::create(dbscheme_path)?);
582586
write!(

ql/ql/src/codeql_ql/ast/internal/TreeSitter.qll

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,3 +1743,116 @@ module Yaml {
17431743
final override AstNode getAFieldOrChild() { yaml_yaml_child(this, _, result) }
17441744
}
17451745
}
1746+
1747+
module Blame {
1748+
/** The base class for all AST nodes */
1749+
class AstNode extends @blame_ast_node {
1750+
/** Gets a string representation of this element. */
1751+
string toString() { result = this.getAPrimaryQlClass() }
1752+
1753+
/** Gets the location of this element. */
1754+
final L::Location getLocation() { blame_ast_node_info(this, _, _, result) }
1755+
1756+
/** Gets the parent of this element. */
1757+
final AstNode getParent() { blame_ast_node_info(this, result, _, _) }
1758+
1759+
/** Gets the index of this node among the children of its parent. */
1760+
final int getParentIndex() { blame_ast_node_info(this, _, result, _) }
1761+
1762+
/** Gets a field or child node of this node. */
1763+
AstNode getAFieldOrChild() { none() }
1764+
1765+
/** Gets the name of the primary QL class for this element. */
1766+
string getAPrimaryQlClass() { result = "???" }
1767+
1768+
/** Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. */
1769+
string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
1770+
}
1771+
1772+
/** A token. */
1773+
class Token extends @blame_token, AstNode {
1774+
/** Gets the value of this token. */
1775+
final string getValue() { blame_tokeninfo(this, _, result) }
1776+
1777+
/** Gets a string representation of this element. */
1778+
final override string toString() { result = this.getValue() }
1779+
1780+
/** Gets the name of the primary QL class for this element. */
1781+
override string getAPrimaryQlClass() { result = "Token" }
1782+
}
1783+
1784+
/** A reserved word. */
1785+
class ReservedWord extends @blame_reserved_word, Token {
1786+
/** Gets the name of the primary QL class for this element. */
1787+
final override string getAPrimaryQlClass() { result = "ReservedWord" }
1788+
}
1789+
1790+
/** A class representing `blame_entry` nodes. */
1791+
class BlameEntry extends @blame_blame_entry, AstNode {
1792+
/** Gets the name of the primary QL class for this element. */
1793+
final override string getAPrimaryQlClass() { result = "BlameEntry" }
1794+
1795+
/** Gets the node corresponding to the field `date`. */
1796+
final Date getDate() { blame_blame_entry_def(this, result) }
1797+
1798+
/** Gets the node corresponding to the field `line`. */
1799+
final Number getLine(int i) { blame_blame_entry_line(this, i, result) }
1800+
1801+
/** Gets a field or child node of this node. */
1802+
final override AstNode getAFieldOrChild() {
1803+
blame_blame_entry_def(this, result) or blame_blame_entry_line(this, _, result)
1804+
}
1805+
}
1806+
1807+
/** A class representing `blame_info` nodes. */
1808+
class BlameInfo extends @blame_blame_info, AstNode {
1809+
/** Gets the name of the primary QL class for this element. */
1810+
final override string getAPrimaryQlClass() { result = "BlameInfo" }
1811+
1812+
/** Gets the node corresponding to the field `file_entry`. */
1813+
final FileEntry getFileEntry(int i) { blame_blame_info_file_entry(this, i, result) }
1814+
1815+
/** Gets the node corresponding to the field `today`. */
1816+
final Date getToday() { blame_blame_info_def(this, result) }
1817+
1818+
/** Gets a field or child node of this node. */
1819+
final override AstNode getAFieldOrChild() {
1820+
blame_blame_info_file_entry(this, _, result) or blame_blame_info_def(this, result)
1821+
}
1822+
}
1823+
1824+
/** A class representing `date` tokens. */
1825+
class Date extends @blame_token_date, Token {
1826+
/** Gets the name of the primary QL class for this element. */
1827+
final override string getAPrimaryQlClass() { result = "Date" }
1828+
}
1829+
1830+
/** A class representing `file_entry` nodes. */
1831+
class FileEntry extends @blame_file_entry, AstNode {
1832+
/** Gets the name of the primary QL class for this element. */
1833+
final override string getAPrimaryQlClass() { result = "FileEntry" }
1834+
1835+
/** Gets the node corresponding to the field `blame_entry`. */
1836+
final BlameEntry getBlameEntry(int i) { blame_file_entry_blame_entry(this, i, result) }
1837+
1838+
/** Gets the node corresponding to the field `file_name`. */
1839+
final Filename getFileName() { blame_file_entry_def(this, result) }
1840+
1841+
/** Gets a field or child node of this node. */
1842+
final override AstNode getAFieldOrChild() {
1843+
blame_file_entry_blame_entry(this, _, result) or blame_file_entry_def(this, result)
1844+
}
1845+
}
1846+
1847+
/** A class representing `filename` tokens. */
1848+
class Filename extends @blame_token_filename, Token {
1849+
/** Gets the name of the primary QL class for this element. */
1850+
final override string getAPrimaryQlClass() { result = "Filename" }
1851+
}
1852+
1853+
/** A class representing `number` tokens. */
1854+
class Number extends @blame_token_number, Token {
1855+
/** Gets the name of the primary QL class for this element. */
1856+
final override string getAPrimaryQlClass() { result = "Number" }
1857+
}
1858+
}

ql/ql/src/ql.dbscheme

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,3 +1187,65 @@ yaml_ast_node_info(
11871187
int loc: @location ref
11881188
);
11891189

1190+
#keyset[blame_blame_entry, index]
1191+
blame_blame_entry_line(
1192+
int blame_blame_entry: @blame_blame_entry ref,
1193+
int index: int ref,
1194+
unique int line: @blame_token_number ref
1195+
);
1196+
1197+
blame_blame_entry_def(
1198+
unique int id: @blame_blame_entry,
1199+
int date__: @blame_token_date ref
1200+
);
1201+
1202+
#keyset[blame_blame_info, index]
1203+
blame_blame_info_file_entry(
1204+
int blame_blame_info: @blame_blame_info ref,
1205+
int index: int ref,
1206+
unique int file_entry: @blame_file_entry ref
1207+
);
1208+
1209+
blame_blame_info_def(
1210+
unique int id: @blame_blame_info,
1211+
int today: @blame_token_date ref
1212+
);
1213+
1214+
#keyset[blame_file_entry, index]
1215+
blame_file_entry_blame_entry(
1216+
int blame_file_entry: @blame_file_entry ref,
1217+
int index: int ref,
1218+
unique int blame_entry: @blame_blame_entry ref
1219+
);
1220+
1221+
blame_file_entry_def(
1222+
unique int id: @blame_file_entry,
1223+
int file_name: @blame_token_filename ref
1224+
);
1225+
1226+
blame_tokeninfo(
1227+
unique int id: @blame_token,
1228+
int kind: int ref,
1229+
string value: string ref
1230+
);
1231+
1232+
case @blame_token.kind of
1233+
0 = @blame_reserved_word
1234+
| 1 = @blame_token_date
1235+
| 2 = @blame_token_filename
1236+
| 3 = @blame_token_number
1237+
;
1238+
1239+
1240+
@blame_ast_node = @blame_blame_entry | @blame_blame_info | @blame_file_entry | @blame_token
1241+
1242+
@blame_ast_node_parent = @blame_ast_node | @file
1243+
1244+
#keyset[parent, parent_index]
1245+
blame_ast_node_info(
1246+
unique int node: @blame_ast_node ref,
1247+
int parent: @blame_ast_node_parent ref,
1248+
int parent_index: int ref,
1249+
int loc: @location ref
1250+
);
1251+

0 commit comments

Comments
 (0)