Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ruby: add an AST reference guide #11056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 7, 2022

Conversation

alexrford
Copy link
Contributor

@alexrford alexrford commented Oct 31, 2022

Adds a reference for CodeQL Ast module classes and associated Ruby syntax.

The Ruby syntax provided is not complete. I used parse.y as a reference, and the actual syntax is very complex and not really realistic to present in a table like this. What's here should hopefully be enough to give a flavour of the kinds of expressions that map onto the provided CodeQL classes.

In some cases where it seemed clearer to do so, such as the Literals section, I've resorted to providing example expressions rather than a syntax definition. It may be that this approach would be better for some other sections as well.

@alexrford alexrford marked this pull request as ready for review November 1, 2022 23:54
@alexrford alexrford added the Ruby label Nov 1, 2022
@github-actions github-actions bot removed the Ruby label Nov 2, 2022
@alexrford alexrford added the ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. label Nov 2, 2022
@lucascosti
Copy link

👋 Docs first responder here! I've added this to our review board for a writer to have a look at. 🙇‍♂️

@felicitymay
Copy link
Contributor

@alexrford - thanks for flagging this work for a writer review. Is there also a technical reviewer planned?

Copy link
Contributor

@felicitymay felicitymay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexrford - thanks for taking the time to write up this information for new query writers ✨

From a docs point of view, there isn't a great deal to say about this. I've left a few suggestions for formatting fixes and a couple of small text suggestions.

I wonder if it's worth adding a further reading section, similar to the ones in the Go and JavaScript

@alexrford
Copy link
Contributor Author

alexrford commented Nov 4, 2022

Thanks for reviewing this @felicitymay.

I wonder if it's worth adding a further reading section, similar to the ones in the Go and JavaScript

Yep, I think this is a good idea.

Is there also a technical reviewer planned?

It's had some light informal technical review on slack. One of the outcomes of that was that we should add a small section mentioning how we handle some desugaring (such as treating assignments to foo as calls to a foo= method), which I'm working on now. It probably needs a more comprehensive technical review once that's done, though.

+----------------------------+---------------------+----------------+-------------------------------+
| ``yield`` «Expr_ ``,``»* | YieldCall_ | Call_ | |
+----------------------------+---------------------+----------------+-------------------------------+
| ``&``IDENTIFIER | BlockArgument_ | Expr_ | Used as an argument to a call |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sphinx says: Inline literal start-string without end-string. . Perhaps we need a space between & and IDENTIFIER

See: https://github.com/github/semmle-code/actions/runs/3395113988/jobs/5644570096#step:18:17

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may well be right. I assumed that it would be okay because line 63 appeared to have a double-backtick followed by another symbol without a space.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully fixed now.

@alexrford
Copy link
Contributor Author

I've made some additional changes to address review comments, and added a short section about desugaring and synthesized AST nodes.

@@ -414,6 +418,32 @@ All classes in this subsection are subclasses of VariableAccess_.
| ``self`` | SelfVariableReadAccess_ | VariableReadAccess_, SelfVariableAccess_ | |
+----------------------------+------------------------------+-----------------------------------------------+------------------+

Desugaring
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect the target audience for this section to be confident of the meaning of "desugaring"? Would it be better to talk about simplifying and expanding the simplified syntax, or something along those lines?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point. Not every user will be familiar with the terminology.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True - I think we should mention the term "desugaring" as part of the text as we have a getDesugared predicate, but probably with a description of what it means. I think that "syntactic sugar" is a commonly understood term, though?

@@ -10,6 +10,7 @@ Experiment and learn how to write effective and efficient queries for CodeQL dat

basic-query-for-ruby-code
codeql-library-for-ruby
abstract-syntax-tree-classes-for-working-with-ruby-programs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a - :doc: entry below? There are some for the other items.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please. 🤦🏻‍♀️ I missed that - great catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thanks for catching that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem, i'll merge this PR and address this issue in a followup PR.

@aibaars aibaars merged commit 16c3da3 into github:codeql-cli-2.11.2 Nov 7, 2022
@alexrford alexrford deleted the ruby/ast-ref-table-docs branch November 22, 2022 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. Ruby GA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants