Example #1
0
        private void ParseCodeStreamObject(OfcToken me)
        {
            if (!Expect(OfcTokenType.KEYWORD))
            {
                throw new ParserException();
            }
            var text = _buffer[_position].Payload;

            if (text != "codeStream")
            {
                throw new ParserException();
            }
            Skip(1);
            if (!Expect(OfcTokenType.BRACES_OPEN))
            {
                throw new ParserException();
            }
            Skip(1);
            _hook.EnterCodeStreamDictionary(me.Payload ?? string.Empty);
            while (!(_eos && _length == 0))
            {
                if (!Needs(1))
                {
                    throw new ParserException();
                }
                var tkn = _buffer[_position];
                if (tkn.Type == OfcTokenType.KEYWORD || tkn.Type == OfcTokenType.STRING)
                {
                    Skip(1);
                    ParseEntryOrObject(tkn);
                }
                else if (tkn.Type == OfcTokenType.NUMBER || tkn.Type == OfcTokenType.PARENTHESE_OPEN)
                {
                    ParseAnonymousList();
                }
                else if (tkn.Type == OfcTokenType.SEMICOLON)
                {
                    Skip(1);
                }
                else if (tkn.Type == OfcTokenType.BRACES_CLOSE)
                {
                    _hook.LeaveCodeStreamDictionary();
                    Skip(1);
                    return;
                }
                else if (tkn.Type == OfcTokenType.HASHTAG)
                {
                    ParseDirective();
                }
                else
                {
                    throw new ParserException();
                }
            }
            throw new ParserException();
        }
Example #2
0
 private void ParseEntry(OfcToken me)
 {
     _hook.EnterEntry(me.Payload ?? string.Empty);
     while (!(_eos && _length == 0))
     {
         if (!Needs(1))
         {
             throw new ParserException();
         }
         var tkn = _buffer[_position];
         if (tkn.Type == OfcTokenType.SEMICOLON)
         {
             _hook.LeaveEntry();
             Skip(1);
             return;
         }
         ParseValue(tkn);
     }
     throw new ParserException();
 }
Example #3
0
        private void ParseEntryOrObject(OfcToken me)
        {
            if (!Needs(1))
            {
                throw new ParserException();
            }
            var c = _buffer[_position];

            if (c.Type == OfcTokenType.BRACES_OPEN)
            {
                Skip(1);
                ParseObject(me);
            }
            else if (c.Type == OfcTokenType.HASHTAG)
            {
                Skip(1);
                ParseCodeStreamObject(me);
            }
            else
            {
                ParseEntry(me);
            }
        }
Example #4
0
        private void ParseValue(OfcToken me)
        {
            switch (me.Type)
            {
            case OfcTokenType.KEYWORD:
                if (me.Payload == "List")
                {
                    Skip(1);
                    if (!Expect(new[] { OfcTokenType.CHEVRONS_OPEN, OfcTokenType.KEYWORD, OfcTokenType.CHEVRONS_CLOSE }))
                    {
                        throw new ParserException();
                    }
                    var         ltype = _buffer[_position + 1].Payload;
                    OfcListType type;
                    switch (ltype)
                    {
                    case "scalar":
                        type = OfcListType.Scalar;
                        break;

                    case "vector":
                        type = OfcListType.Vector;
                        break;

                    case "tensor":
                        type = OfcListType.Tensor;
                        break;

                    default:
                        throw new ParserException();
                    }
                    Skip(3);
                    if (!Needs(1))
                    {
                        throw new ParserException();
                    }
                    var amount = -1;
                    var c      = _buffer[_position];
                    if (c.Type == OfcTokenType.NUMBER)
                    {
                        amount = (int)double.Parse(c.Payload);
                        Skip(1);
                    }
                    if (!Expect(OfcTokenType.PARENTHESE_OPEN))
                    {
                        throw new ParserException();
                    }
                    Skip(1);
                    ParseList(type, amount);
                    return;
                }

                Skip(1);
                _hook.HandleKeyword(me.Payload ?? string.Empty);
                return;

            case OfcTokenType.NUMBER:
                if (Needs(2) && _buffer[_position + 1].Type == OfcTokenType.PARENTHESE_OPEN)
                {
                    Skip(2);
                    double a;
                    if (!double.TryParse(me.Payload, out a))
                    {
                        ParseAnonymousList();
                    }
                    else
                    {
                        ParseAnonymousList((int)a);
                    }
                    return;
                }

                Skip(1);
                _hook.HandleScalar(me.Payload);
                return;

            case OfcTokenType.STRING:
                Skip(1);
                _hook.HandleString(me.Payload ?? string.Empty);
                return;

            case OfcTokenType.BRACKETS_OPEN:
                Skip(1);
                if (!Expect(new[] { OfcTokenType.NUMBER, OfcTokenType.NUMBER, OfcTokenType.NUMBER, OfcTokenType.NUMBER, OfcTokenType.NUMBER, OfcTokenType.NUMBER, OfcTokenType.NUMBER, OfcTokenType.BRACKETS_CLOSE }))
                {
                    throw new ParserException();
                }
                var values = new string[7];
                for (var i = 0; i < 7; i++)
                {
                    values[i] = _buffer[_position + i].Payload;
                }
                Skip(8);
                _hook.HandleDimension(values);
                return;

            case OfcTokenType.PARENTHESE_OPEN:
                Skip(1);
                ParseAnonymousList();
                return;

            default:
                throw new ParserException();
            }
        }