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

Skip to content

Commit c598dc6

Browse files
committed
Initial work on user-facing AST library
1 parent 2082171 commit c598dc6

29 files changed

Lines changed: 2184 additions & 1564 deletions

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ jobs:
4646
- uses: actions/upload-artifact@v2
4747
if: ${{ matrix.os == 'ubuntu-latest' }}
4848
with:
49-
name: ruby_ast.qll
50-
path: ql/src/codeql_ruby/ast.qll
49+
name: Generated.qll
50+
path: ql/src/codeql_ruby/Generated.qll
5151
- uses: actions/upload-artifact@v2
5252
with:
5353
name: extractor-${{ matrix.os }}

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ cargo build --release
1212

1313
## Generating the database schema and QL library
1414

15-
The generated `ql/src/ruby.dbscheme` and `ql/src/codeql_ruby/ast.qll` files are included in the repository, but they can be re-generated as follows:
15+
The generated `ql/src/ruby.dbscheme` and `ql/src/codeql_ruby/Generated.qll` files are included in the repository, but they can be re-generated as follows:
1616

1717
```bash
1818
# Run the generator
1919
cargo run --release -p ruby-generator
2020
# Then auto-format the QL library
21-
codeql query format -i ql/src/codeql_ruby/ast.qll
21+
codeql query format -i ql/src/codeql_ruby/Generated.qll
2222
```
2323

2424
## Building a CodeQL database for a Ruby program

create-extractor-pack.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cargo build --release
22

33
cargo run --release -p ruby-generator
4-
codeql query format -i ql\src\codeql_ruby\ast.qll
4+
codeql query format -i ql\src\codeql_ruby\Generated.qll
55

66
rm -Recurse -Force extractor-pack
77
mkdir extractor-pack | Out-Null

create-extractor-pack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fi
1313
cargo build --release
1414

1515
cargo run --release -p ruby-generator
16-
codeql query format -i ql/src/codeql_ruby/ast.qll
16+
codeql query format -i ql/src/codeql_ruby/Generated.qll
1717

1818
rm -rf extractor-pack
1919
mkdir -p extractor-pack

extractor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2018"
1010
flate2 = "1.0"
1111
node-types = { path = "../node-types" }
1212
tree-sitter = "0.17"
13-
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "93632008c63e0577413bbedf120fb92a96397785" }
13+
tree-sitter-ruby = { git = "https://github.com/nickrolfe/tree-sitter-ruby.git", branch = "refinements" }
1414
clap = "2.33"
1515
tracing = "0.1"
1616
tracing-subscriber = { version = "0.2", features = ["env-filter"] }

generator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ edition = "2018"
1010
node-types = { path = "../node-types" }
1111
tracing = "0.1"
1212
tracing-subscriber = { version = "0.2", features = ["env-filter"] }
13-
tree-sitter-ruby = { git = "https://github.com/tree-sitter/tree-sitter-ruby.git", rev = "93632008c63e0577413bbedf120fb92a96397785" }
13+
tree-sitter-ruby = { git = "https://github.com/nickrolfe/tree-sitter-ruby.git", branch = "refinements" }

generator/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ fn main() {
574574
name: "Ruby".to_owned(),
575575
node_types: tree_sitter_ruby::NODE_TYPES,
576576
dbscheme_path: PathBuf::from("ql/src/ruby.dbscheme"),
577-
ql_library_path: PathBuf::from("ql/src/codeql_ruby/ast.qll"),
577+
ql_library_path: PathBuf::from("ql/src/codeql_ruby/Generated.qll"),
578578
};
579579
match node_types::read_node_types_str(&ruby.node_types) {
580580
Err(e) => {

generator/src/ql.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,12 @@ pub fn write<'a>(
214214
" * Automatically generated from the tree-sitter grammar; do not edit\n"
215215
)?;
216216
write!(file, " */\n\n")?;
217+
write!(file, "module Generated {{\n")?;
217218

218219
for element in elements {
219220
write!(file, "{}\n\n", &element)?;
220221
}
221222

223+
write!(file, "}}")?;
222224
Ok(())
223225
}

ql/src/codeql_ruby/AST.qll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import codeql_ruby.Method
2+
import codeql_ruby.Parameter
3+
private import codeql_ruby.Generated
4+
5+
class Location = Generated::Location;
6+
7+
/**
8+
* A node in the abstract syntax tree. This class is the base class for all Ruby
9+
* program elements.
10+
*/
11+
class AstNode extends @ast_node {
12+
/**
13+
* Gets the name of a primary CodeQL class to which this node belongs.
14+
*
15+
* This predicate always has a result. If no primary class can be
16+
* determined, the result is `"???"`. If multiple primary classes match,
17+
* this predicate can have multiple results.
18+
*/
19+
string describeQlClass() { result = "???" }
20+
21+
/** Gets a textual representation of this node. */
22+
string toString() { result = "AstNode" }
23+
24+
/** Gets the location if this node. */
25+
Location getLocation() { result = this.(Generated::AstNode).getLocation() }
26+
}
27+
28+
/**
29+
* Models program elements for destructured patterns.
30+
*/
31+
abstract class Pattern extends AstNode {
32+
/** Gets the number of elements in this pattern. */
33+
abstract int getNumberOfElements();
34+
35+
/** Gets the nth element in this pattern. */
36+
abstract AstNode getElement(int n);
37+
38+
/** Gets an element in this pattern. */
39+
AstNode getAnElement() { result = this.getElement(_) }
40+
}

0 commit comments

Comments
 (0)