Exemplo n.º 1
0
 static void parseToValueFor(CKanFormat bar, string S)
 {
     TokenFile.Cursor Curs = bar.MoveCursTo(S);
     //WARNING This is awful, but I did it anyways....
     // This as side effect sets the global variable IndentationGloabalHack to the whitespace preceding nameField
     // just in case someone needs it later read allthe code everywher to see how this works or doesnt.
     // p.IndentationHack = Curs.TokenObj.WhiteSpace;
     Curs.advance();                            // advance over the just found identifier Token
     // does not accept EOL between name and ":"
     bar.expectToken(":", TokenCategory.Token); //advance over the ":"  NO EOLS allowed
     bar.skipEOL();                             // skips all EOLS and WS
     return;                                    // Cursor points to Value String OR [ OR { dependign on Namevalue Type
 }
Exemplo n.º 2
0
        public TokenFile.Cursor MoveCursTo(string Name)
        {
            NameCursorData NameMarker = Level1Name.Find(x => x.Name == Name);

            if (NameMarker == null)
            {
                throw new FormatException($"Fatal Error: Required Field Named \"{Name}\" is missing.", true);
            }
            TokenFile.Cursor Curs = NameMarker.setCursorLocation(this);
            if (Curs.TokenObj.theToken != Name)
            {
                throw new FormatException("name is not where it is Meant to be");
            }


            return(Curs);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This function does not fully validate the file against a Ckan schema.
        /// What it foes do is validate the format enough to be sure the file
        /// looks like std format Ckan file such as netkan produces.
        /// </summary>
        /// <remarks>
        /// There exist other json comaptible files (with strange 100% optional
        /// white space structures) that would validate as correct versus
        /// the json schemea that this code rejects, as it is too visually
        /// different and this code thus this code 'decides' that a human probably wont
        /// have properly validated the input file.
        /// </remarks>
        /// <returns>returns true if the file is sufficiently valid for our purposes.</returns>
        public bool validation(bool echo = false)
        {
            CkanLocaliserClass.DoingWhat.Push("Validation");
            // reset parser state.
            Level1Name.Clear();
            FileIsValid    = true;
            Level          = 0;
            AllowEOLs      = true;
            EOLMissedCount = 0;
            EOLExtraCount  = 0;

            // grammar:
            // <CkanFile>    := <CompoundValue> <EOF>
            Curs = TokFile.getCursor(echo);
            try
            {
                parseCompound();

                // grammar:
                // <EOF> := <EOL> >spaces tabs etc< / physical end of file.
                // <EOF> := >spaces tabs etc< / physical end of file.
                if (Curs.TokenObj.isCategory(TokenCategory.tokEOL))
                {   // alow 1 optional EOL then expect the EOF.
                    expectToken(TokenCategory.tokEOL);
                }
                expectToken(TokenCategory.tokEOF); // may have leading spaces.
            } catch (FormatException fe)
            {
                Console.WriteLine($"While Doing : {CkanLocaliserClass.WhatString()} ");
                Console.WriteLine(fe.Cause);
                FileIsValid = false;
                CkanLocaliserClass.DoingWhat.Pop();
                return(false);
            }
            CkanLocaliserClass.DoingWhat.Pop();
            return(true);
        }