当前位置: 首页>>代码示例>>C#>>正文


C# Reader.next方法代码示例

本文整理汇总了C#中Reader.next方法的典型用法代码示例。如果您正苦于以下问题:C# Reader.next方法的具体用法?C# Reader.next怎么用?C# Reader.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Reader的用法示例。


在下文中一共展示了Reader.next方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: read_atom

 public static MalVal read_atom(Reader rdr)
 {
     string token = rdr.next();
     string pattern = @"(^-?[0-9]+$)|(^-?[0-9][0-9.]*$)|(^nil$)|(^true$)|(^false$)|^("".*"")$|:(.*)|(^[^""]*$)";
     Regex regex = new Regex(pattern);
     Match match = regex.Match(token);
     //Console.WriteLine("token: ^" + token + "$");
     if (!match.Success) {
         throw new ParseError("unrecognized token '" + token + "'");
     }
     if (match.Groups[1].Value != String.Empty) {
         return new Mal.types.MalInt(int.Parse(match.Groups[1].Value));
     } else if (match.Groups[3].Value != String.Empty) {
         return Mal.types.Nil;
     } else if (match.Groups[4].Value != String.Empty) {
         return Mal.types.True;
     } else if (match.Groups[5].Value != String.Empty) {
         return Mal.types.False;
     } else if (match.Groups[6].Value != String.Empty) {
         string str = match.Groups[6].Value;
         str = str.Substring(1, str.Length-2)
             .Replace("\\\"", "\"")
             .Replace("\\n", "\n");
         return new Mal.types.MalString(str);
     } else if (match.Groups[7].Value != String.Empty) {
         return new Mal.types.MalString("\u029e" + match.Groups[7].Value);
     } else if (match.Groups[8].Value != String.Empty) {
         return new Mal.types.MalSymbol(match.Groups[8].Value);
     } else {
         throw new ParseError("unrecognized '" + match.Groups[0] + "'");
     }
 }
开发者ID:nboyd,项目名称:mal,代码行数:32,代码来源:reader.cs

示例2: read_form

        public static MalVal read_form(Reader rdr)
        {
            string token = rdr.peek();
            if (token == null) { throw new MalContinue(); }
            MalVal form = null;

            switch (token) {
                case "'": rdr.next();
                    return new MalList(new MalSymbol("quote"),
                                       read_form(rdr));
                case "`": rdr.next();
                    return new MalList(new MalSymbol("quasiquote"),
                                       read_form(rdr));
                case "~":
                    rdr.next();
                    return new MalList(new MalSymbol("unquote"),
                                       read_form(rdr));
                case "[email protected]":
                    rdr.next();
                    return new MalList(new MalSymbol("splice-unquote"),
                                       read_form(rdr));
                case "^": rdr.next();
                    MalVal meta = read_form(rdr);
                    return new MalList(new MalSymbol("with-meta"),
                                       read_form(rdr),
                                       meta);
                case "@": rdr.next();
                    return new MalList(new MalSymbol("deref"),
                                       read_form(rdr));

                case "(": form = read_list(rdr, new MalList(), '(' , ')'); break;
                case ")": throw new ParseError("unexpected ')'");
                case "[": form = read_list(rdr, new MalVector(), '[' , ']'); break;
                case "]": throw new ParseError("unexpected ']'");
                case "{": form = read_hash_map(rdr); break;
                case "}": throw new ParseError("unexpected '}'");
                default:  form = read_atom(rdr); break;
            }
            return form;
        }
开发者ID:nboyd,项目名称:mal,代码行数:40,代码来源:reader.cs

示例3: read_list

        public static MalVal read_list(Reader rdr, MalList lst, char start, char end)
        {
            string token = rdr.next();
            if (token[0] != start) {
                throw new ParseError("expected '" + start + "'");
            }

            while ((token = rdr.peek()) != null && token[0] != end) {
                lst.conj_BANG(read_form(rdr));
            }

            if (token == null) {
                throw new ParseError("expected '" + end + "', got EOF");
            }
            rdr.next();

            return lst;
        }
开发者ID:nboyd,项目名称:mal,代码行数:18,代码来源:reader.cs


注:本文中的Reader.next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。