Abstract Syntax Tree¶
Abstract Syntax Tree elements which are returned by
parse_raw() and
parse_tree().
- class cmake_parser.ast.AstFileNode(span, line, column)¶
Bases:
AstNodeBase class for all AST nodes with associated file location
- Parameters:
line (
int) – the line number where the corresponding code begins. Note that the code can span multiple lines.column (
int) – the column where the corresponding code begins.
- class cmake_parser.ast.AstNode(span)¶
Bases:
objectBase class for all Abstract Syntax Tree elements
- Parameters:
span (
slice) – the code location in the parsed string.
- class cmake_parser.ast.Block(span, line, column, args, body)¶
Bases:
BuiltinBlockScoped block.
This node represents a
block()/endblock()block.
- class cmake_parser.ast.Break(span, line, column)¶
Bases:
BuiltinNoArgsLoop exit.
This node represents the
break()command.
- class cmake_parser.ast.Builtin(span, line, column, args)¶
Bases:
AstFileNodeBase class for AST nodes which represent CMake built-in instructions with parseable arguments.
- Parameters:
args (
List[Token]) – the list of arguments.
Note
As variable expansion can split tokens into multiple arguments or remove them from the argument list altogether, there is no 1:1 relation between tokens and arguments.
- class cmake_parser.ast.BuiltinBlock(span, line, column, args, body)¶
Bases:
BuiltinBase class for AST nodes which represent a block of CMake commands
- Parameters:
body (
List[AstNode]) – the list of commands which form the block.
- class cmake_parser.ast.BuiltinNoArgs(span, line, column)¶
Bases:
AstFileNodeBase class for AST nodes which represent CMake built-in instructions which can never have arguments
- class cmake_parser.ast.Command(span, line, column, identifier, args)¶
Bases:
AstFileNodeGeneric representation of a single CMake instruction.
CMake code consists of a serious of command invocations with a (possibly empty) list of arguments in parentheses.
CommandandCommentare the two possible outputs ofparse_raw().- Parameters:
identifier (
str) – the function or instruction name to be invoked.args (
List[Token]) – the tokens which form the argumen list.
Note
As variable expansion can split tokens into multiple arguments or remove them from the argument list altogether, there is no 1:1 relation between tokens and arguments.
- class cmake_parser.ast.Comment(span, line, column, comment)¶
Bases:
AstFileNodeCMake Comment.
This is the only AST node which does not represent executable code. Both
parse_raw()andparse_tree()can be instructed to omit comments from their output.- Parameters:
comment (
str) – The comment string without leading#or enclosing brackets.
- class cmake_parser.ast.Continue(span, line, column)¶
Bases:
BuiltinNoArgsLoop continuation.
This node represents the
continue()command.
- class cmake_parser.ast.ForEach(span, line, column, args, body)¶
Bases:
BuiltinBlockForEach Loop.
This node represents a
foreach()/endforeach()block.
- class cmake_parser.ast.Function(span, line, column, args, body)¶
Bases:
BuiltinBlockMacro definition.
This node represents a
function()/endfunction()block.
- class cmake_parser.ast.If(span, line, column, args, if_true, if_false)¶
Bases:
BuiltinConditional block.
This node represents a
if()/else()/endif()block.elseif()statements are converted into a singleIfcommand inif_false.
- class cmake_parser.ast.Include(span, line, column, args)¶
Bases:
BuiltinInclude other CMake file.
This node represents the
include()command.
- class cmake_parser.ast.Macro(span, line, column, args, body)¶
Bases:
BuiltinBlockMacro definition.
This node represents a
macro()/endmacro()block.
- class cmake_parser.ast.Math(span, line, column, args)¶
Bases:
BuiltinMath expression.
This node represents the
math()command.
- class cmake_parser.ast.Option(span, line, column, args)¶
Bases:
BuiltinDeclare CMake option.
This node represents the
option()command.
- class cmake_parser.ast.Return(span, line, column, args)¶
Bases:
BuiltinReturn from function or module.
This node represents the
return()command.
- class cmake_parser.ast.Set(span, line, column, args)¶
Bases:
BuiltinSet variable.
This node represents the
set()command.
- class cmake_parser.ast.Unset(span, line, column, args)¶
Bases:
BuiltinUnset variable.
This node represents the
unset()command.
- class cmake_parser.ast.While(span, line, column, args, body)¶
Bases:
BuiltinBlockWhile Loop.
This node represents a
while()/endwhile()block.