| | |
| | | token->len = state->pos - token->ptr; |
| | | |
| | | if (token->len > 0) { |
| | | token->type = TokWhiteSpace; |
| | | token->type = SCPI_TOKEN_WS; |
| | | } else { |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | } |
| | | |
| | | return token->len; |
| | |
| | | int scpiLex_ProgramHeader(lex_state_t * state, scpi_token_t * token) { |
| | | int res; |
| | | token->ptr = state->pos; |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | |
| | | res = skipCommonProgramHeader(state); |
| | | if (res >= SKIP_OK) { |
| | | if (skipChr(state, '?') >= SKIP_OK) { |
| | | token->type = TokCommonQueryProgramHeader; |
| | | token->type = SCPI_TOKEN_COMMON_QUERY_PROGRAM_HEADER; |
| | | } else { |
| | | token->type = TokCommonProgramHeader; |
| | | token->type = SCPI_TOKEN_COMMON_PROGRAM_HEADER; |
| | | } |
| | | } else if (res <= SKIP_INCOMPLETE) { |
| | | token->type = TokIncompleteCommonProgramHeader; |
| | | token->type = SCPI_TOKEN_INCOMPLETE_COMMON_PROGRAM_HEADER; |
| | | } else if (res == SKIP_NONE) { |
| | | res = skipCompoundProgramHeader(state); |
| | | |
| | | if (res >= SKIP_OK) { |
| | | if (skipChr(state, '?') >= SKIP_OK) { |
| | | token->type = TokCompoundQueryProgramHeader; |
| | | token->type = SCPI_TOKEN_COMPOUND_QUERY_PROGRAM_HEADER; |
| | | } else { |
| | | token->type = TokCompoundProgramHeader; |
| | | token->type = SCPI_TOKEN_COMPOUND_PROGRAM_HEADER; |
| | | } |
| | | } else if (res <= SKIP_INCOMPLETE) { |
| | | token->type = TokIncompleteCompoundProgramHeader; |
| | | token->type = SCPI_TOKEN_INCOMPLETE_COMPOUND_PROGRAM_HEADER; |
| | | } |
| | | } |
| | | |
| | | if (token->type != TokUnknown) { |
| | | if (token->type != SCPI_TOKEN_UNKNOWN) { |
| | | token->len = state->pos - token->ptr; |
| | | } else { |
| | | token->len = 0; |
| | |
| | | |
| | | token->len = state->pos - token->ptr; |
| | | if (token->len > 0) { |
| | | token->type = TokProgramMnemonic; |
| | | token->type = SCPI_TOKEN_PROGRAM_MNEMONIC; |
| | | } else { |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | } |
| | | |
| | | return token->len; |
| | |
| | | |
| | | token->len = state->pos - token->ptr; |
| | | if (token->len > 0) { |
| | | token->type = TokDecimalNumericProgramData; |
| | | token->type = SCPI_TOKEN_DECIMAL_NUMERIC_PROGRAM_DATA; |
| | | } else { |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | } |
| | | |
| | | return token->len; |
| | |
| | | |
| | | token->len = state->pos - token->ptr; |
| | | if ((token->len > 0)) { |
| | | token->type = TokSuffixProgramData; |
| | | token->type = SCPI_TOKEN_SUFFIX_PROGRAM_DATA; |
| | | } else { |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | state->pos = token->ptr; |
| | | token->len = 0; |
| | | } |
| | |
| | | if (isH(state->pos[0])) { |
| | | state->pos++; |
| | | someNumbers = skipHexNum(state); |
| | | token->type = TokHexnum; |
| | | token->type = SCPI_TOKEN_HEXNUM; |
| | | } else if (isQ(state->pos[0])) { |
| | | state->pos++; |
| | | someNumbers = skipOctNum(state); |
| | | token->type = TokOctnum; |
| | | token->type = SCPI_TOKEN_OCTNUM; |
| | | } else if (isB(state->pos[0])) { |
| | | state->pos++; |
| | | someNumbers = skipBinNum(state); |
| | | token->type = TokBinnum; |
| | | token->type = SCPI_TOKEN_BINNUM; |
| | | } |
| | | } |
| | | } |
| | |
| | | token->ptr += 2; // ignore number prefix |
| | | token->len = state->pos - token->ptr; |
| | | } else { |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | state->pos = token->ptr; |
| | | token->len = 0; |
| | | } |
| | |
| | | if (!iseos(state)) { |
| | | if (ischr(state, '"')) { |
| | | state->pos++; |
| | | token->type = TokDoubleQuoteProgramData; |
| | | token->type = SCPI_TOKEN_DOUBLE_QUOTE_PROGRAM_DATA; |
| | | skipDoubleQuoteProgramData(state); |
| | | if (!iseos(state) && ischr(state, '"')) { |
| | | state->pos++; |
| | |
| | | } |
| | | } else if (ischr(state, '\'')) { |
| | | state->pos++; |
| | | token->type = TokSingleQuoteProgramData; |
| | | token->type = SCPI_TOKEN_SINGLE_QUOTE_PROGRAM_DATA; |
| | | skipSingleQuoteProgramData(state); |
| | | if (!iseos(state) && ischr(state, '\'')) { |
| | | state->pos++; |
| | |
| | | token->ptr++; |
| | | token->len -= 2; |
| | | } else { |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | state->pos = token->ptr; |
| | | token->len = 0; |
| | | } |
| | |
| | | } |
| | | |
| | | if ((token->len > 0)) { |
| | | token->type = TokArbitraryBlockProgramData; |
| | | token->type = SCPI_TOKEN_ARBITRARY_BLOCK_PROGRAM_DATA; |
| | | } else { |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | state->pos = token->ptr; |
| | | token->len = 0; |
| | | } |
| | |
| | | } |
| | | |
| | | if ((token->len > 0)) { |
| | | token->type = TokProgramExpression; |
| | | token->type = SCPI_TOKEN_PROGRAM_EXPRESSION; |
| | | } else { |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | state->pos = token->ptr; |
| | | token->len = 0; |
| | | } |
| | |
| | | |
| | | if (skipChr(state, ',')) { |
| | | token->len = 1; |
| | | token->type = TokComma; |
| | | token->type = SCPI_TOKEN_COMMA; |
| | | } else { |
| | | token->len = 0; |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | } |
| | | |
| | | return token->len; |
| | |
| | | |
| | | if (skipChr(state, ';')) { |
| | | token->len = 1; |
| | | token->type = TokSemicolon; |
| | | token->type = SCPI_TOKEN_SEMICOLON; |
| | | } else { |
| | | token->len = 0; |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | } |
| | | |
| | | return token->len; |
| | |
| | | token->len = state->pos - token->ptr; |
| | | |
| | | if ((token->len > 0)) { |
| | | token->type = TokNewLine; |
| | | token->type = SCPI_TOKEN_NL; |
| | | } else { |
| | | token->type = TokUnknown; |
| | | token->type = SCPI_TOKEN_UNKNOWN; |
| | | state->pos = token->ptr; |
| | | token->len = 0; |
| | | } |