Skip to content

Commit 6a0a81b

Browse files
committed
Ruby: expand explanation of desugaring
1 parent 63dc044 commit 6a0a81b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

docs/codeql/codeql-language-guides/abstract-syntax-tree-classes-for-working-with-ruby-programs.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,13 @@ All classes in this subsection are subclasses of VariableAccess_.
421421
Desugaring
422422
~~~~~~~~~~
423423

424-
Certain Ruby language features are implemented using syntactic sugar. For example, supposing that ``x`` is an object with an attribute ``foo``, the assignment::
424+
Certain Ruby language features are shorthands for a common operations that could also be expressed in an alternate, more verbose, forms.
425+
Such language features are typically referred to as "syntactic sugar", and make it easier for programmers to write and read code. This is
426+
great for programmers. Source code analyzers on the other hand, this lead to additional work as they need to understand the short
427+
hand notation as well as the long form. To make analysis easier, CodeQL automatically "desugars" Ruby code, effectively rewriting
428+
rich syntactic constructs into equivalent code that uses simpler syntactic contructs.
429+
430+
For example, supposing that ``x`` is an object with an attribute ``foo``, the assignment::
425431

426432
x.foo = y
427433

@@ -432,7 +438,7 @@ is desugared to code similar to::
432438

433439
In other words, there is effectively a call to the SetterMethodCall_ ``foo=`` on ``x`` with argument ``__synth_0 = y``, followed by a read of the ``__synth_0`` variable.
434440

435-
In CodeQL, this is implemented by syntheisizing AstNode_ instances corresponding to this desugared version of the code.
441+
In CodeQL, this is implemented by synthesizing AstNode_ instances corresponding to this desugared version of the code.
436442

437443
Note that both the original AssignExpr_ and the desugared SetterMethodCall_ versions are both available to CodeQL queries, and it is usually not necessary to be aware of any desugaring that may take place. However, if a codebase explicitly uses ``x.foo=(y)`` SetterMethodCall_ syntax, then this will not be found by a query for AssignExpr_ instances.
438444

0 commit comments

Comments
 (0)