1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
Sub returnCommandParm(ByVal intAskedForDelim As String)
Dim strState As String, strError As String, strErrorState As String, blnFirstTime As Boolean
Dim strValue As String, strCommandType As String
Dim strQreg As String, blnIsFunction As Boolean, strCommand As String
Const strModule As String = "returnCommandParm"
strState = "beginToken": blnFirstTime = True
Do While strState <> strEndParse
Call getChar
If strState = "beginToken" Then
GoSub beginToken
ElseIf strState = "collectString" Then
GoSub collectString
ElseIf strState = "collectCommand" Then
GoSub collectCommand
ElseIf strState = "gotEscape" Then
GoSub gotEscape
Else
Call handleError(strModule, strState, "Unknown state") ' tec019
End If
If mintDelimType = dError Then strState = strEndParse
Loop
Exit Sub
beginToken: ' we have nothing - collect characters or $function; or we have existing string and collect more
If mintDelimType = dEOI Then ' this picks up the premature EOI
Call handleError(strModule, strState, "` (end of string) missing") ' tec075
ElseIf (mintDelimType And intAskedForDelim) <> 0 Then ' this picks up asked for delimiters, push whatever we have so far
If blnFirstTime Then
Call pushCode("$PUSH", "", rString) ' push an empty string
End If
strState = strEndParse
ElseIf mstrChar = "$" Then ' modifier="$" -> push a null for the function call
Call pushCode("XPUSH", Null, rDefault)
strCommand = mstrChar: strState = "collectCommand" ' and go get the command
ElseIf mstrChar = "\" Then ' escape
strState = "gotEscape"
Else
strValue = mstrChar: strState = "collectString"
End If
Return
collectString: ' we are building up a string term
If mintDelimType = dEOI Then ' this picks up the EOI
Call handleError(strModule, strState, "Unexpected EOI while building string") ' tec060
ElseIf (mintDelimType And intAskedForDelim) <> 0 Then
Call pushCode("$PUSH", strValue, rString)
If Not blnFirstTime Then ' handle string concatenation
mintCodeStack = mintCodeStack + 1: codeStack(mintCodeStack, 1) = "$OPER": codeStack(mintCodeStack, 2) = "+"
mintExecStack = mintExecStack - 1 ' pop off the extra string value
End If
strState = strEndParse
ElseIf mstrChar = "\" Then ' escape
strState = "gotEscape"
ElseIf mstrChar = "$" Then ' modifier="$" -> push collected string, then a null for the function call
Call pushCode("$PUSH", strValue, rString)
If Not blnFirstTime Then
mintCodeStack = mintCodeStack + 1: codeStack(mintCodeStack, 1) = "$OPER": codeStack(mintCodeStack, 2) = "+"
mintExecStack = mintExecStack - 1 ' pop off the extra string value
End If
blnFirstTime = False
Call pushCode("XPUSH", Null, rDefault)
strCommand = mstrChar: strState = "collectCommand" ' and go get the command
Else ' everything else - add to value
strValue = strValue & mstrChar
End If
Return
collectCommand: ' string-version
If mintDelimType = dEOI Then ' this picks up the EOI
Call handleError(strModule, strState, "Unexpected EOI while building command/function") ' tec026
ElseIf (mintDelimType And intAskedForDelim) <> 0 Then ' this picks any asked for delimiters
Call handleError(strModule, strState, "Unexpected character while building command/function") ' tec027
ElseIf (mintCharType And aCmdChar) Then
strCommand = strCommand & mstrChar
strCommandType = commandType(strCommand, strQreg, blnIsFunction)
' commandType {unknown, command, incomplete, exprCommand, exprFunction}
If strCommandType = rUnknown Then
strState = strEndParse ' exit because we have already done our error message
ElseIf strCommandType = rCommand Then
Call handleError(strModule, strState, "Command not valid inside parameter") ' tec061
ElseIf strCommandType = rIncomplete Then
' if incomplete just collect more characters
Else ' must be either exprCommand or exprFunction
' now do the expression - which will push the result onto the stack
If processCommand(strModule, strState, strCommand, strQreg, blnIsFunction) Then
If Not blnFirstTime Then
mintCodeStack = mintCodeStack + 1: codeStack(mintCodeStack, 1) = "$OPER": codeStack(mintCodeStack, 2) = "+"
mintExecStack = mintExecStack - 1 ' take 2 strings off stack and replace with 1
End If
strState = "begintoken": blnFirstTime = False
End If
End If
Else ' error token not a command
Call handleError(strModule, strState, "Unexpected character while building command/function") 'tec027
End If
Return
gotEscape: ' have an escape, see what next character is
If mintDelimType = dEOI Then ' this picks up the EOI
Call handleError(strModule, strState, "Unexpected EOI while building string") ' tec060
Else ' all other characters - just add them to the string
If mstrChar = "t" Then
strValue = strValue & vbTab
ElseIf mstrChar = "r" Then
strValue = strValue & vbCr
ElseIf mstrChar = "n" Then
strValue = strValue & vbLf
Else
strValue = strValue & mstrChar
End If
strState = "collectString"
End If
Return
End Sub
|