================================================================================ 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 type: (predefined_type) (variable_declarator name: (identifier) (equals_value_clause (string_literal (string_literal_fragment))))))) (elif_directive (identifier)) (global_statement (local_declaration_statement (variable_declaration type: (predefined_type) (variable_declarator name: (identifier) (equals_value_clause (string_literal (string_literal_fragment))))))) (else_directive) (global_statement (local_declaration_statement (variable_declaration type: (predefined_type) (variable_declarator name: (identifier) (equals_value_clause (string_literal (string_literal_fragment))))))) (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 argument: (identifier))) (if_directive (binary_expression left: (identifier) right: (boolean_literal))) (if_directive (binary_expression left: (prefix_unary_expression argument: (identifier)) right: (boolean_literal))) (if_directive (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) (if_directive (parenthesized_expression (identifier))) (if_directive (parenthesized_expression (binary_expression left: (identifier) right: (identifier)))) (if_directive (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (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 name: (identifier) body: (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 #line (1, 1) - (1, 3) 1 "a.cs" #line (2, 1) - (2, 3) "a.cs" } } -------------------------------------------------------------------------------- (compilation_unit (class_declaration name: (identifier) body: (declaration_list (method_declaration type: (predefined_type) name: (identifier) parameters: (parameter_list) body: (block (line_directive (preproc_integer_literal) (preproc_string_literal)) (comment) (line_directive) (line_directive) (line_directive (preproc_integer_literal) (preproc_integer_literal) (preproc_integer_literal) (preproc_integer_literal) (preproc_integer_literal) (preproc_string_literal)) (line_directive (preproc_integer_literal) (preproc_integer_literal) (preproc_integer_literal) (preproc_integer_literal) (preproc_string_literal))))))) ================================================================================ Spaces in directives ================================================================================ class Of1879 { void AMethod() { # line 2001 "A Space" # line hidden # line default } } -------------------------------------------------------------------------------- (compilation_unit (class_declaration name: (identifier) body: (declaration_list (method_declaration type: (predefined_type) name: (identifier) parameters: (parameter_list) body: (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 name: (identifier) body: (declaration_list (method_declaration type: (predefined_type) name: (identifier) parameters: (parameter_list) body: (block (local_declaration_statement (variable_declaration type: (implicit_type) (variable_declarator name: (identifier) (equals_value_clause (verbatim_string_literal))))) (comment)))))) ================================================================================ Reference (r) directive ================================================================================ #r "Microsoft.WindowsAzure.Storage" -------------------------------------------------------------------------------- (compilation_unit (reference_directive (preproc_string_literal))) ================================================================================ Load directive ================================================================================ #load "mylogger.csx" -------------------------------------------------------------------------------- (compilation_unit (load_directive (preproc_string_literal))) ================================================================================ Shebang directive ================================================================================ #!/usr/bin/env scriptcs -------------------------------------------------------------------------------- (compilation_unit (shebang_directive))