Skip to content

Commit f61565c

Browse files
committed
Python: add YAML library
1 parent 9c25c15 commit f61565c

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

python/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ dependencies:
99
codeql/regex: ${workspace}
1010
codeql/tutorial: ${workspace}
1111
codeql/util: ${workspace}
12+
codeql/yaml: ${workspace}
1213
dataExtensions:
1314
- semmle/python/frameworks/**/model.yml

python/ql/lib/semmle/python/YAML.qll

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Provides classes for working with YAML data.
3+
*
4+
* YAML documents are represented as abstract syntax trees whose nodes
5+
* are either YAML values or alias nodes referring to another YAML value.
6+
*/
7+
8+
private import codeql.yaml.Yaml as LibYaml
9+
10+
private module YamlSig implements LibYaml::InputSig {
11+
import semmle.python.Files
12+
13+
class LocatableBase extends @yaml_locatable {
14+
Location getLocation() { yaml_locations(this, result) }
15+
16+
string toString() { none() }
17+
}
18+
19+
class NodeBase extends LocatableBase, @yaml_node {
20+
NodeBase getChildNode(int i) { yaml(result, _, this, i, _, _) }
21+
22+
string getTag() { yaml(this, _, _, _, result, _) }
23+
24+
string getAnchor() { yaml_anchors(this, result) }
25+
26+
override string toString() { yaml(this, _, _, _, _, result) }
27+
}
28+
29+
class ScalarNodeBase extends NodeBase, @yaml_scalar_node {
30+
int getStyle() { yaml_scalars(this, result, _) }
31+
32+
string getValue() { yaml_scalars(this, _, result) }
33+
}
34+
35+
class CollectionNodeBase extends NodeBase, @yaml_collection_node { }
36+
37+
class MappingNodeBase extends CollectionNodeBase, @yaml_mapping_node { }
38+
39+
class SequenceNodeBase extends CollectionNodeBase, @yaml_sequence_node { }
40+
41+
class AliasNodeBase extends NodeBase, @yaml_alias_node {
42+
string getTarget() { yaml_aliases(this, result) }
43+
}
44+
45+
class ParseErrorBase extends LocatableBase, @yaml_error {
46+
string getMessage() { yaml_errors(this, result) }
47+
}
48+
}
49+
50+
import LibYaml::Make<YamlSig>

0 commit comments

Comments
 (0)