1 |
/* |
/* |
2 |
* Copyright (c) 2014-2015 Christian Schoenebeck |
* Copyright (c) 2014-2016 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
76 |
VM_EXEC_ERROR = (1<<2), ///< A runtime error occurred while executing the script (i.e. a call to some built-in script function failed). |
VM_EXEC_ERROR = (1<<2), ///< A runtime error occurred while executing the script (i.e. a call to some built-in script function failed). |
77 |
}; |
}; |
78 |
|
|
79 |
|
/** @brief Script event handler type. |
80 |
|
* |
81 |
|
* Identifies one of the possible event handler callback types defined by |
82 |
|
* the NKSP script language. |
83 |
|
*/ |
84 |
|
enum VMEventHandlerType_t { |
85 |
|
VM_EVENT_HANDLER_INIT, ///< Initilization event handler, that is script's "on init ... end on" code block. |
86 |
|
VM_EVENT_HANDLER_NOTE, ///< Note event handler, that is script's "on note ... end on" code block. |
87 |
|
VM_EVENT_HANDLER_RELEASE, ///< Release event handler, that is script's "on release ... end on" code block. |
88 |
|
VM_EVENT_HANDLER_CONTROLLER, ///< Controller event handler, that is script's "on controller ... end on" code block. |
89 |
|
}; |
90 |
|
|
91 |
// just symbol prototyping |
// just symbol prototyping |
92 |
class VMIntExpr; |
class VMIntExpr; |
93 |
class VMStringExpr; |
class VMStringExpr; |
353 |
* Script data type of the function's @c iArg 'th function argument. |
* Script data type of the function's @c iArg 'th function argument. |
354 |
* The information provided here is less strong than acceptsArgType(). |
* The information provided here is less strong than acceptsArgType(). |
355 |
* The parser will compare argument data types provided in scripts by |
* The parser will compare argument data types provided in scripts by |
356 |
* calling cceptsArgType(). The return value of argType() is used by the |
* calling acceptsArgType(). The return value of argType() is used by the |
357 |
* parser instead to show an appropriate parser error which data type |
* parser instead to show an appropriate parser error which data type |
358 |
* this function usually expects as "default" data type. Reason: a |
* this function usually expects as "default" data type. Reason: a |
359 |
* function may accept multiple data types for a certain function |
* function may accept multiple data types for a certain function |
616 |
* engine) which is using the virtual machine classes here, must take |
* engine) which is using the virtual machine classes here, must take |
617 |
* care by itself about taking time stamps, determining the script |
* care by itself about taking time stamps, determining the script |
618 |
* handlers that shall be put aside for the requested amount of |
* handlers that shall be put aside for the requested amount of |
619 |
* microseconds indicated by this method by comparing the time stamps in |
* microseconds, indicated by this method by comparing the time stamps in |
620 |
* real-time, and to continue passing the respective handler to |
* real-time, and to continue passing the respective handler to |
621 |
* ScriptVM::exec() as soon as its suspension exceeded, etc. Or in other |
* ScriptVM::exec() as soon as its suspension exceeded, etc. Or in other |
622 |
* words: all classes in this directory never have an idea what time it |
* words: all classes in this directory never have an idea what time it |
639 |
class VMEventHandler { |
class VMEventHandler { |
640 |
public: |
public: |
641 |
/** |
/** |
642 |
|
* Type of this event handler, which identifies its purpose. For example |
643 |
|
* for a "on note ... end on" script callback block, |
644 |
|
* @c VM_EVENT_HANDLER_NOTE would be returned here. |
645 |
|
*/ |
646 |
|
virtual VMEventHandlerType_t eventHandlerType() const = 0; |
647 |
|
|
648 |
|
/** |
649 |
* Name of the event handler which identifies its purpose. For example |
* Name of the event handler which identifies its purpose. For example |
650 |
* for a "on note ... end on" script callback block, the name "note" |
* for a "on note ... end on" script callback block, the name "note" |
651 |
* would be returned here. |
* would be returned here. |
668 |
struct ParserIssue { |
struct ParserIssue { |
669 |
String txt; ///< Human readable explanation text of the parser issue. |
String txt; ///< Human readable explanation text of the parser issue. |
670 |
int line; ///< Line number within the script where this issue was encountered. |
int line; ///< Line number within the script where this issue was encountered. |
671 |
|
int column; ///< Column within the script where this issue was encountered. |
672 |
ParserIssueType_t type; ///< Whether this issue is either a parser error or just a parser warning. |
ParserIssueType_t type; ///< Whether this issue is either a parser error or just a parser warning. |
673 |
|
|
674 |
/** |
/** |
677 |
inline void dump() { |
inline void dump() { |
678 |
switch (type) { |
switch (type) { |
679 |
case PARSER_ERROR: |
case PARSER_ERROR: |
680 |
printf("[ERROR] line %d: %s\n", line, txt.c_str()); |
printf("[ERROR] line %d, column %d: %s\n", line, column, txt.c_str()); |
681 |
break; |
break; |
682 |
case PARSER_WARNING: |
case PARSER_WARNING: |
683 |
printf("[Warning] line %d: %s\n", line, txt.c_str()); |
printf("[Warning] line %d, column %d: %s\n", line, column, txt.c_str()); |
684 |
break; |
break; |
685 |
} |
} |
686 |
} |
} |
768 |
virtual VMEventHandler* eventHandlerByName(const String& name) = 0; |
virtual VMEventHandler* eventHandlerByName(const String& name) = 0; |
769 |
}; |
}; |
770 |
|
|
771 |
|
class SourceToken; |
772 |
|
|
773 |
|
/** @brief Recognized token of a script's source code. |
774 |
|
* |
775 |
|
* Represents one recognized token of a script's source code, for example |
776 |
|
* a keyword, variable name, etc. and it provides further informations about |
777 |
|
* that particular token, i.e. the precise location (line and column) of the |
778 |
|
* token within the original script's source code. |
779 |
|
* |
780 |
|
* This class is not actually used by the sampler itself. It is rather |
781 |
|
* provided for external script editor applications. Primary purpose of |
782 |
|
* this class is syntax highlighting for external script editors. |
783 |
|
*/ |
784 |
|
class VMSourceToken { |
785 |
|
public: |
786 |
|
VMSourceToken(); |
787 |
|
VMSourceToken(SourceToken* ct); |
788 |
|
VMSourceToken(const VMSourceToken& other); |
789 |
|
virtual ~VMSourceToken(); |
790 |
|
|
791 |
|
// original text of this token as it is in the script's source code |
792 |
|
String text() const; |
793 |
|
|
794 |
|
// position of token in script |
795 |
|
int firstLine() const; |
796 |
|
int firstColumn() const; |
797 |
|
|
798 |
|
// base types |
799 |
|
bool isEOF() const; |
800 |
|
bool isNewLine() const; |
801 |
|
bool isKeyword() const; |
802 |
|
bool isVariableName() const; |
803 |
|
bool isIdentifier() const; |
804 |
|
bool isNumberLiteral() const; |
805 |
|
bool isStringLiteral() const; |
806 |
|
bool isComment() const; |
807 |
|
bool isPreprocessor() const; |
808 |
|
bool isOther() const; |
809 |
|
|
810 |
|
// extended types |
811 |
|
bool isIntegerVariable() const; |
812 |
|
bool isStringVariable() const; |
813 |
|
bool isArrayVariable() const; |
814 |
|
bool isEventHandlerName() const; |
815 |
|
|
816 |
|
VMSourceToken& operator=(const VMSourceToken& other); |
817 |
|
|
818 |
|
private: |
819 |
|
SourceToken* m_token; |
820 |
|
}; |
821 |
|
|
822 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |
823 |
|
|
824 |
#endif // LS_INSTR_SCRIPT_PARSER_COMMON_H |
#endif // LS_INSTR_SCRIPT_PARSER_COMMON_H |