1 /* 2 * Copyright (c) 2020, Masatake YAMATO 3 * Copyright (c) 2020, Red Hat, Inc. 4 * 5 * This source code is released for free distribution under the terms of the 6 * GNU General Public License version 2 or (at your option) any later version. 7 */ 8 9 #ifndef DSL_H 10 #define DSL_H 11 12 /* 13 * INCLUDES 14 */ 15 #include "es.h" 16 #include "readtags.h" 17 18 19 /* 20 * TYPES 21 */ 22 enum eDSLEngineType { 23 DSL_INTERNAL_PSEUDO, 24 DSL_COMMON, 25 DSL_QUALIFIER, 26 DSL_SORTER, 27 DSL_FORMATTER, 28 DSL_ENGINE_COUNT 29 }; 30 typedef enum eDSLEngineType DSLEngineType; 31 32 struct sDSLEnv { 33 enum eDSLEngineType engine; 34 const tagEntry *entry; 35 const tagEntry *alt_entry; 36 }; 37 typedef struct sDSLEnv DSLEnv; 38 39 typedef EsObject* (* DSLProc) (EsObject *args, DSLEnv *env); 40 typedef EsObject* (* DSLMacro) (EsObject *expr); 41 42 43 enum eDSLPAttr { 44 DSL_PATTR_MEMORABLE = 1UL << 0, 45 DSL_PATTR_SELF_EVAL = 1UL << 1, 46 DSL_PATTR_CHECK_ARITY = 1UL << 2, 47 DSL_PATTR_CHECK_ARITY_OPT = 1UL << 3 | DSL_PATTR_CHECK_ARITY, 48 }; 49 typedef enum eDSLPAttr DSLPAttr; 50 51 typedef struct sDSLProcBind DSLProcBind; 52 struct sDSLProcBind { 53 const char *name; 54 DSLProc proc; 55 EsObject* cache; 56 DSLPAttr flags; 57 int arity; 58 const char* helpstr; 59 DSLMacro macro; 60 }; 61 62 typedef struct sDSLCode DSLCode; 63 64 #define DSL_ERR_UNBOUND_VARIABLE (es_error_intern("unbound-variable")) 65 #define DSL_ERR_TOO_FEW_ARGUMENTS (es_error_intern("too-few-arguments")) 66 #define DSL_ERR_TOO_MANY_ARGUMENTS (es_error_intern("too-many-arguments")) 67 #define DSL_ERR_STRING_REQUIRED (es_error_intern("string-required")) 68 #define DSL_ERR_BOOLEAN_REQUIRED (es_error_intern("boolean-required")) 69 #define DSL_ERR_INTEGER_REQUIRED (es_error_intern("integer-required")) 70 #define DSL_ERR_NUMBER_REQUIRED (es_error_intern("number-required")) 71 #define DSL_ERR_CALLABLE_REQUIRED (es_error_intern("callable-required")) 72 #define DSL_ERR_WRONG_TYPE_ARGUMENT (es_error_intern("wrong-type-argument")) 73 #define DSL_ERR_NO_ALT_ENTRY (es_error_intern("the-alternative-entry-unavailable")) 74 75 76 /* 77 * MACROS 78 */ 79 #define dsl_throw(e,o) return es_error_set_object(DSL_ERR_##e, o) 80 81 82 /* 83 * Function declarations 84 */ 85 86 /* Return 1 if no error. */ 87 int dsl_init (DSLEngineType engine, DSLProcBind *engine_pbinds, int count); 88 DSLProcBind *dsl_lookup (DSLEngineType engine, EsObject *name); 89 void dsl_help (DSLEngineType engine, FILE *fp); 90 void dsl_cache_reset (DSLEngineType engine); 91 DSLCode *dsl_compile (DSLEngineType engine, EsObject *expr); 92 EsObject *dsl_eval (DSLCode *code, DSLEnv *env); 93 void dsl_release (DSLEngineType engine, DSLCode *code); 94 95 /* This should be remove when we have a real compiler. */ 96 EsObject *dsl_compile_and_eval (EsObject *expr, DSLEnv *env); 97 98 99 EsObject* dsl_entry_xget_string (const tagEntry *entry, const char* name); 100 101 EsObject* dsl_entry_name (const tagEntry *entry); 102 EsObject* dsl_entry_input (const tagEntry *entry); 103 EsObject* dsl_entry_pattern (const tagEntry *entry); 104 EsObject* dsl_entry_line (const tagEntry *entry); 105 106 EsObject* dsl_entry_access (const tagEntry *entry); 107 EsObject* dsl_entry_end (const tagEntry *entry); 108 EsObject* dsl_entry_extras (const tagEntry *entry); 109 EsObject* dsl_entry_file (const tagEntry *entry); 110 EsObject* dsl_entry_inherits (const tagEntry *entry); 111 EsObject* dsl_entry_implementation (const tagEntry *entry); 112 EsObject* dsl_entry_kind (const tagEntry *entry); 113 EsObject* dsl_entry_language (const tagEntry *entry); 114 EsObject* dsl_entry_scope (const tagEntry *entry); 115 EsObject* dsl_entry_scope_kind (const tagEntry *entry); 116 EsObject* dsl_entry_scope_name (const tagEntry *entry); 117 EsObject* dsl_entry_signature (const tagEntry *entry); 118 EsObject* dsl_entry_typeref (const tagEntry *entry); 119 EsObject* dsl_entry_typeref_kind (const tagEntry *entry); 120 EsObject* dsl_entry_typeref_name (const tagEntry *entry); 121 EsObject* dsl_entry_roles (const tagEntry *entry); 122 EsObject* dsl_entry_xpath (const tagEntry *entry); 123 124 void dsl_report_error (const char *msg, EsObject *obj); 125 126 #endif 127