コード例 #1
0
ファイル: Literals.cs プロジェクト: AndrewAGuy/XCScript
        public static IArgument TypeName(CharSource source, ref char chr)
        {
            // Arrive on seeing '/', get collections of names separated by '.'
            if (!source.Advance(out chr))
            {
                throw new FinalCharacterException("Expected type name");
            }

            var str = new StringBuilder();

            while (true)
            {
                str.Append(source.ReadName(ref chr));
                if (chr != '.')
                {
                    return(new TypeNameLiteral()
                    {
                        Value = str.ToString()
                    });
                }
                str.Append('.');
                // We now expect more
                if (!source.Advance(out chr))
                {
                    throw new FinalCharacterException("Expected further type name");
                }
                if (!CharSource.IsNameStart(chr))
                {
                    throw new InvalidCharacterException("Expected name start character: found " + chr);
                }
            }
        }
コード例 #2
0
ファイル: Literals.cs プロジェクト: AndrewAGuy/XCScript
 public static IArgument Default(CharSource source, ref char chr)
 {
     if (CharSource.IsNameStart(chr))
     {
         var name = source.ReadName(ref chr);
         if (bool.TryParse(name, out var bval))
         {
             return(new BooleanLiteral()
             {
                 Value = bval
             });
         }
         return(new NameArgument()
         {
             Value = name
         });
     }
     else if (CharSource.IsNumberStart(chr))
     {
         return(Number(source, ref chr));
     }
     throw new InvalidCharacterException($"Not a valid name or number start: '{chr}'");
 }