From 0aa1abe43295cfeafaff8cde711bf1fd0dd8d05b Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Thu, 4 Jun 2026 11:37:54 +0100 Subject: [PATCH] Python: Add support for YAML comments. --- python/ql/lib/semmle/python/Yaml.qll | 6 +++++ python/ql/lib/semmlecode.python.dbscheme | 6 ++++- .../ql/lib/semmlecode.python.dbscheme.stats | 23 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/python/ql/lib/semmle/python/Yaml.qll b/python/ql/lib/semmle/python/Yaml.qll index 21a1fe02bb3..af45a97ccce 100644 --- a/python/ql/lib/semmle/python/Yaml.qll +++ b/python/ql/lib/semmle/python/Yaml.qll @@ -45,6 +45,12 @@ private module YamlSig implements LibYaml::InputSig { class ParseErrorBase extends LocatableBase, @yaml_error { string getMessage() { yaml_errors(this, result) } } + + class CommentBase extends LocatableBase, @yaml_comment { + string getText() { yaml_comments(this, result, _) } + + override string toString() { yaml_comments(this, _, result) } + } } import LibYaml::Make diff --git a/python/ql/lib/semmlecode.python.dbscheme b/python/ql/lib/semmlecode.python.dbscheme index eb5fc917c79..b7745eb2df8 100644 --- a/python/ql/lib/semmlecode.python.dbscheme +++ b/python/ql/lib/semmlecode.python.dbscheme @@ -280,13 +280,17 @@ yaml_scalars (unique int scalar: @yaml_scalar_node ref, int style: int ref, string value: string ref); +yaml_comments (unique int id: @yaml_comment, + string text: string ref, + string tostring: string ref); + yaml_errors (unique int id: @yaml_error, string message: string ref); yaml_locations(unique int locatable: @yaml_locatable ref, int location: @location_default ref); -@yaml_locatable = @yaml_node | @yaml_error; +@yaml_locatable = @yaml_node | @yaml_error | @yaml_comment; /*- Python dbscheme -*/ diff --git a/python/ql/lib/semmlecode.python.dbscheme.stats b/python/ql/lib/semmlecode.python.dbscheme.stats index 2805763a54f..5c4e3d182e1 100644 --- a/python/ql/lib/semmlecode.python.dbscheme.stats +++ b/python/ql/lib/semmlecode.python.dbscheme.stats @@ -641,6 +641,10 @@ @yaml_error 1 + +@yaml_comment +1000 + externalDefects @@ -18657,5 +18661,24 @@ + +yaml_comments +1000 + + +id +1000 + + +text +1000 + + +tostring +1000 + + + +