From 06ca0ab8991fe36731ae715a072fb12cc22abcca Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周一, 24 6月 2013 22:19:34 +0800
Subject: [PATCH] Update documentation

---
 libscpi/src/parser.c |  614 ++++++++++++++++++++++++++-----------------------------
 1 files changed, 294 insertions(+), 320 deletions(-)

diff --git a/libscpi/src/parser.c b/libscpi/src/parser.c
index d10cfe1..cedce47 100644
--- a/libscpi/src/parser.c
+++ b/libscpi/src/parser.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2012-2013 Jan Breuer,
  *
  * All Rights Reserved
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
  * met:
@@ -11,7 +11,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -28,10 +28,10 @@
 /**
  * @file   scpi_parser.c
  * @date   Thu Nov 15 10:58:45 UTC 2012
- * 
+ *
  * @brief  SCPI parser implementation
- * 
- * 
+ *
+ *
  */
 
 #include <ctype.h>
@@ -42,100 +42,6 @@
 #include "scpi/lexer.h"
 #include "utils.h"
 #include "scpi/error.h"
-
-
-static size_t cmdTerminatorPos(const char * cmd, size_t len);
-static size_t cmdlineSeparatorPos(const char * cmd, size_t len);
-static const char * cmdlineSeparator(const char * cmd, size_t len);
-static const char * cmdlineTerminator(const char * cmd, size_t len);
-static const char * cmdlineNext(const char * cmd, size_t len);
-
-static void paramSkipBytes(scpi_t * context, size_t num);
-static void paramSkipWhitespace(scpi_t * context);
-static bool_t paramNext(scpi_t * context, bool_t mandatory);
-
-/*
-int _strnicmp(const char* s1, const char* s2, size_t len) {
-    int result = 0;
-    int i;
-
-    for (i = 0; i < len && s1[i] && s2[i]; i++) {
-        char c1 = tolower(s1[i]);
-        char c2 = tolower(s2[i]);
-        if (c1 != c2) {
-            result = (int) c1 - (int) c2;
-            break;
-        }
-    }
-
-    return result;
-}
- */
-
-/**
- * Find command termination character
- * @param cmd - input command
- * @param len - max search length
- * @return position of terminator or len
- */
-size_t cmdTerminatorPos(const char * cmd, size_t len) {
-    const char * terminator = strnpbrk(cmd, len, "; \r\n\t");
-    if (terminator == NULL) {
-        return len;
-    } else {
-        return terminator - cmd;
-    }
-}
-
-/**
- * Find command line separator
- * @param cmd - input command
- * @param len - max search length
- * @return pointer to line separator or NULL
- */
-const char * cmdlineSeparator(const char * cmd, size_t len) {
-    return strnpbrk(cmd, len, ";\r\n");
-}
-
-/**
- * Find command line terminator
- * @param cmd - input command
- * @param len - max search length
- * @return pointer to command line terminator or NULL
- */
-const char * cmdlineTerminator(const char * cmd, size_t len) {
-    return strnpbrk(cmd, len, "\r\n");
-}
-
-/**
- * Find command line separator position
- * @param cmd - input command
- * @param len - max search length
- * @return position of line separator or len
- */
-size_t cmdlineSeparatorPos(const char * cmd, size_t len) {
-    const char * separator = cmdlineSeparator(cmd, len);
-    if (separator == NULL) {
-        return len;
-    } else {
-        return separator - cmd;
-    }
-}
-
-/**
- * Find next part of command
- * @param cmd - input command
- * @param len - max search length
- * @return Pointer to next part of command
- */
-const char * cmdlineNext(const char * cmd, size_t len) {
-    const char * separator = cmdlineSeparator(cmd, len);
-    if (separator == NULL) {
-        return cmd + len;
-    } else {
-        return separator + 1;
-    }
-}
 
 /**
  * Write data to SCPI output
@@ -195,7 +101,8 @@
  * @param context
  */
 static void processCommand(scpi_t * context) {
-    const scpi_command_t * cmd = context->paramlist.cmd;
+    const scpi_command_t * cmd = context->param_list.cmd;
+    lex_state_t * state = &context->param_list.lex_state;
 
     context->cmd_error = FALSE;
     context->output_count = 0;
@@ -212,11 +119,8 @@
     /* conditionaly write new line */
     writeNewLine(context);
 
-    /* skip all whitespaces */
-    paramSkipWhitespace(context);
-
     /* set error if command callback did not read all parameters */
-    if (context->paramlist.length != 0 && !context->cmd_error) {
+    if (state->pos < (state->buffer + state->len) && !context->cmd_error) {
         SCPI_ErrorPush(context, SCPI_ERROR_PARAMETER_NOT_ALLOWED);
     }
 }
@@ -226,16 +130,14 @@
  * @param context
  * @result TRUE if context->paramlist is filled with correct values
  */
-static bool_t findCommand(scpi_t * context, const char * cmdline_ptr, size_t cmdline_len, size_t cmd_len) {
+static bool_t findCommandHeader(scpi_t * context, const char * header, int len) {
     int32_t i;
     const scpi_command_t * cmd;
 
     for (i = 0; context->cmdlist[i].pattern != NULL; i++) {
         cmd = &context->cmdlist[i];
-        if (matchCommand(cmd->pattern, cmdline_ptr, cmd_len)) {
-            context->paramlist.cmd = cmd;
-            context->paramlist.parameters = cmdline_ptr + cmd_len;
-            context->paramlist.length = cmdline_len - cmd_len;
+        if (matchCommand(cmd->pattern, header, len)) {
+            context->param_list.cmd = cmd;
             return TRUE;
         }
     }
@@ -249,30 +151,46 @@
  * @param len - command line length
  * @return 1 if the last evaluated command was found
  */
-int SCPI_Parse(scpi_t * context, const char * data, size_t len) {
+int SCPI_Parse(scpi_t * context, const char * data, int len) {
     int result = 0;
-    const char * cmdline_end = data + len;
-    const char * cmdline_ptr = data;
-    size_t cmd_len;
-    size_t cmdline_len;
+    scpi_parser_state_t * state;
+    int r;
 
     if (context == NULL) {
         return -1;
     }
 
-    while (cmdline_ptr < cmdline_end) {
+    state = &context->parser_state;
+
+    while (1) {
         result = 0;
-        cmd_len = cmdTerminatorPos(cmdline_ptr, cmdline_end - cmdline_ptr);
-        cmdline_len = cmdlineSeparatorPos(cmdline_ptr, cmdline_end - cmdline_ptr);
-        if (cmd_len > 0) {
-            if(findCommand(context, cmdline_ptr, cmdline_len, cmd_len)) {
+
+        r = SCPI_DetectProgramMessageUnit(state, data, len);
+
+        if (state->programHeader.type == TokInvalid) {
+            SCPI_ErrorPush(context, SCPI_ERROR_UNEXPECTED_CHARACTER);
+        } else if (state->programHeader.len > 0) {
+            if (findCommandHeader(context, state->programHeader.ptr, state->programHeader.len)) {
+
+                context->param_list.lex_state.buffer = state->programData.ptr;
+                context->param_list.lex_state.pos = context->param_list.lex_state.buffer;
+                context->param_list.lex_state.len = state->programData.len;
+
                 processCommand(context);
+
                 result = 1;
             } else {
                 SCPI_ErrorPush(context, SCPI_ERROR_UNDEFINED_HEADER);
             }
         }
-        cmdline_ptr = cmdlineNext(cmdline_ptr, cmdline_end - cmdline_ptr);
+
+        if (r < len) {
+            data += r;
+            len -= r;
+        } else {
+            break;
+        }
+
     }
     return result;
 }
@@ -293,22 +211,24 @@
  * Interface to the application. Adds data to system buffer and try to search
  * command line termination. If the termination is found or if len=0, command
  * parser is called.
- * 
+ *
  * @param context
  * @param data - data to process
  * @param len - length of data
- * @return 
+ * @return
  */
-int SCPI_Input(scpi_t * context, const char * data, size_t len) {
+int SCPI_Input(scpi_t * context, const char * data, int len) {
     int result = 0;
-    const char * cmd_term;
+    size_t totcmdlen = 0;
+    int cmdlen = 0;
+
     if (len == 0) {
         context->buffer.data[context->buffer.position] = 0;
         result = SCPI_Parse(context, context->buffer.data, context->buffer.position);
         context->buffer.position = 0;
     } else {
-        size_t buffer_free;
-        int ws;
+        int buffer_free;
+
         buffer_free = context->buffer.length - context->buffer.position;
         if (len > (buffer_free - 1)) {
             return -1;
@@ -317,13 +237,19 @@
         context->buffer.position += len;
         context->buffer.data[context->buffer.position] = 0;
 
-        ws = skipWhitespace(context->buffer.data, context->buffer.position);
-        cmd_term = cmdlineTerminator(context->buffer.data + ws, context->buffer.position - ws);
-        if (cmd_term != NULL) {
-            int curr_len = cmd_term - context->buffer.data;
-            result = SCPI_Parse(context, context->buffer.data + ws, curr_len - ws);
-            memmove(context->buffer.data, cmd_term, context->buffer.position - curr_len);
-            context->buffer.position -= curr_len;
+
+        while (1) {
+            cmdlen = SCPI_DetectProgramMessageUnit(&context->parser_state, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen);
+            totcmdlen += cmdlen;
+            if (context->parser_state.termination == PmutNewLine) break;
+            if (context->parser_state.programHeader.type == TokUnknown) break;
+            if (totcmdlen >= context->buffer.position) break;
+        }
+
+        if (context->parser_state.termination == PmutNewLine) {
+            result = SCPI_Parse(context, context->buffer.data, totcmdlen);
+            memmove(context->buffer.data, context->buffer.data + totcmdlen, context->buffer.position - totcmdlen);
+            context->buffer.position -= totcmdlen;
         }
     }
 
@@ -336,10 +262,9 @@
  * Write raw string result to the output
  * @param context
  * @param data
- * @return 
+ * @return
  */
-size_t SCPI_ResultString(scpi_t * context, const char * data) {
-    size_t len = strlen(data);
+size_t SCPI_ResultCharacters(scpi_t * context, const char * data, size_t len) {
     size_t result = 0;
     result += writeDelimiter(context);
     result += writeData(context, data, len);
@@ -351,13 +276,34 @@
  * Write integer value to the result
  * @param context
  * @param val
- * @return 
+ * @return
  */
 size_t SCPI_ResultInt(scpi_t * context, int32_t val) {
-    char buffer[12];
+    return SCPI_ResultIntBase(context, val, 10);
+}
+
+static const char * getBasePrefix(int8_t base) {
+    switch (base) {
+        case 2: return "#B";
+        case 8: return "#Q";
+        case 16: return "#H";
+        default: return NULL;
+    }
+}
+
+size_t SCPI_ResultIntBase(scpi_t * context, int32_t val, int8_t base) {
+    char buffer[33];
+    const char * basePrefix;
     size_t result = 0;
-    size_t len = longToStr(val, buffer, sizeof (buffer));
+    size_t len;
+
+    len = longToStr(val, buffer, sizeof (buffer), base);
+    basePrefix = getBasePrefix(base);
+
     result += writeDelimiter(context);
+    if (basePrefix != NULL) {
+        result += writeData(context, basePrefix, 2);
+    }
     result += writeData(context, buffer, len);
     context->output_count++;
     return result;
@@ -367,7 +313,7 @@
  * Write double walue to the result
  * @param context
  * @param val
- * @return 
+ * @return
  */
 size_t SCPI_ResultDouble(scpi_t * context, double val) {
     char buffer[32];
@@ -384,7 +330,7 @@
  * Write string withn " to the result
  * @param context
  * @param data
- * @return 
+ * @return
  */
 size_t SCPI_ResultText(scpi_t * context, const char * data) {
     size_t result = 0;
@@ -398,209 +344,237 @@
 
 /* parsing parameters */
 
-/**
- * Skip num bytes from the begginig of parameters
- * @param context
- * @param num
- */
-void paramSkipBytes(scpi_t * context, size_t num) {
-    if (context->paramlist.length < num) {
-        num = context->paramlist.length;
-    }
-    context->paramlist.parameters += num;
-    context->paramlist.length -= num;
-}
+bool_t SCPI_Parameter(scpi_t * context, scpi_parameter_t * parameter, bool_t mandatory) {
+    token_t token;
+    lex_state_t * state;
+    int32_t value;
 
-/**
- * Skip white spaces from the beggining of parameters
- * @param context
- */
-void paramSkipWhitespace(scpi_t * context) {
-    size_t ws = skipWhitespace(context->paramlist.parameters, context->paramlist.length);
-    paramSkipBytes(context, ws);
-}
+    parameter->data.ptr = NULL;
+    parameter->data.len = 0;
+    parameter->number.value = 0;
+    parameter->number.base = 10;
+    parameter->number.unit = SCPI_UNIT_NONE;
+    parameter->number.type = SCPI_NUM_NUMBER;
+    parameter->type = TokUnknown;
 
-/**
- * Find next parameter
- * @param context
- * @param mandatory
- * @return 
- */
-bool_t paramNext(scpi_t * context, bool_t mandatory) {
-    paramSkipWhitespace(context);
-    if (context->paramlist.length == 0) {
+    state = &context->param_list.lex_state;
+
+    if (state->pos >= (state->buffer + state->len)) {
         if (mandatory) {
             SCPI_ErrorPush(context, SCPI_ERROR_MISSING_PARAMETER);
+        } else {
+            parameter->number.type = SCPI_NUM_DEF;
+            parameter->type = TokProgramMnemonic; // TODO: select something different
         }
         return FALSE;
     }
     if (context->input_count != 0) {
-        if (context->paramlist.parameters[0] == ',') {
-            paramSkipBytes(context, 1);
-            paramSkipWhitespace(context);
-        } else {
+        SCPI_LexComma(state, &token);
+        if (token.type != TokComma) {
             SCPI_ErrorPush(context, SCPI_ERROR_INVALID_SEPARATOR);
             return FALSE;
         }
     }
+
     context->input_count++;
-    return TRUE;
+
+    SCPI_ParseProgramData(&context->param_list.lex_state, &token);
+
+    parameter->type = token.type;
+    parameter->data.ptr = token.ptr;
+    parameter->data.len = token.len;
+
+    switch (token.type) {
+        case TokHexnum:
+            parameter->number.base = 16;
+            strToLong(token.ptr, &value, 16);
+            parameter->number.value = value;
+            return TRUE;
+        case TokOctnum:
+            parameter->number.base = 8;
+            strToLong(token.ptr, &value, 8);
+            parameter->number.value = value;
+            return TRUE;
+        case TokBinnum:
+            parameter->number.base = 2;
+            strToLong(token.ptr, &value, 2);
+            parameter->number.value = value;
+            return TRUE;
+        case TokProgramMnemonic:
+            return TRUE;
+        case TokDecimalNumericProgramData:
+            strToDouble(token.ptr, &parameter->number.value);
+            return TRUE;
+        case TokDecimalNumericProgramDataWithSuffix:
+            strToDouble(token.ptr, &parameter->number.value);
+            return TRUE;
+        case TokArbitraryBlockProgramData:
+            return TRUE;
+        case TokSingleQuoteProgramData:
+            // TODO: replace double "single qoute"
+            return TRUE;
+        case TokDoubleQuoteProgramData:
+            // TODO: replace double "double qoute"
+            return TRUE;
+        case TokProgramExpression:
+            return TRUE;
+        default:
+            parameter->type = TokUnknown;
+            parameter->data.ptr = NULL;
+            parameter->data.len = 0;
+            SCPI_ErrorPush(context, SCPI_ERROR_UNKNOWN_PARAMETER);
+            return FALSE;
+    }
 }
 
-/**
- * Parse integer parameter
- * @param context
- * @param value
- * @param mandatory
- * @return 
- */
-bool_t SCPI_ParamInt(scpi_t * context, int32_t * value, bool_t mandatory) {
-    const char * param;
-    size_t param_len;
-    size_t num_len;
-
-    if (!value) {
-        return FALSE;
+int32_t SCPI_ParamGetIntVal(scpi_t * context, scpi_parameter_t * parameter) {
+    switch (parameter->type) {
+        case TokHexnum:
+        case TokOctnum:
+        case TokBinnum:
+        case TokDecimalNumericProgramData:
+        case TokDecimalNumericProgramDataWithSuffix:
+            return parameter->number.value;
+        default:
+            SCPI_ErrorPush(context, SCPI_ERROR_INVALID_PARAMETER);
+            return 0;
     }
-
-    if (!SCPI_ParamString(context, &param, &param_len, mandatory)) {
-        return FALSE;
-    }
-
-    num_len = strToLong(param, value);
-
-    if (num_len != param_len) {
-        SCPI_ErrorPush(context, SCPI_ERROR_SUFFIX_NOT_ALLOWED);
-        return FALSE;
-    }
-
-    return TRUE;
 }
 
-/**
- * Parse double parameter
- * @param context
- * @param value
- * @param mandatory
- * @return 
- */
-bool_t SCPI_ParamDouble(scpi_t * context, double * value, bool_t mandatory) {
-    const char * param;
-    size_t param_len;
-    size_t num_len;
-
-    if (!value) {
-        return FALSE;
-    }
-
-    if (!SCPI_ParamString(context, &param, &param_len, mandatory)) {
-        return FALSE;
-    }
-
-    num_len = strToDouble(param, value);
-
-    if (num_len != param_len) {
-        SCPI_ErrorPush(context, SCPI_ERROR_SUFFIX_NOT_ALLOWED);
-        return FALSE;
-    }
-
-    return TRUE;
+double SCPI_ParamGetDoubleVal(scpi_t * context, scpi_parameter_t * parameter) {
+    return parameter->number.value;
 }
 
-/**
- * Parse string parameter
- * @param context
- * @param value
- * @param len
- * @param mandatory
- * @return 
- */
-bool_t SCPI_ParamString(scpi_t * context, const char ** value, size_t * len, bool_t mandatory) {
-    size_t length;
-
-    if (!value || !len) {
-        return FALSE;
-    }
-
-    if (!paramNext(context, mandatory)) {
-        return FALSE;
-    }
-
-    if (locateStr(context->paramlist.parameters, context->paramlist.length, value, &length)) {
-        paramSkipBytes(context, length);
-        paramSkipWhitespace(context);
-        if (len) {
-            *len = length;
-        }
-        return TRUE;
-    }
-
-    return FALSE;
+void SCPI_ParamGetTextVal(scpi_t * context, scpi_parameter_t * parameter, const char ** data, int32_t * len) {
+    *data = parameter->data.ptr;
+    *len = parameter->data.len;
 }
 
-/**
- * Parse text parameter (can be inside "")
- * @param context
- * @param value
- * @param len
- * @param mandatory
- * @return 
- */
-bool_t SCPI_ParamText(scpi_t * context, const char ** value, size_t * len, bool_t mandatory) {
-    size_t length;
-
-    if (!value || !len) {
-        return FALSE;
-    }
-
-    if (!paramNext(context, mandatory)) {
-        return FALSE;
-    }
-
-    if (locateText(context->paramlist.parameters, context->paramlist.length, value, &length)) {
-        paramSkipBytes(context, length);
-        if (len) {
-            *len = length;
-        }
-        return TRUE;
-    }
-
-    return FALSE;
-}
-
-
-
-void SCPI_ProgramMessageUnit(scpi_t * context) {
-    lex_state_t state;
+int SCPI_ParseProgramData(lex_state_t * state, token_t * token) {
     token_t tmp;
-    token_t header;
-    token_t token;
-    
-    state.buffer = state.pos = context->buffer.data;
-    state.len = context->buffer.position;
-    
-    /* ignore whitespace at the begginig */
-    SCPI_LexWhiteSpace(&state, &tmp);
-    
-    SCPI_LexProgramHeader(&state, &header);
-    
-    SCPI_LexWhiteSpace(&state, &tmp);
-    
-    SCPI_ParseProgramDate(context, &state, &token);
-    
-    SCPI_LexWhiteSpace(&state, &tmp);
-    
-    {
-        SCPI_LexComma(&state, &token);
-        
-        SCPI_LexWhiteSpace(&state, &tmp);
-        
-        SCPI_ParseProgramDate(context, &state);
-        
-        SCPI_LexWhiteSpace(&state, &tmp);
+    int result = 0;
+    int wsLen;
+    int suffixLen;
+    int realLen = 0;
+    realLen += SCPI_LexWhiteSpace(state, &tmp);
+
+    if (result == 0) result = SCPI_LexNondecimalNumericData(state, token);
+    if (result == 0) result = SCPI_LexCharacterProgramData(state, token);
+    if (result == 0) {
+        result = SCPI_LexDecimalNumericProgramData(state, token);
+        if (result != 0) {
+            wsLen = SCPI_LexWhiteSpace(state, &tmp);
+            suffixLen = SCPI_LexSuffixProgramData(state, &tmp);
+            if (suffixLen > 0) {
+                token->len += wsLen + suffixLen;
+                token->type = TokDecimalNumericProgramDataWithSuffix;
+                result = token->len;
+            }
+        }
     }
-    
-    SCPI_LexNewLine(&state, &tmp);
+
+    if (result == 0) result = SCPI_LexStringProgramData(state, token);
+    if (result == 0) result = SCPI_LexArbitraryBlockProgramData(state, token);
+    if (result == 0) result = SCPI_LexProgramExpression(state, token);
+
+    realLen += SCPI_LexWhiteSpace(state, &tmp);
+
+    return result + realLen;
+}
+
+int SCPI_ParseAllProgramData(lex_state_t * state, token_t * token, int * numberOfParameters) {
+
+    int result;
+    token_t tmp;
+    int paramCount = 0;
+
+    token->len = -1;
+    token->type = TokAllProgramData;
+    token->ptr = state->pos;
+
+
+    for (result = 1; result != 0; result = SCPI_LexComma(state, &tmp)) {
+        token->len += result;
+
+        if (result == 0) {
+            token->type = TokUnknown;
+            token->len = 0;
+            paramCount = -1;
+            break;
+        }
+
+        result = SCPI_ParseProgramData(state, &tmp);
+        if (tmp.type != TokUnknown) {
+            token->len += result;
+        } else {
+            token->type = TokUnknown;
+            token->len = 0;
+            paramCount = -1;
+            break;
+        }
+        paramCount++;
+    }
+
+    if (token->len == -1) {
+        token->len = 0;
+    }
+
+    if (numberOfParameters != NULL) {
+        *numberOfParameters = paramCount;
+    }
+    return token->len;
+}
+
+static void invalidateToken(token_t * token, const char * ptr) {
+    token->len = 0;
+    token->ptr = ptr;
+    token->type = TokUnknown;
+}
+
+int SCPI_DetectProgramMessageUnit(scpi_parser_state_t * state, const char * buffer, int len) {
+    lex_state_t lex_state;
+    token_t tmp;
+    int result = 0;
+
+    lex_state.buffer = lex_state.pos = buffer;
+    lex_state.len = len;
+    state->numberOfParameters = 0;
+
+    /* ignore whitespace at the begginig */
+    SCPI_LexWhiteSpace(&lex_state, &tmp);
+
+    if (SCPI_LexProgramHeader(&lex_state, &state->programHeader) >= 0) {
+        if (SCPI_LexWhiteSpace(&lex_state, &tmp) > 0) {
+            SCPI_ParseAllProgramData(&lex_state, &state->programData, &state->numberOfParameters);
+        } else {
+            invalidateToken(&state->programData, lex_state.pos);
+        }
+    } else {
+        invalidateToken(&state->programHeader, lex_state.buffer);
+        invalidateToken(&state->programData, lex_state.buffer);
+    }
+
+    if (result == 0) result = SCPI_LexNewLine(&lex_state, &tmp);
+    if (result == 0) result = SCPI_LexSemicolon(&lex_state, &tmp);
+
+    if (!SCPI_LexIsEos(&lex_state) && (result == 0)) {
+        lex_state.pos++;
+
+        state->programHeader.len = 1;
+        state->programHeader.type = TokInvalid;
+
+        invalidateToken(&state->programData, lex_state.buffer);        
+    }
+
+    if (TokSemicolon == tmp.type) {
+        state->termination = PmutSemicolon;
+    } else if (TokNewLine == tmp.type) {
+        state->termination = PmutNewLine;
+    } else {
+        state->termination = PmutNone;
+    }
+
+    return lex_state.pos - lex_state.buffer;
 }
 
 

--
Gitblit v1.9.1