Esempio n. 1
0
		internal Token(Parser parser, string text, int line, int position) {
            this.parser = parser;
			this.text=text;

			this.line=line;
			this.position=position;
			size=text.Length;
			
			try {
				if(text.StartsWith("\"") || text.StartsWith("`")) {
					type=Type.STRING;
					obj=Parser.ParseString(text);
				} else if(text.StartsWith("'")) {
					type=Type.CHARACTER;
					obj=text[1];
				} else if(text.Equals("null")) {
					type=Type.NULL;
					obj=null;
				} else if(text.Equals("true") || text.Equals("on")) {
					type=Type.BOOLEAN;
					obj=true;
				} else if(text.Equals("false") || text.Equals("off")) {
					type=Type.BOOLEAN;
					obj=false;
				} else if(text.StartsWith("[")) {
					type=Type.BINARY;
					obj=Parser.ParseBinary(text);
				} else if(text[0]!='/' && text.IndexOf('/')!=-1 &&
						text.IndexOf(':')==-1) {
					type=Type.DATE;
                    obj = Parser.ParseDateTime(text);
				} else if(text[0]!=':' && text.IndexOf(':')!=-1) {
					type=Type.TIME;
                    obj = ParseTimeSpanWithZone(text);
				} else if("01234567890-.".IndexOf(text[0])!=-1) {
					type=Type.NUMBER;
					obj=Parser.ParseNumber(text);				
				} else if (text[0]=='{') {
                    type=Type.START_BLOCK;
                } else if (text[0]=='}') {
                    type=Type.END_BLOCK;
                } else if (text[0]=='=') {
                    type=Type.EQUALS;
                } else if (text[0]==':') {
                    type=Type.COLON;	
				} else {
                    type = Type.IDENTIFIER;
                }
			} catch(FormatException fe) {
				throw new SDLParseException(fe.Message, line,
						position);
			}

			punctuation = type==Type.COLON || type==Type.EQUALS ||
				type==Type.START_BLOCK || type==Type.END_BLOCK;
			literal =  type!=Type.IDENTIFIER && !punctuation;
		}
Esempio n. 2
0
        /// <summary>
        /// Add all the tags specified in the given Reader to this Tag.
        /// </summary>
        /// <param name="reader">A reader containing SDL source</param>
        /// <returns>This tag after adding all the children read from the reader
        /// </returns>
        /// <exception cref="System.IO.IOException">If there is an IO problem
        /// while reading the source</exception>
        /// <exception cref="SDLParseException">If the SDL input is malformed
        /// </exception>
        public Tag Read(TextReader reader) {
		    IList<Tag> tags = new Parser(reader).Parse();
		    foreach(Tag t in tags)
			    AddChild(t);
		    return this;
	    }