Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Started info subcommand pastexpected.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wip
Files: files | file ages | folders
SHA3-256: 78b0aac051f78009a66b71dcea26677f2302c635b611d729ddb56fe4d54d8b10
User & Date: rolf 2019-10-10 01:50:15
Context
2019-10-11
11:54
Merged from schema. check-in: 6165f6c203 user: rolf tags: wip
2019-10-10
01:50
Started info subcommand pastexpected. check-in: 78b0aac051 user: rolf tags: wip
2019-10-09
16:40
Added subcommand nextexpected to the info method of schema commands. check-in: c9fd675e9f user: rolf tags: schema
Changes

Changes to generic/schema.c.

758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
....
2970
2971
2972
2973
2974
2975
2976





































2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
....
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
....
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123


3124

3125





3126
3127
3128
3129
3130
3131
3132
3133
3134


3135


3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
        stackElm = TMALLOC (SchemaValidationStack);
    }
    memset (stackElm, 0, sizeof (SchemaValidationStack));
    stackElm->pattern = pattern;
    return stackElm;
}

/* The ac argument is the currend looked at child of the stack top
 * (which is not pattern, in case the looked ad child of the stack top
 * is SCHEMA_CTYPE_CHOICE). */
static void
pushToStack (
    SchemaData *sdata,
    SchemaCP *pattern,
    int ac
    )
{
................................................................................
        se->down->hasMatched = 1;
        rc = getNextExpected (sdata, se->down, interp, seenCPs, rObj);
        se->down->hasMatched = hm;
        return rc;
    }
    return 1;
}






































static int
schemaInstanceInfoCmd (
    SchemaData *sdata,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[]
    )
{
    int methodIndex, len, i, hnew;
    Tcl_HashEntry *h;
    SchemaCP *cp;
    SchemaValidationStack *se;
    void *ns;
    Tcl_Obj *rObj, *r2Obj, *thisObj;
    Tcl_HashTable localHash;
    Tcl_HashSearch search;
    
    static const char *schemaInstanceInfoMethods[] = {
        "validationstate", "vstate", "definedElements", "stack", "toplevel",
        "pastexpected", "nextexpected", "definition", NULL
    };
    enum schemaInstanceInfoMethod {
        m_validationstate, m_vstate, m_definedElements, m_stack, m_toplevel,
................................................................................
            SetBooleanResult (0);
        } else {
            SetBooleanResult (1);
        }
        return TCL_OK;

    case m_nextexpected:
        if (sdata->validationState == VALIDATION_ERROR) {
            SetResult ("Validation command in error state.");
            return TCL_ERROR;
        } else if (sdata->validationState == VALIDATION_FINISHED) {
            return TCL_OK;
        }
        if (!sdata->stack) {
            if (sdata->start) {
                Tcl_AppendElement (interp, sdata->start);
                if (sdata->startNamespace) {
                    Tcl_AppendElement (interp, sdata->startNamespace);
................................................................................
                definedElements (sdata, interp);
            }
        } else {
            rObj = Tcl_NewObj();
            Tcl_InitHashTable (&localHash, TCL_ONE_WORD_KEYS);
            getNextExpected (sdata, sdata->stack, interp, &localHash, rObj);
            Tcl_DeleteHashTable (&localHash);
            Tcl_ListObjLength (interp, rObj, &len);
            if (len <= 1) {
                Tcl_SetObjResult (interp, rObj);
            } else {
                Tcl_InitHashTable (&localHash, TCL_STRING_KEYS);
                for (i = 0; i < len; i++) {
                    Tcl_ListObjIndex (interp, rObj, i, &thisObj);
                    h = Tcl_CreateHashEntry (
                        &localHash, Tcl_GetString (thisObj), &hnew
                        );
                    if (hnew) {
                        Tcl_SetHashValue (h, thisObj);


                    }

                }





                r2Obj = Tcl_NewObj();
                len = 0;
                for (h = Tcl_FirstHashEntry (&localHash, &search);
                     h != NULL;
                     h = Tcl_NextHashEntry (&search)) {
                    Tcl_ListObjAppendElement (interp, r2Obj,
                                              Tcl_GetHashValue (h));
                    len++;
                }


                Tcl_DeleteHashTable (&localHash);


                Tcl_DecrRefCount (rObj);
                Tcl_SetObjResult (interp, r2Obj);
            }
        }
        return TCL_OK;
        
    case m_pastexpected:
        break;
        
    case m_definition:
        if (objc < 3 && objc > 4) {
            Tcl_WrongNumArgs (interp, 1, objv, "name ?namespace?");
            return TCL_ERROR;
        }







<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









|




|

<







 







|
<
<
|







 







<
<
|
<
<
<
<
<
<
<
<
<
>
>
|
>
|
>
>
>
>
>
|
<
<
<
<
<
<
<
<
>
>
|
>
>
|
<
|
|
<
<
<







758
759
760
761
762
763
764



765
766
767
768
769
770
771
....
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026

3027
3028
3029
3030
3031
3032
3033
....
3118
3119
3120
3121
3122
3123
3124
3125


3126
3127
3128
3129
3130
3131
3132
3133
....
3136
3137
3138
3139
3140
3141
3142


3143









3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154








3155
3156
3157
3158
3159
3160

3161
3162



3163
3164
3165
3166
3167
3168
3169
        stackElm = TMALLOC (SchemaValidationStack);
    }
    memset (stackElm, 0, sizeof (SchemaValidationStack));
    stackElm->pattern = pattern;
    return stackElm;
}




static void
pushToStack (
    SchemaData *sdata,
    SchemaCP *pattern,
    int ac
    )
{
................................................................................
        se->down->hasMatched = 1;
        rc = getNextExpected (sdata, se->down, interp, seenCPs, rObj);
        se->down->hasMatched = hm;
        return rc;
    }
    return 1;
}

static Tcl_Obj *
unifyMatchList (
    Tcl_Interp *interp,
    Tcl_HashTable *htable,
    Tcl_Obj *list
    )
{
    int len, i, hnew;
    Tcl_HashEntry *h;
    Tcl_Obj *rObj, *thisObj;
    Tcl_HashSearch search;
    
    rObj = Tcl_NewObj();
    Tcl_ListObjLength (interp, list, &len);
    if (len == 0) return rObj;
    if (len == 1) {
        Tcl_ListObjIndex (interp, list, 0, &thisObj);
        Tcl_ListObjAppendElement (interp, rObj, thisObj);
        return rObj;
    }
    Tcl_InitHashTable (htable, TCL_STRING_KEYS);
    for (i = 0; i < len; i++) {
        Tcl_ListObjIndex (interp, list, i, &thisObj);
        h = Tcl_CreateHashEntry (htable, Tcl_GetString (thisObj), &hnew);
        if (hnew) {
            Tcl_SetHashValue (h, thisObj);
        }
    }
    for (h = Tcl_FirstHashEntry (htable, &search);
         h != NULL;
         h = Tcl_NextHashEntry (&search)) {
        Tcl_ListObjAppendElement (interp, rObj, Tcl_GetHashValue (h));
    }
    Tcl_DeleteHashTable (htable);
    return rObj;
}

static int
schemaInstanceInfoCmd (
    SchemaData *sdata,
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const objv[]
    )
{
    int methodIndex;
    Tcl_HashEntry *h;
    SchemaCP *cp;
    SchemaValidationStack *se;
    void *ns;
    Tcl_Obj *rObj;
    Tcl_HashTable localHash;

    
    static const char *schemaInstanceInfoMethods[] = {
        "validationstate", "vstate", "definedElements", "stack", "toplevel",
        "pastexpected", "nextexpected", "definition", NULL
    };
    enum schemaInstanceInfoMethod {
        m_validationstate, m_vstate, m_definedElements, m_stack, m_toplevel,
................................................................................
            SetBooleanResult (0);
        } else {
            SetBooleanResult (1);
        }
        return TCL_OK;

    case m_nextexpected:
        if (sdata->validationState == VALIDATION_ERROR


            || sdata->validationState == VALIDATION_FINISHED) {
            return TCL_OK;
        }
        if (!sdata->stack) {
            if (sdata->start) {
                Tcl_AppendElement (interp, sdata->start);
                if (sdata->startNamespace) {
                    Tcl_AppendElement (interp, sdata->startNamespace);
................................................................................
                definedElements (sdata, interp);
            }
        } else {
            rObj = Tcl_NewObj();
            Tcl_InitHashTable (&localHash, TCL_ONE_WORD_KEYS);
            getNextExpected (sdata, sdata->stack, interp, &localHash, rObj);
            Tcl_DeleteHashTable (&localHash);


            Tcl_SetObjResult (interp, unifyMatchList (interp, &localHash,









                                                      rObj));
            Tcl_DecrRefCount (rObj);
        }
        return TCL_OK;
        
    case m_pastexpected:
        if (sdata->validationState == VALIDATION_READY || !sdata->stack)
            return TCL_OK;
        se = sdata->lastMatchse;
        if (!se) se = sdata->stack;
        rObj = Tcl_NewObj();








        Tcl_InitHashTable (&localHash, TCL_ONE_WORD_KEYS);
        getNextExpected (sdata, se, interp, &localHash, rObj);
        Tcl_DeleteHashTable (&localHash);
        Tcl_SetObjResult (interp, unifyMatchList (interp, &localHash,
                                                  rObj));
        Tcl_DecrRefCount (rObj);

        
        



        break;
        
    case m_definition:
        if (objc < 3 && objc > 4) {
            Tcl_WrongNumArgs (interp, 1, objv, "name ?namespace?");
            return TCL_ERROR;
        }

Changes to generic/schema.h.

154
155
156
157
158
159
160

161
162
163
164
165
166
167
    SchemaQuant *quants;
    unsigned int numQuants;
    unsigned int quantsSize;
    int       currentEvals;
    int       cleanupAfterEval;
    int       evalError;
    Tcl_Obj  *reportCmd;

    Tcl_Obj **evalStub;
    Tcl_Obj **textStub;
    char *currentNamespace;
    int   defineToplevel;
    int   isTextConstraint;
    int   isAttributeConstaint;
    SchemaCP *cp;







>







154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
    SchemaQuant *quants;
    unsigned int numQuants;
    unsigned int quantsSize;
    int       currentEvals;
    int       cleanupAfterEval;
    int       evalError;
    Tcl_Obj  *reportCmd;
    SchemaValidationStack *lastMatchse;
    Tcl_Obj **evalStub;
    Tcl_Obj **textStub;
    char *currentNamespace;
    int   defineToplevel;
    int   isTextConstraint;
    int   isAttributeConstaint;
    SchemaCP *cp;

Changes to tests/schema.test.

4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
....
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
....
5021
5022
5023
5024
5025
5026
5027




























5028
5029
5030
5031
5032
5033
5034
        s event start doc
        lappend result {*}[lsort [s info nextexpected]]
        s delete
    }
    set result
} {a b c a b c d a b c d}

test schema-17.11 {info nextexpected interleave} {
    set defs {
        {
            group + {
                element c ?
                element a ?
                element b ?
            }
................................................................................
        s event end
        set result [lsort [s info nextexpected]]
        s delete
    }
    set result
} {a b c d}

test schema-17.12 {info nextexpected interleave} {
    tdom::schema s
    s define {
        prefixns {ns1 http://foo.bar}
        defelement doc {
            element a
            any
            any ns1 ?
................................................................................
    set result [lsort [s info nextexpected]]
    s event start something
    s event end
    lappend result {*}[lsort [s info nextexpected]]
    s delete
    set result
} {{<any> {}} {<any> http://foo.bar} b}





























proc schema-18 {args} {
    lappend ::result {*}$args
}
test schema-18.1 {reportcmd} {
    tdom::schema s
    s define {







|







 







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
....
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
....
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
        s event start doc
        lappend result {*}[lsort [s info nextexpected]]
        s delete
    }
    set result
} {a b c a b c d a b c d}

test schema-17.11 {info nextexpected} {
    set defs {
        {
            group + {
                element c ?
                element a ?
                element b ?
            }
................................................................................
        s event end
        set result [lsort [s info nextexpected]]
        s delete
    }
    set result
} {a b c d}

test schema-17.12 {info nextexpected} {
    tdom::schema s
    s define {
        prefixns {ns1 http://foo.bar}
        defelement doc {
            element a
            any
            any ns1 ?
................................................................................
    set result [lsort [s info nextexpected]]
    s event start something
    s event end
    lappend result {*}[lsort [s info nextexpected]]
    s delete
    set result
} {{<any> {}} {<any> http://foo.bar} b}

proc schema-17.13 {scmd} {
    global result
    lappend result {*}[lsort [$scmd info pastexpected]]
}
test schema-17.13 {info pastexpected} {
    set defs {
        {
            group + {
                element c ?
                element a ?
                element b ?
                tcl schema-17.13
            }
            element d
        }
    }
    set result [list]
    foreach def $defs {
        tdom::schema s
        s defelement doc $def
        s event start doc
        puts [s info nextexpected]
        catch {s event start unknownElement}
        s delete
    }
    set result
} {a b c}

proc schema-18 {args} {
    lappend ::result {*}$args
}
test schema-18.1 {reportcmd} {
    tdom::schema s
    s define {