Skip to content

Commit 0725b10

Browse files
committed
Add basic YEAST dependency and rule
1 parent 6eeafb9 commit 0725b10

6 files changed

Lines changed: 24 additions & 3 deletions

File tree

Cargo.lock

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

unified/extractor/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ codeql_rust_binary(
1515
normal = True,
1616
) + [
1717
"//shared/tree-sitter-extractor",
18+
"//shared/yeast",
1819
],
1920
)

unified/extractor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ lazy_static = "1.5.0"
2020
serde_json = "1.0.145"
2121

2222
codeql-extractor = { path = "../../shared/tree-sitter-extractor" }
23+
yeast = { path = "../../shared/yeast" }

unified/extractor/src/extractor.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::PathBuf;
33

44
use codeql_extractor::extractor::simple;
55
use codeql_extractor::trap;
6+
use yeast::{rule, DesugaringConfig};
67

78
#[derive(Args)]
89
pub struct Options {
@@ -19,9 +20,21 @@ pub struct Options {
1920
file_list: PathBuf,
2021
}
2122

23+
fn swift_desugaring_rules() -> Vec<yeast::Rule> {
24+
vec![
25+
rule!(
26+
(additive_expression)
27+
=>
28+
(simple_identifier "blah")
29+
),
30+
]
31+
}
32+
2233
pub fn run(options: Options) -> std::io::Result<()> {
2334
codeql_extractor::extractor::set_tracing_level("ql");
2435

36+
let swift_desugar = DesugaringConfig::new(swift_desugaring_rules());
37+
2538
let extractor = simple::Extractor {
2639
prefix: "unified".to_string(),
2740
languages: vec![
@@ -30,7 +43,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
3043
ts_language: tree_sitter_swift::LANGUAGE.into(),
3144
node_types: tree_sitter_swift::NODE_TYPES,
3245
file_globs: vec!["*.swift".into(), "*.swiftinterface".into()],
33-
desugar: None,
46+
desugar: Some(swift_desugar),
3447
},
3548
],
3649
trap_dir: options.output_dir,

unified/ql/test/library-tests/BasicTest/test.expected

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ identifier
7575
| test.swift:73:23:73:29 | Element | Element |
7676
| test.swift:74:10:74:17 | isSorted | isSorted |
7777
| test.swift:75:13:75:13 | i | i |
78-
| test.swift:75:23:75:27 | count | count |
78+
| test.swift:75:23:75:31 | blah | blah |
7979
| test.swift:76:21:76:21 | i | i |
80-
| test.swift:76:31:76:31 | i | i |
80+
| test.swift:76:31:76:35 | blah | blah |
8181
| test.swift:85:6:85:12 | combine | combine |
8282
| test.swift:85:17:85:17 | _ | _ |
8383
| test.swift:85:19:85:24 | values | values |
@@ -98,3 +98,4 @@ func
9898
| test.swift:62:5:69:5 | FunctionDeclaration |
9999
| test.swift:74:5:81:5 | FunctionDeclaration |
100100
| test.swift:85:1:88:1 | FunctionDeclaration |
101+
add

unified/ql/test/library-tests/BasicTest/test.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ import codeql.unified.Ast
33
query predicate identifier(Swift::SimpleIdentifier node, string name) { name = node.getValue() }
44

55
query predicate func(Swift::FunctionDeclaration node) { any() }
6+
7+
query predicate add(Swift::AdditiveExpression node, Swift::AstNode lhs, Swift::AstNode rhs) {
8+
lhs = node.getLhs(0) and rhs = node.getRhs(0)
9+
}

0 commit comments

Comments
 (0)