difftastic/vendor/tree-sitter-c-sharp/corpus/preprocessor.txt

203 lines
4.3 KiB
Plaintext

===================================
If, elif and else directives
===================================
#if WIN32
string os = "Win32";
#elif MACOS
string os = "MacOS";
#else
string os = "Unknown";
#endif
---
(compilation_unit
(if_directive (identifier))
(global_statement
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator (identifier) (equals_value_clause (string_literal))))))
(elif_directive (identifier))
(global_statement
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator (identifier) (equals_value_clause (string_literal))))))
(else_directive)
(global_statement
(local_declaration_statement
(variable_declaration
(predefined_type)
(variable_declarator (identifier) (equals_value_clause (string_literal))))))
(endif_directive))
===========================
Complex if conditions
===========================
#if !MACOS
#if WIN32==true
#if !MACOS!=false
#if A && B || C
#if (A)
#if (A || B)
#if (A && B) || C
---
(compilation_unit
(if_directive (prefix_unary_expression (identifier)))
(if_directive
(binary_expression (identifier) (boolean_literal)))
(if_directive
(binary_expression (prefix_unary_expression (identifier)) (boolean_literal)))
(if_directive
(binary_expression (binary_expression (identifier) (identifier)) (identifier)))
(if_directive (parenthesized_expression (identifier)))
(if_directive
(parenthesized_expression (binary_expression (identifier) (identifier))))
(if_directive
(binary_expression
(parenthesized_expression (binary_expression (identifier) (identifier)))
(identifier))))
===========================
Region directives
===========================
#region Here, there, everywhere
// something fast
#endregion
---
(compilation_unit
(region_directive (preproc_message))
(comment)
(endregion_directive))
===================================
Define and undefine directives
===================================
#define SOMETHING
#undef BAD
---
(compilation_unit
(define_directive (identifier))
(undef_directive (identifier)))
===================================
Warning and error directives
===================================
class Of1879 {
#warning This class is bad.
#error Okay, just stop.
}
---
(compilation_unit
(class_declaration (identifier) (declaration_list
(warning_directive (preproc_message))
(error_directive (preproc_message)))))
===================================
Line directives
===================================
class Of1879 {
void AMethod() {
#line 2001 "A Space" // Comment
#line hidden
#line default
}
}
---
(compilation_unit (class_declaration
(identifier)
(declaration_list
(method_declaration
(void_keyword)
(identifier)
(parameter_list)
(block
(line_directive (preproc_integer_literal) (preproc_string_literal)) (comment)
(line_directive)
(line_directive))))))
===================================
Spaces in directives
===================================
class Of1879 {
void AMethod() {
# line 2001 "A Space"
# line hidden
# line default
}
}
---
(compilation_unit (class_declaration
(identifier)
(declaration_list
(method_declaration
(void_keyword)
(identifier)
(parameter_list)
(block
(line_directive (preproc_integer_literal) (preproc_string_literal))
(line_directive)
(line_directive))))))
===================================
Pragmas
===================================
#pragma warning disable 660,661,nullable
---
(compilation_unit
(pragma_directive (integer_literal) (integer_literal) (identifier)))
===================================
Directives not in strings or comments
===================================
class Of1879 {
void AMethod() {
var s = @"Only a string
#if NOPE
";
/* Only a comment
#if NOPE
*/
}
}
---
(compilation_unit (class_declaration
(identifier)
(declaration_list
(method_declaration
(void_keyword)
(identifier)
(parameter_list)
(block
(local_declaration_statement
(variable_declaration (implicit_type)
(variable_declarator (identifier)
(equals_value_clause (verbatim_string_literal)))))
(comment))))))