1 /++ Programming concepts that capture semantic that is common among different 2 programming language, both imperative, functional and declarative. 3 4 The class hierarchy together class fields, member functions and UDAs encode 5 the semantics of the above mentioned concepts. +/ 6 module nxt.agnostics; 7 8 @safe pure nothrow: 9 10 /++ Language-Agnostic Syntax Tree Node Type Code. 11 A UDA ´@isA_$NODETYPE´ => inherit `$NODETYPE`. 12 Expresses inheritance via UDAs, for instance: 13 `@isA_token comment` 14 means that `comment` is a kind of `token`. 15 +/ 16 enum NodeTypeCode : ubyte { 17 any, /++ Any kind of node. +/ 18 token, /++ Token|Terminal node. (typically un-named in tree-sitter terminology). +/ 19 @isA_token comment, /++ Any kind of comment. +/ 20 @isA_comment comment_multiLine, /++ Multi-Line Comment. +/ 21 @isA_comment comment_endOfLine, /++ End-Of-Line Comment. +/ 22 @isA_node expr, /++ Expression. +/ 23 @isA_node expr_ident_rvalue, /++ Identifier Expression (r-value). +/ 24 @isA_node expr_ident_lvalue, /++ Identifier Expression (l-value). +/ 25 @isA_expr expr_unary, /++ Unary Expression. +/ 26 @isA_expr_unary expr_unary_cast, /++ Cast Expression. +/ 27 @isA_expr_unary_arith expr_unary_arith_negation, /++ Arithmetic negation. +/ 28 @isA_expr_unary_arith expr_unary_arith_plus, /++ Arithmetic plus. +/ 29 @isA_expr expr_binary, /++ Binary Expression. +/ 30 @isA_expr_binary_arith expr_binary_arith_addition, /++ Addition. +/ 31 @isA_expr_binary_arith expr_binary_arith_multiplication, /++ Multiplication. +/ 32 @isA_expr_binary_arith expr_binary_arith_division, /++ Division. +/ 33 @isA_expr_binary_arith expr_binary_arith_exponentation, /++ Exponentation|Power. +/ 34 @isA_expr expr_ternary, /++ Ternary Expression. +/ 35 @isA_expr expr_assign, /++ Assign Expression. +/ 36 @isA_expr expr_functionCall, /++ Function Call Expression. +/ 37 @isA_token litr, /++ Literal (Constant). +/ 38 @isA_litr litr_string, /++ String Literal. +/ 39 @isA_litr litr_string_standard, /++ Standard-String Literal. +/ 40 @isA_litr litr_string_raw, /++ Raw-String Literal. +/ 41 @isA_litr litr_string_quoted, /++ Quoted-String Literal (in dlang.org). +/ 42 @isA_litr litr_string_standard_interpolating, /++ Interpolating Standard-String Literal. +/ 43 @isA_litr litr_string_raw_interpolating, /++ Interpolating Raw-String Literal. +/ 44 @isA_litr litr_string_quoted_interpolating, /++ Interpolating Quoted-String Literal (in dlang.org). +/ 45 @isA_litr litr_scalar, /++ Scalar Literal. +/ 46 @isA_litr_scalar litr_scalar_character, /++ Character Literal. +/ 47 @isA_litr_scalar litr_numeric, /++ Numeric Literal. +/ 48 @isA_litr_numeric litr_boolean, /++ Boolean Literal. +/ 49 @isA_litr_numeric litr_numeric_integer, /++ Integer Numeric Literal. +/ 50 @isA_litr_numeric_integer litr_numeric_integer_signed, /++ Signed Integer Numeric Literal. +/ 51 @isA_litr_numeric_integer litr_numeric_integer_unsigned, /++ Signed Integer Numeric Literal. +/ 52 @isA_litr_numeric litr_numeric_floatingPoint, /++ Floating-Point|Real|Decimal Numeric Literal. +/ 53 @isA_token symbolReference, /++ Symbol reference. +/ 54 @isA_node decl, /++ Declaration. +/ 55 @isA_decl decl_type, /++ Type Declaration. +/ 56 @isA_decl_type decl_module, /++ Module Declaration. +/ 57 @isA_decl_type decl_package, /++ Package Declaration. +/ 58 @isA_decl_type decl_namespace, /++ Namespace Declaration. +/ 59 @isA_decl_type decl_type_label, /++ Label Declaration. +/ 60 @isA_decl_type decl_type_function, /++ Function Type Declaration. +/ 61 @isA_decl_type decl_type_class, /++ Class Type Declaration. +/ 62 @isA_decl_type decl_type_interface, /++ Interface Type Declaration. +/ 63 @isA_decl_type decl_type_enumeration, /++ Enumeration Type Declaration. +/ 64 @isA_decl_type decl_type_union, /++ Union Type Declaration. +/ 65 @isA_decl_type decl_type_struct, /++ Struct Type Declaration. +/ 66 @isA_decl decl_constant_enumerator, /++ Enumerator Constant Declaration. +/ 67 @isA_type type_scalar, 68 @isA_type_scalar type_scalar_numeric, /++ Numeric Scalar Type. +/ 69 @isA_type type_vector, /++ SIMD fixed-length vector type of scalar elements. +/ 70 @isA_type_vector type_vector_integer, /++ SIMD fixed-length vector type of scalar elements. +/ 71 @isA_type_vector type_vector_floatingPoint, /++ SIMD fixed-length vector type of scalar elements. +/ 72 @isA_type_scalar type_scalar_arith, /++ Arithmetic Type. +/ 73 @isA_type_scalar type_scalar_character, /++ Character Type. +/ 74 @isA_type type_string, /++ String Type. +/ 75 @isA_type type_aggregate, /++ Aggregate Type. +/ 76 @isA_type_aggregate type_value_aggregate, 77 @isA_type_value_aggregate type_struct, /++ Struct Type having value semantics. +/ 78 @isA_type_aggregate type_anonymous_struct, /++ Anonymous Struct Type. +/ 79 @isA_type_aggregate type_aggregate_tuple = type_anonymous_struct, /++ Tuple Type. +/ 80 @isA_type_aggregate type_aggregate_union, /++ Union type. +/ 81 @isA_type_aggregate type_aggregate_class, /++ Class type. +/ 82 @isA_type type_enumeration, /++ Enumeration Type. +/ 83 @isA_type type_array, /++ Array type. +/ 84 @isA_type type_array_slice, /++ Array slice type. +/ 85 @isA_type type_machine_word, /++ Type of size machine word. +/ 86 @isA_machinewordtype type_addr, /++ Address type. +/ 87 @isA_machinewordtype type_size, /++ Size type. +/ 88 @isA_type_addr type_ptr, /++ Pointer type. +/ 89 @isA_type_addr type_ref, /++ Reference type. +/ 90 @isA_type functionType, /++ Function type. +/ 91 @isA_node defi, /++ Definition. +/ 92 @isA_defi defi_type, /++ Type Definition. +/ 93 @isA_defi_type defi_type_module, /++ Module Definition. +/ 94 @isA_defi_type defi_type_package, /++ Package Definition. +/ 95 @isA_defi_type defi_type_namespace, /++ Namespace Definition. +/ 96 @isA_defi_type defi_type_label, /++ Label definition. +/ 97 @isA_defi_type defi_type_function, /++ Function definition. +/ 98 @isA_defi_type defi_type_class, /++ Class definition. +/ 99 @isA_defi_type defi_type_interface, /++ Interface definition. +/ 100 @isA_defi_type defi_type_enumeration, /++ Enumeration definition. +/ 101 @isA_defi_type defi_type_union, /++ Union definition. +/ 102 @isA_defi_type defi_type_struct, /++ Struct definition. +/ 103 @isA_defi_type defi_type_enumerator, /++ Enumerator definition. +/ 104 @isA_defi defi_variable, /++ Variable definition. +/ 105 @isA_defi_variable defi_variable_parameter, /++ Function parameter (local variable) definition. +/ 106 @isA_node directive, /++ Directive. +/ 107 @isA_directive directive_pragma, /++ Pragma directive. +/ 108 @isA_node inst, /++ Instance. +/ 109 @isA_inst inst_variable, /++ Variable instance. +/ 110 @isA_inst inst_function, /++ Function instance. +/ 111 @isA_inst inst_class, /++ Class instance. +/ 112 @isA_inst inst_interface, /++ Interface instance. +/ 113 @isA_inst inst_enumeration, /++ Enumeration instance. +/ 114 @isA_inst inst_union, /++ Union instance. +/ 115 @isA_inst inst_struct, /++ Struct instance. +/ 116 @isA_node stmt, /++ Statement. +/ 117 @isA_stmt stmt_assignment, /++ Assignment Statement. +/ 118 @isA_stmt_assignment stmt_assignment_add, 119 @isA_stmt_assignment stmt_assignment_sub, 120 @isA_stmt_assignment stmt_assignment_mul, 121 @isA_stmt_assignment stmt_assignment_div, 122 @isA_stmt_assignment stmt_assignment_pow, 123 @isA_stmt_assignment stmt_assignment_shl, 124 @isA_stmt_assignment stmt_assignment_shr, 125 @isA_stmt_assignment stmt_assignment_rol, 126 @isA_stmt_assignment stmt_assignment_ror, 127 @isA_stmt_assignment stmt_assignment_cat, 128 @isA_stmt stmt_cflow, /++ Control-Flow Statement. +/ 129 @isA_stmt_cflow stmt_if, /++ If statement. +/ 130 @isA_stmt_cflow stmt_switch, /++ Switch statement. +/ 131 @isA_stmt_cflow stmt_for, /++ For statement. +/ 132 @isA_stmt_cflow stmt_while, /++ While statement. +/ 133 @isA_stmt_cflow stmt_doWhile, /++ Do-while statement. +/ 134 @isA_stmt_cflow stmt_break, /++ Break statement. +/ 135 @isA_stmt_cflow stmt_continue, /++ Continue statement. +/ 136 @isA_stmt_cflow stmt_return, /++ Return statement. +/ 137 @isA_stmt_cflow stmt_goto, /++ Goto statement. +/ 138 @isA_stmt_cflow stmt_block_try, /++ Try block statement. +/ 139 @isA_stmt_cflow stmt_block_catch, /++ Catch block statement. +/ 140 @isA_stmt_cflow stmt_block_finally, /++ Finally block statement. +/ 141 @isA_stmt stmt_throw, /++ Throw statement. +/ 142 @isA_stmt stmt_import, /++ Import statement. +/ 143 @isA_stmt_import stmt_import_module, /++ Import stmt of public module(s). +/ 144 @isA_stmt_import_module stmt_import_module_public, /++ Import stmt of public module(s). +/ 145 @isA_stmt_import_module stmt_import_module_private, /++ Import stmt of private module(s) (default). +/ 146 @isA_stmt_import_module stmt_import_symbol, /++ Symbol import statement. +/ 147 @isA_stmt_import_module stmt_import_symbol_public, /++ Import stmt of public symbol(s). +/ 148 @isA_stmt_import_module stmt_import_symbol_private, /++ Import stmt of private symbol(s). +/ 149 @isA_stmt stmt_namespace_using, /++ Namespace using. (C++). +/ 150 @isA_node modi_access, /++ Access modifier. +/ 151 @isA_modi_access modi_access_public, /++ Unrestricted access. +/ 152 @isA_modi_access modi_access_protected, /++ Access restricted to class and sub-classes. (C++'s `protected`). +/ 153 @isA_modi_access modi_access_package, /++ Access restricted to current package. (D's `package`). +/ 154 @isA_modi_access modi_access_private_aggregate, /++ Aggregate-scope private qualifier (C++'s `private`). +/ 155 @isA_modi_access modi_access_private_module, /++ Module-scope private qualifier (D's `private`). +/ 156 @isA_modi_access modi_access_mutable, /++ Mutable qualifier. +/ 157 @isA_modi_access modi_access_constant, /++ Constant qualifier. +/ 158 @isA_modi_access modi_access_immutable, /++ Immutable qualifier. +/ 159 @isA_modi_access modi_access_unique, /++ Unique-reference qualifier. +/ 160 @isA_modi_access_unique modi_access_owned, /++ Unique-and-owning-reference qualifier. See Mojo's `owned`. +/ 161 @isA_modi_access modi_access_scope, /++ Scope qualifier. +/ 162 @isA_node annotation, 163 @isA_node attr, 164 @isA_attr attr_inline, /++ Attribute inline. +/ 165 @isA_node decorator, 166 @isA_node language_specific, /++ Such C Preprocessor (CPP) directives. +/ 167 } 168 169 /+ `NodeTypeCode` Predicates. +/ 170 171 enum isA_token; 172 enum isA_comment; 173 enum isA_litr; 174 enum isA_litr_scalar; 175 enum isA_litr_numeric; 176 enum isA_litr_numeric_integer; 177 enum isA_type; 178 enum isA_type_aggregate; 179 enum isA_type_value_aggregate; 180 enum isA_type_scalar; 181 enum isA_type_vector; 182 enum isA_machinewordtype; 183 enum isA_type_addr; 184 enum isA_node; 185 enum isA_expr; 186 enum isA_expr_unary; 187 enum isA_expr_unary_arith; 188 enum isA_expr_binary; 189 enum isA_expr_binary_arith; 190 enum isA_expr_ternary; 191 enum isA_decl; 192 enum isA_decl_type; 193 enum isA_defi; 194 enum isA_defi_type; 195 enum isA_defi_variable; 196 enum isA_directive; 197 enum isA_inst; 198 enum isA_stmt; 199 enum isA_stmt_assignment; 200 enum isA_stmt_import; 201 enum isA_stmt_import_module; 202 enum isA_stmt_cflow; 203 enum isA_modi_access; 204 enum isA_modi_access_unique; 205 enum isA_attr; 206 207 version (none): // unused 208 209 class Point {} 210 class Node {} 211 class Token : Node { 212 @safe pure nothrow /+@nogc+/: 213 @property Point start() const { return new typeof(return)(); } 214 @property Point end() const { return new typeof(return)(); } 215 } 216 class Comment : Token {} 217 class EndOfLineComment : Token {} 218 class MultiLineComment : Token {} 219 class Literal : Token {} 220 class StringLiteraleral : Literal {} 221 class CharacterLiteraleral : Literal {} 222 class NumericLiteraleral : Literal {} 223 class IntegerLiteraleral : Literal {} 224 class FloatingPointLiteraleral : Literal {} 225 class Symbol : Token {} 226 class SymbolReference : Token {} 227 class Tree : Node {} 228 class Declaration : Tree { 229 @safe pure nothrow @nogc: 230 Node[] ctParams; ///< Compile-time parameters. 231 @property bool isTemplate() const => ctParams.length != 0; 232 } 233 class Type : Declaration {} 234 class ScalarType : Type {} 235 class ArithmeticType : ScalarType {} 236 class CharacterType : ScalarType {} 237 class StringType : Type {} 238 class AggregateType : Type {} 239 class ValueAggregateType : AggregateType {} 240 class StructType : ValueAggregateType {} 241 class AnonymousStructType : AggregateType {} 242 alias TupleType = AnonymousStructType; 243 class UnionType : AggregateType {} 244 class ClassType : AggregateType {} 245 class EnumerationType : Type {} 246 class ArrayType : Type {} 247 class MachineWordType : Type {} 248 class AddressType : MachineWordType {} 249 class SizeType : MachineWordType {} 250 class PointerType : AddressType {} // pointer 251 class ReferenceType : AddressType {} // D class 252 class FunctionType : Type {} 253 class Definition : Node {} 254 class LabelDefinition : Definition {} 255 class FunctionDefinition : Definition {} 256 class ClassDefinition : Definition {} 257 class InterfaceDefinition : Definition {} 258 class EnumDefinition : Definition {} 259 class UnionDefinition : Definition {} 260 class StructDefinition : Definition {} 261 class Instance : Node {} 262 class VariableInstance : Instance {} 263 class FunctionInstance : Instance {} 264 class ClassInstance : Instance {} 265 class InterfaceInstance : Instance {} 266 class EnumInstance : Instance {} 267 class UnionInstance : Instance {} 268 class StructInstance : Instance {} 269 class Statement {} 270 class FunctionCallStatement : Statement {} 271 class ControlflowStatement : Statement {} 272 class IfStatement : ControlflowStatement {} 273 class SwitchStatement : ControlflowStatement {} 274 class ForStatement : ControlflowStatement {} 275 class WhileStatement : ControlflowStatement {} 276 class DoWhileStatement : ControlflowStatement {} 277 class BreakStatement : ControlflowStatement {} 278 class ContinueStatement : ControlflowStatement {} 279 class ReturnStatement : ControlflowStatement {} 280 class GotoStatement : ControlflowStatement {} 281 class ExceptionHandling : Node {} 282 class TryBlock : ExceptionHandling {} 283 class CatchBlock : ExceptionHandling {} 284 class FinallyBlock : ExceptionHandling {} 285 class ThrowStatement : ExceptionHandling {} 286 class Module : Node {} 287 class Package : Node {} 288 class ImportStatement : Node {} 289 class SymbolImportStatement : Node {} 290 class AccessModifiers {} 291 class PublicModifier : AccessModifiers {} 292 class PrivateModifier : AccessModifiers {} 293 class ProtectedModifier : AccessModifiers {} 294 class InternalModifier : AccessModifiers {} 295 class Annotation : Node {} 296 class Decorator : Node {} 297 class Concurrency {} 298 class Thread : Concurrency {} 299 class AsyncAwait : Concurrency {} 300 class Lock : Concurrency {} 301 302 @safe pure nothrow unittest { 303 auto d = new Declaration(); 304 assert(!d.isTemplate); 305 }