Skip to content

Commit 3004068

Browse files
authored
QL: "Parse" YAML without errors
1 parent 3ed7f96 commit 3004068

5 files changed

Lines changed: 103 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extractor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2018"
1010
flate2 = "1.0"
1111
node-types = { path = "../node-types" }
1212
tree-sitter = "0.19"
13-
tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "a9348d405de3b2dde0e6d7e59d476ae91516b7af" }
13+
tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "577c43d96c93915bd7ae9c2765d11be8db102952" }
1414
clap = "2.33"
1515
tracing = "0.1"
1616
tracing-subscriber = { version = "0.2", features = ["env-filter"] }

generator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ edition = "2018"
1010
node-types = { path = "../node-types" }
1111
tracing = "0.1"
1212
tracing-subscriber = { version = "0.2", features = ["env-filter"] }
13-
tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "a9348d405de3b2dde0e6d7e59d476ae91516b7af" }
13+
tree-sitter-ql = { git = "https://github.com/tausbn/tree-sitter-ql.git", rev = "577c43d96c93915bd7ae9c2765d11be8db102952" }

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

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,26 +1687,86 @@ module Generated {
16871687
override AstNode getAFieldOrChild() { variable_def(this, result, _) }
16881688
}
16891689

1690+
/** A class representing `yaml_comment` nodes. */
1691+
class YamlComment extends @yaml_comment, AstNode {
1692+
/** Gets the name of the primary QL class for this element. */
1693+
override string getAPrimaryQlClass() { result = "YamlComment" }
1694+
1695+
/** Gets the location of this element. */
1696+
override Location getLocation() { yaml_comment_def(this, _, result) }
1697+
1698+
/** Gets the child of this node. */
1699+
YamlValue getChild() { yaml_comment_def(this, result, _) }
1700+
1701+
/** Gets a field or child node of this node. */
1702+
override AstNode getAFieldOrChild() { yaml_comment_def(this, result, _) }
1703+
}
1704+
16901705
/** A class representing `yaml_entry` nodes. */
16911706
class YamlEntry extends @yaml_entry, AstNode {
16921707
/** Gets the name of the primary QL class for this element. */
16931708
override string getAPrimaryQlClass() { result = "YamlEntry" }
16941709

16951710
/** Gets the location of this element. */
1696-
override Location getLocation() { yaml_entry_def(this, _, _, result) }
1711+
override Location getLocation() { yaml_entry_def(this, _, result) }
1712+
1713+
/** Gets the child of this node. */
1714+
AstNode getChild() { yaml_entry_def(this, result, _) }
1715+
1716+
/** Gets a field or child node of this node. */
1717+
override AstNode getAFieldOrChild() { yaml_entry_def(this, result, _) }
1718+
}
1719+
1720+
/** A class representing `yaml_key` nodes. */
1721+
class YamlKey extends @yaml_key, AstNode {
1722+
/** Gets the name of the primary QL class for this element. */
1723+
override string getAPrimaryQlClass() { result = "YamlKey" }
1724+
1725+
/** Gets the location of this element. */
1726+
override Location getLocation() { yaml_key_def(this, result) }
1727+
1728+
/** Gets the `i`th child of this node. */
1729+
AstNode getChild(int i) { yaml_key_child(this, i, result) }
1730+
1731+
/** Gets a field or child node of this node. */
1732+
override AstNode getAFieldOrChild() { yaml_key_child(this, _, result) }
1733+
}
1734+
1735+
/** A class representing `yaml_keyvaluepair` nodes. */
1736+
class YamlKeyvaluepair extends @yaml_keyvaluepair, AstNode {
1737+
/** Gets the name of the primary QL class for this element. */
1738+
override string getAPrimaryQlClass() { result = "YamlKeyvaluepair" }
1739+
1740+
/** Gets the location of this element. */
1741+
override Location getLocation() { yaml_keyvaluepair_def(this, _, _, result) }
16971742

16981743
/** Gets the node corresponding to the field `key`. */
1699-
SimpleId getKey() { yaml_entry_def(this, result, _, _) }
1744+
YamlKey getKey() { yaml_keyvaluepair_def(this, result, _, _) }
17001745

17011746
/** Gets the node corresponding to the field `value`. */
1702-
YamlValue getValue() { yaml_entry_def(this, _, result, _) }
1747+
YamlValue getValue() { yaml_keyvaluepair_def(this, _, result, _) }
17031748

17041749
/** Gets a field or child node of this node. */
17051750
override AstNode getAFieldOrChild() {
1706-
yaml_entry_def(this, result, _, _) or yaml_entry_def(this, _, result, _)
1751+
yaml_keyvaluepair_def(this, result, _, _) or yaml_keyvaluepair_def(this, _, result, _)
17071752
}
17081753
}
17091754

1755+
/** A class representing `yaml_listitem` nodes. */
1756+
class YamlListitem extends @yaml_listitem, AstNode {
1757+
/** Gets the name of the primary QL class for this element. */
1758+
override string getAPrimaryQlClass() { result = "YamlListitem" }
1759+
1760+
/** Gets the location of this element. */
1761+
override Location getLocation() { yaml_listitem_def(this, _, result) }
1762+
1763+
/** Gets the child of this node. */
1764+
YamlValue getChild() { yaml_listitem_def(this, result, _) }
1765+
1766+
/** Gets a field or child node of this node. */
1767+
override AstNode getAFieldOrChild() { yaml_listitem_def(this, result, _) }
1768+
}
1769+
17101770
/** A class representing `yaml_value` tokens. */
17111771
class YamlValue extends @token_yaml_value, Token {
17121772
/** Gets the name of the primary QL class for this element. */

ql/src/ql.dbscheme

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,13 +1042,47 @@ variable_def(
10421042
int loc: @location ref
10431043
);
10441044

1045+
yaml_comment_def(
1046+
unique int id: @yaml_comment,
1047+
int child: @token_yaml_value ref,
1048+
int loc: @location ref
1049+
);
1050+
1051+
@yaml_entry_child_type = @yaml_comment | @yaml_keyvaluepair | @yaml_listitem
1052+
10451053
yaml_entry_def(
10461054
unique int id: @yaml_entry,
1047-
int key__: @token_simple_id ref,
1055+
int child: @yaml_entry_child_type ref,
1056+
int loc: @location ref
1057+
);
1058+
1059+
@yaml_key_child_type = @token_simple_id | @yaml_key
1060+
1061+
#keyset[yaml_key, index]
1062+
yaml_key_child(
1063+
int yaml_key: @yaml_key ref,
1064+
int index: int ref,
1065+
unique int child: @yaml_key_child_type ref
1066+
);
1067+
1068+
yaml_key_def(
1069+
unique int id: @yaml_key,
1070+
int loc: @location ref
1071+
);
1072+
1073+
yaml_keyvaluepair_def(
1074+
unique int id: @yaml_keyvaluepair,
1075+
int key__: @yaml_key ref,
10481076
int value: @token_yaml_value ref,
10491077
int loc: @location ref
10501078
);
10511079

1080+
yaml_listitem_def(
1081+
unique int id: @yaml_listitem,
1082+
int child: @token_yaml_value ref,
1083+
int loc: @location ref
1084+
);
1085+
10521086
tokeninfo(
10531087
unique int id: @token,
10541088
int kind: int ref,
@@ -1120,7 +1154,7 @@ case @diagnostic.severity of
11201154
;
11211155

11221156

1123-
@ast_node = @add_expr | @aggregate | @annot_arg | @annotation | @arityless_predicate_expr | @as_expr | @as_exprs | @body | @bool | @call_body | @call_or_unqual_agg_expr | @charpred | @class_member | @classless_predicate | @comp_term | @conjunction | @dataclass | @datatype | @datatype_branch | @datatype_branches | @db_annotation | @db_args_annotation | @db_branch | @db_case_decl | @db_col_type | @db_column | @db_entry | @db_repr_type | @db_table | @db_table_name | @db_union_decl | @disjunction | @expr_aggregate_body | @expr_annotation | @field | @full_aggregate_body | @higher_order_term | @if_term | @implication | @import_directive | @import_module_expr | @in_expr | @instance_of | @literal | @member_predicate | @module | @module_alias_body | @module_expr | @module_member | @module_name | @mul_expr | @negation | @order_by | @order_bys | @par_expr | @predicate_alias_body | @predicate_expr | @prefix_cast | @ql | @qual_module_expr | @qualified_expr | @qualified_rhs | @quantified | @range | @select | @set_literal | @special_call | @super_ref | @token | @type_alias_body | @type_expr | @type_union_body | @unary_expr | @unqual_agg_body | @var_decl | @var_name | @variable | @yaml_entry
1157+
@ast_node = @add_expr | @aggregate | @annot_arg | @annotation | @arityless_predicate_expr | @as_expr | @as_exprs | @body | @bool | @call_body | @call_or_unqual_agg_expr | @charpred | @class_member | @classless_predicate | @comp_term | @conjunction | @dataclass | @datatype | @datatype_branch | @datatype_branches | @db_annotation | @db_args_annotation | @db_branch | @db_case_decl | @db_col_type | @db_column | @db_entry | @db_repr_type | @db_table | @db_table_name | @db_union_decl | @disjunction | @expr_aggregate_body | @expr_annotation | @field | @full_aggregate_body | @higher_order_term | @if_term | @implication | @import_directive | @import_module_expr | @in_expr | @instance_of | @literal | @member_predicate | @module | @module_alias_body | @module_expr | @module_member | @module_name | @mul_expr | @negation | @order_by | @order_bys | @par_expr | @predicate_alias_body | @predicate_expr | @prefix_cast | @ql | @qual_module_expr | @qualified_expr | @qualified_rhs | @quantified | @range | @select | @set_literal | @special_call | @super_ref | @token | @type_alias_body | @type_expr | @type_union_body | @unary_expr | @unqual_agg_body | @var_decl | @var_name | @variable | @yaml_comment | @yaml_entry | @yaml_key | @yaml_keyvaluepair | @yaml_listitem
11241158

11251159
@ast_node_parent = @ast_node | @file
11261160

0 commit comments

Comments
 (0)