MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey-v1.0 / ParseAndAddLine

Method ParseAndAddLine

Source/script.cpp:1948–2713  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1946
1947
1948ResultType Script::ParseAndAddLine(char *aLineText, char *aActionName, char *aEndMarker
1949 , char *aLiteralMap, size_t aLiteralMapLength
1950 , ActionTypeType aActionType, ActionTypeType aOldActionType)
1951// Returns OK or FAIL.
1952// aLineText needs to be a string whose contents are modifiable (this
1953// helps performance by allowing the string to be split into sections
1954// without having to make temporary copies).
1955{
1956#ifdef _DEBUG
1957 if (!aLineText || !*aLineText)
1958 return ScriptError("ParseAndAddLine() called incorrectly.");
1959#endif
1960
1961 // The characters below are ordered with most-often used ones first, for performance:
1962 #define DEFINE_END_FLAGS \
1963 char end_flags[] = {' ', g_delimiter, '(', '\t', '<', '>', ':', '=', '+', '-', '*', '/', '!', '~', '&', '|', '^', '\0'}; // '\0' must be last.
1964 DEFINE_END_FLAGS
1965
1966 char action_name[MAX_VAR_NAME_LENGTH + 1], *end_marker;
1967 if (aActionName) // i.e. this function was called recursively with explicit values for the optional params.
1968 {
1969 strcpy(action_name, aActionName);
1970 end_marker = aEndMarker;
1971 }
1972 else
1973 if ( !(end_marker = ParseActionType(action_name, aLineText, true)) )
1974 return FAIL; // It already displayed the error.
1975
1976 // Find the arguments (not to be confused with exec_params) of this action, if it has any:
1977 char *action_args = omit_leading_whitespace(end_marker + 1);
1978 // Now action_args is either the first delimiter or the first parameter (if it optional first
1979 // delimiter was omitted):
1980 bool is_var_and_operator;
1981 if (*action_args == g_delimiter)
1982 {
1983 is_var_and_operator = false; // Since there's a comma, we know it's not, e.g. something, += 4
1984 // Find the start of the next token (or its ending delimiter if the token is blank such as ", ,"):
1985 for (++action_args; IS_SPACE_OR_TAB(*action_args); ++action_args);
1986 }
1987 else
1988 {
1989 // The next line is used to help avoid ambiguity of a line such as the following:
1990 // Input = test ; Would otherwise be confused with the Input command.
1991 // But there may be times when a line like this would be used:
1992 // MsgBox = ; i.e. the equals is intended to be the first parameter, not an operator.
1993 // In the above case, the user can provide the optional comma to avoid the ambiguity:
1994 // MsgBox, =
1995 switch(*action_args)
1996 {
1997 case '=':
1998 case ':': // i.e. :=
1999 case '(': // i.e. "if (expr)"
2000 is_var_and_operator = true;
2001 break;
2002 case '*':
2003 case '/':
2004 case '-':
2005 case '+':

Callers

nothing calls this directly

Calls 6

omit_leading_whitespaceFunction · 0.85
StrChrAnyFunction · 0.85
strcasestrFunction · 0.85
IsPureNumericFunction · 0.85
rtrimFunction · 0.85
snprintfFunction · 0.85

Tested by

no test coverage detected