Skip to content

Commit 0aa1abe

Browse files
committed
Python: Add support for YAML comments.
1 parent b6521e7 commit 0aa1abe

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

python/ql/lib/semmle/python/Yaml.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ private module YamlSig implements LibYaml::InputSig {
4545
class ParseErrorBase extends LocatableBase, @yaml_error {
4646
string getMessage() { yaml_errors(this, result) }
4747
}
48+
49+
class CommentBase extends LocatableBase, @yaml_comment {
50+
string getText() { yaml_comments(this, result, _) }
51+
52+
override string toString() { yaml_comments(this, _, result) }
53+
}
4854
}
4955

5056
import LibYaml::Make<YamlSig>

python/ql/lib/semmlecode.python.dbscheme

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,17 @@ yaml_scalars (unique int scalar: @yaml_scalar_node ref,
280280
int style: int ref,
281281
string value: string ref);
282282

283+
yaml_comments (unique int id: @yaml_comment,
284+
string text: string ref,
285+
string tostring: string ref);
286+
283287
yaml_errors (unique int id: @yaml_error,
284288
string message: string ref);
285289

286290
yaml_locations(unique int locatable: @yaml_locatable ref,
287291
int location: @location_default ref);
288292

289-
@yaml_locatable = @yaml_node | @yaml_error;
293+
@yaml_locatable = @yaml_node | @yaml_error | @yaml_comment;
290294

291295
/*- Python dbscheme -*/
292296

python/ql/lib/semmlecode.python.dbscheme.stats

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@
641641
<k>@yaml_error</k>
642642
<v>1</v>
643643
</e>
644+
<e>
645+
<k>@yaml_comment</k>
646+
<v>1000</v>
647+
</e>
644648
</typesizes>
645649
<stats><relation>
646650
<name>externalDefects</name>
@@ -18657,5 +18661,24 @@
1865718661
</dep>
1865818662
</dependencies>
1865918663
</relation>
18664+
<relation>
18665+
<name>yaml_comments</name>
18666+
<cardinality>1000</cardinality>
18667+
<columnsizes>
18668+
<e>
18669+
<k>id</k>
18670+
<v>1000</v>
18671+
</e>
18672+
<e>
18673+
<k>text</k>
18674+
<v>1000</v>
18675+
</e>
18676+
<e>
18677+
<k>tostring</k>
18678+
<v>1000</v>
18679+
</e>
18680+
</columnsizes>
18681+
<dependencies/>
18682+
</relation>
1866018683
</stats>
1866118684
</dbstats>

0 commit comments

Comments
 (0)