Esempio n. 1
0
        public void SetRange(int start, int end)
        {
            this.start = start;
            this.end   = end;

            reader.setoffset(start);
        }
Esempio n. 2
0
        public bool advance(Block preblock, Block curblock)
        {
            tok = TokenType.TXT;

            if (Src.Length == 0 && curblock.isLineHeadCmt == 1)
            {
                curblock.mRule = preblock.mRule;
                isNextLine     = true;
            }

            if (Src.Length == 0 && curblock.isLineHeadPart == 1)
            {
                curblock.PartID = preblock.PartID;
                scisNextLine    = true;
            }

            int c = reader.read();

            if (c == -1)
            {
                tok = TokenType.EOS;
                return(false);
            }

            switch (c)
            {
            case ' ':
            case 0x3000:
            case '\t':
                break;

            default:
                //TODO test
                if (curblock.isLineHeadCmt == 0)
                {
                    if (curblock.isLineHeadPart == 0)
                    {
                        if (paruleStartKeys.Contains((char)c))
                        {
                            char fc = (char)c;
                            foreach (var item in partRuleDic)
                            {
                                if (item.Key[0] == fc)
                                {
                                    var len = item.Value.start.Length;
                                    if (Offset - 1 + len <= Src.Length)
                                    {
                                        var text = Src.Substring(Offset - 1, len);
                                        if (text.ToString() == item.Key)
                                        {
                                            tok = TokenType.PartitionStart;
                                            if (curblock != null)
                                            {
                                                curblock.PartID = item.Value.id;
                                                scisNextLine    = true;
                                            }
                                            reader.setoffset(Offset + text.Length);
                                            return(true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (Offset - 1 == 0)
                        {
                            while (c != -1)
                            {
                                if (paruleStartKeys.Contains((char)c))
                                {
                                    StringBuilder buf = new StringBuilder();
                                    while (c != -1)
                                    {
                                        buf.Append((char)c);

                                        if (partRuleEndDic.ContainsKey(buf.ToString()))
                                        {
                                            if (preblock.PartID == partRuleEndDic[buf.ToString()].id)
                                            {
                                                var Eenelem = partRuleEndDic[buf.ToString()];
                                                tok = TokenType.PartitionEnd;

                                                curblock.PartID = Eenelem.id;
                                                scisNextLine    = false;

                                                reader.setoffset(Offset + buf.ToString().Length);

                                                return(true);
                                            }
                                        }
                                        c = reader.read();
                                    }
                                }
                                c = reader.read();
                            }

                            //Finish:

                            if (c == -1)
                            {
                                tok             = TokenType.Partition;
                                curblock.PartID = preblock.PartID;
                                scisNextLine    = true;
                            }
                            reader.setoffset(0);
                            c = reader.read();
                        }
                        else if (paruleStartKeys.Contains((char)c))
                        {
                            char fc = (char)c;
                            foreach (var item in partRuleDic)
                            {
                                if (item.Key[0] == fc)
                                {
                                    var len = item.Value.start.Length;
                                    if (Offset - 1 + len <= Src.Length)
                                    {
                                        var text = Src.Substring(Offset - 1, len);
                                        if (text.ToString() == item.Key)
                                        {
                                            tok = TokenType.PartitionStart;
                                            if (curblock != null)
                                            {
                                                curblock.PartID = item.Key;
                                                scisNextLine    = true;
                                            }
                                            reader.setoffset(Offset + text.Length);
                                            //break;
                                            return(true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (curblock.isLineHeadCmt == 0)       //0: 行頭がブロックコメントの内部ではない
                {
                    if (Char.IsDigit((char)c))
                    {
                        reader.unread();
                        lexDigit();
                        break;
                    }
                    else if (Util.isIdentifierPart((char)c))
                    {
                        reader.unread();
                        lexKeyWord();
                        break;
                    }
                    else
                    {
                        reader.unread();
                        lexSymbol(curblock);
                        break;
                    }
                }
                else       //1: 行頭がブロックコメントの内部

                {
                    if (Offset - 1 == 0)
                    {
                        reader.unread();
                        StringBuilder buf = new StringBuilder();
                        while (true)
                        {
                            c = reader.read();
                            if (c == -1)
                            {
                                break;
                            }
                            buf.Append((char)c);

                            string s   = buf.ToString();
                            string end = preblock.mRule.end;

                            if (s.EndsWith(end))
                            {
                                if (multiRuleEndDic.ContainsKey(end))
                                {
                                    var rule = multiRuleEndDic[end];
                                    if (rule.Detected(end, reader))
                                    {
                                        curblock.mRule = rule;
                                        //isNextLine = false;

                                        tok = rule.token;
                                        int len = rule.getLen(end, reader);
                                        reader.setoffset(len);
                                        OffsetLenAttr = new Tuple <int, int, Attribute>(0, len, rule.attr);
                                        //break;
                                        return(true);
                                    }
                                }
                            }
                        }

                        if (c == -1 && preblock.mRule != null && multiRuleDic.ContainsKey(preblock.mRule.start))
                        {
                            var enelem = multiRuleDic[preblock.mRule.start];
                            curblock.mRule = preblock.mRule;

                            tok           = TokenType.MultiLineStart;
                            OffsetLenAttr = new Tuple <int, int, Attribute>(0, Src.Length, enelem.attr);

                            reader.setoffset(Src.Length);
                        }
                        break;
                    }
                    else
                    {
                        if (Char.IsDigit((char)c))
                        {
                            reader.unread();
                            lexDigit();
                        }
                        else if (Util.isIdentifierPart((char)c))
                        {
                            reader.unread();
                            lexKeyWord();
                        }
                        else
                        {
                            reader.unread();
                            lexSymbol(curblock);
                        }
                    }
                }
                break;
            }
            return(true);
        }