예제 #1
0
 private static bool _check_syntax(List <YVALUE> list, YDEF.TreeSet ts)
 {
     for (var i = 0; i < list.Count; i++) // 走査
     {
         if (_isMatchAndMake(list, i, ts))
         {
             if (slagtool.sys.DEBUGLEVEL == 1)
             {
                 //sys.logline("match ..." + ": list[" + i + "] " + ts.ToString());
             }
             else
             {
                 sys.logline("\n match ..." + ": list[" + i + "] " + ts.ToString() + ">\n" + YDEF_DEBUG.PrintValue(list[i]));
             }
             return(true);
         }
     }
     return(false);
 }
예제 #2
0
        private static bool _isMatchAndMake(List <YVALUE> list, int index, YDEF.TreeSet ts)
        {
            Func <int, YVALUE> get = (n) => {
                if (n >= list.Count)
                {
                    return(null);
                }
                return(list[n]);
            };
            List <YVALUE> args         = new List <YVALUE>();
            int           removelength = ts.list.Count;

            for (int i = 0; i < ts.list.Count; i++)
            {
                var v = get(index + i);
                if (v == null)
                {
                    return(false);
                }

                if (i == 0 && ts.list.Count == 1 && v.IsType(ts.type))
                {
                    return(false);                                               //既に変換済み
                }
                int    tstype = 0;
                var    o      = ts.list[i];
                YVALUE nv     = null;
                if (o.GetType() == typeof(string))
                {
                    if (v.GetString() == (string)o)
                    {
                        nv = v.GetTerminalValue_ascent();
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    tstype = (int)o;
                    if (tstype == YDEF.REST) // ※RESTは特殊処理。EOLまでのすべて(除EOL)が入る
                    {
                        removelength--;      //本VALUE分を事前に引く

                        var restv = new YVALUE();
                        restv.type = YDEF.REST;
                        restv.list = new List <YVALUE>();

                        for (int j = index + i; j < list.Count; j++)
                        {
                            var v2 = get(j);
                            if (v2 != null && !v2.IsType(YDEF.EOL))
                            {
                                restv.list.Add(v2);
                                removelength++;
                            }
                            else
                            {
                                break;
                            }
                        }

                        args.Add(restv);
                        break;
                    }
                    else
                    {
                        if (v.IsType(tstype))
                        {
                            nv = v.FindValueByTravarse(tstype);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }

                if (nv != null)
                {
                    args.Add(nv);
                }
                else
                {
                    args.Add(v);
                }
            }

            //Yes, they match! then Make it.

            //var makefunc = (Func<int, YVALUE[], int[], YVALUE>)ts.make_func;

            var newv = ts.make_func(ts.type, args.ToArray(), ts.make_index.ToArray());

            list.RemoveRange(index, removelength);
            list.Insert(index, newv);

            return(true);
        }