Tutorials

Create AST Rules

BackNext

1. What is an AST rule

An AST rule is a set of rules that applies to specific nodes of an AST (Abstract Syntax Tree). When the code is analyzed, Codiga generates the AST of your program and applies your rule to all the nodes of a specific type. An AST is a tree data structure that best represents the syntactic structure of the source code. They are a fundamental part of the way a compiler works. When a compiler transforms code, it follows these steps:

your code
123456
import loggingimport requests def my_function():  foo = 1  foobar()
Lexical Analysis

The lexical analysis breaks down the source code into tokens, it is also called tokenization.

📦
Tokens
Syntax Analysis

It converts the tokens into a tree representing the current structure of the code.

Tree structure of your code
Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.