Diff
Not logged in

Differences From Artifact [faac545a7e]:

To Artifact [a1c51aeda7]:


465
466
467
468
469
470
471
472

473
474
475
476
477
478
479
465
466
467
468
469
470
471

472
473
474
475
476
477
478
479







-
+







	INVALID		/* CAN */,	INVALID		/* EM */,
	INVALID		/* SUB */,	INVALID		/* ESC */,
	INVALID		/* FS */,	INVALID		/* GS */,
	INVALID		/* RS */,	INVALID		/* US */,
	INVALID		/* SPACE */,	0		/* ! or != */,
	QUOTED		/* " */,	INVALID		/* # */,
	VARIABLE	/* $ */,	MOD		/* % */,
	0		/* & or && */,	INVALID		/* ' */,
	0		/* & or && */,	VARNAME		/* ' */,
	OPEN_PAREN	/* ( */,	CLOSE_PAREN	/* ) */,
	0		/* * or ** */,	PLUS		/* + */,
	COMMA		/* , */,	MINUS		/* - */,
	0		/* . */,	DIVIDE		/* / */,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0,			/* 0-9 */
	0		/* : or := */,	SEPARATOR	/* ; */,
	0		/* < or << or <= */,
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771

772
773
774
775
776
777
778






779
780
781


782
783
784
785
786
787

788
789
790



791

792
793
794
795
796
797
798
730
731
732
733
734
735
736



































737
738






739
740
741
742
743
744
745


746
747

748
749
750
751
752
753



754
755
756

757
758
759
760
761
762
763
764







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+
-





+
-
-
-
+
+
+
-
+







		 * exceptions are that when a bareword is followed by an open
		 * paren, it might be a function call, and when the bareword
		 * is a legal literal boolean value, we accept that as well.
		 */

		if (start[scanned+TclParseAllWhiteSpace(
			start+scanned, numBytes-scanned)] == '(') {

		    /* Look ahead for assignment operator */

		    /* 
		     * TODO: this can probably be simplified.  
		     * For now, it is working. 
		     */

		    Tcl_Parse vparse;
		    const char *varend, *varstart = &start[TclParseAllWhiteSpace(start, numBytes)];
		    int code, len;
		    TclParseInit(interp, varstart, numBytes, &vparse);
		    code = Tcl_ParseVarName(NULL, varstart, numBytes, &vparse, 0);
		    if (code != TCL_OK) {
			//fprintf(stderr, "Replace me with proper error!\n");
		    }
		    len = vparse.tokenPtr[0].size;
		    varend = varstart+len;
		    Tcl_FreeParse(&vparse);

		    /* Look ahead for Assignment operator ':=' */
		    if (code == TCL_OK &&
			varend[TclParseAllWhiteSpace(varend,numBytes-len)] == ':' && 
			varend[TclParseAllWhiteSpace(varend,numBytes-len)+1] == '=') {

			lexeme = VARNAME;

			/* Adjust scanned bytes */
			scanned = varend-start;

			/* The variable name is tokenized below as a quoted string */

		    } else {

			lexeme = FUNCTION;
		    lexeme = FUNCTION;

			/*
			 * When we compile the expression we'll need the function
			 * name, and there's no place in the parse tree to store
			 * it, so we keep a separate list of all the function
			 * names we've parsed in the order we found them.
			 */
		    /*
		     * When we compile the expression we'll need the function
		     * name, and there's no place in the parse tree to store
		     * it, so we keep a separate list of all the function
		     * names we've parsed in the order we found them.
		     */

			Tcl_ListObjAppendElement(NULL, funcList, literal);
		    }
		    Tcl_ListObjAppendElement(NULL, funcList, literal);


		} else if (start[scanned+TclParseAllWhiteSpace(
			start+scanned, numBytes-scanned)] == ':' &&
			   start[scanned+TclParseAllWhiteSpace(
			start+scanned, numBytes-scanned)+1] == '=') {

		    Tcl_ListObjAppendElement(NULL, litList, literal);
		    /* Simple bareword */
		    lexeme = VARNAME;

		    complete = lastParsed = OT_LITERAL;
		    start += scanned;
		    numBytes -= scanned;
		    /* The variable name is stored as an OT_LITERAL below */
		    continue;

		} else if (Tcl_GetBooleanFromObj(NULL,literal,&b) == TCL_OK) {
		    lexeme = BOOLEAN;
		} else {
		    Tcl_DecrRefCount(literal);
		    msg = Tcl_ObjPrintf("invalid bareword \"%.*s%s\"",
			    (scanned < limit) ? scanned : limit - 3, start,
920
921
922
923
924
925
926



927
928
929






930
931
932


933
934
935


936
937
938


939
940
941
942
943
944
945
886
887
888
889
890
891
892
893
894
895



896
897
898
899
900
901



902
903



904
905



906
907
908
909
910
911
912
913
914







+
+
+
-
-
-
+
+
+
+
+
+
-
-
-
+
+
-
-
-
+
+
-
-
-
+
+







		Tcl_ListObjAppendElement(NULL, litList, literal);
		complete = lastParsed = OT_LITERAL;
		start += scanned;
		numBytes -= scanned;
		continue;

	    case VARNAME: {
                Tcl_Parse vparse;  int vcode, length;
                TclParseInit(NULL, start, numBytes, &vparse);
                vcode = Tcl_ParseVarName(NULL, start, numBytes, &vparse, 0);
		int length;
		TclGetStringFromObj(literal, &length);
		if (length < scanned) {
                length = vparse.tokenPtr[0].size;
                Tcl_FreeParse(&vparse);

                if (vcode == TCL_OK && length > 1) {
                   start++; length--; numBytes--;
                   scanned = length;
		    // Go tokenize the literal...
		    break;
		} else {
                   break;
                } else {
		    Tcl_ListObjAppendElement(NULL, litList, literal);
		    complete = lastParsed = OT_LITERAL;
		    start += scanned;
                   //fprintf(stderr, "VARNAME-1: code=%d,len=%d, \"%s\"\n",vcode,length,start);
                   start++; scanned = 1; numBytes--;
		    numBytes -= scanned;
		    continue;
		}
                   continue;
                }
	    } /* VARNAME case */

	    default:
		break;
	    }

	    /*
1382
1383
1384
1385
1386
1387
1388
1389

1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1402
1351
1352
1353
1354
1355
1356
1357

1358

1359
1360
1361

1362

1363
1364
1365
1366
1367
1368
1369







-
+
-



-
+
-







		if (incompletePtr->lexeme != OPEN_PAREN) {
		    TclNewLiteralStringObj(msg, "unbalanced close paren");
		    errCode = "UNBALANCED";
		    goto error;
		}
	    }

	    /* Enfocre LHS is literal, bareword, function
	    /* Enforce LHS is literal or bareword
	     * TODO: If function, convert to array reference
	     */
	    if (lexeme == ASSIGN) {
		if (complete != OT_LITERAL &&
		    complete != OT_TOKENS &&
		    complete != OT_TOKENS) {
		    complete != FUNCTION) {

		    TclNewLiteralStringObj(msg, "Target of assignment must be string");
		    errCode = "SURPRISE";
		    goto error;		    
		}
	    }