Ejemplo n.º 1
0
        internal bool ReadTo(string str)
        {
            if (SrcIndex > SrcLength - str.Length)
            {
                return(false);
            }

            var p = Src.IndexOf(str, SrcIndex);

            if (p < 0)
            {
                return(false);
            }

            SrcIndex = p + 1;
            return(true);
        }
Ejemplo n.º 2
0
        public bool advance(Block preblock, Block curblock)
        {
            tok = TokenType.TXT;

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

            int c = reader.read();

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

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

            default:
                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)
                    {
                        int index;
                        if ((index = Src.IndexOf(preblock.mRule.end, 0)) >= 0)
                        {
                            string end  = preblock.mRule.end;
                            var    rule = multiRuleEndDic[end];
                            if (rule.Detected(end, reader))
                            {
                                curblock.mRule = rule;
                                tok            = TokenType.MultiLineEnd;
                                //int len = rule.getLen(end, reader);
                                int len = index + end.Length;
                                reader.setoffset(len);
                                OffsetLenAttr = new Tuple <int, int, Rule>(0, len, rule);
                                return(true);
                            }
                        }
                        else if (multiRuleDic.ContainsKey(preblock.mRule.start))
                        {
                            var rule = multiRuleDic[preblock.mRule.start];
                            curblock.mRule = preblock.mRule;
                            tok            = TokenType.MultiLineAllLine;
                            OffsetLenAttr  = new Tuple <int, int, Rule>(0, Src.Length, rule);
                            reader.setoffset(Src.Length);
                            return(true);
                        }

                        //{
                        //    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;
                        //                    tok = TokenType.MultiLineEnd;
                        //                    int len = rule.getLen(end, reader);
                        //                    reader.setoffset(len);
                        //                    OffsetLenAttr = new Tuple<int, int, Rule>(0, len, rule);
                        //                    //break;
                        //                    return true;
                        //                }
                        //            }
                        //        }
                        //    }

                        //    if (c == -1 && preblock.mRule != null && multiRuleDic.ContainsKey(preblock.mRule.start)) {
                        //        var enelem = multiRuleDic[preblock.mRule.start];
                        //        curblock.mRule = preblock.mRule;
                        //        //isNextLine = true;
                        //        //tok = TokenType.MultiLineStart;
                        //        tok = TokenType.MultiLineAllLine;
                        //        OffsetLenAttr = new Tuple<int, int, Rule>(0, Src.Length, enelem);
                        //        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);
        }