Tag constructTag(List<Token> toks) throws SDLParseException {
		if(toks.isEmpty())
			// we have to use -2 for position rather than -1 for unknown because
			// the parseException method adds 1 to line and position
			parseException("Internal Error: Empty token list", lineNumber, -2);
			
		Token t0 = toks.get(0);
		
		
		if(t0.literal) {
			toks.add(0, t0=new Token("content", -1, -1));
		} else if(t0.type!=Type.IDENTIFIER) {
			expectingButGot("IDENTIFIER", "" + t0.type + " (" + t0.text + ")",
					t0.line, t0.position);	
		}
		
		int size = toks.size();
		
		Tag tag = null;
		
		if(size==1) {
			tag = new Tag(t0.text);
		} else {
			int valuesStartIndex = 1;
			
			Token t1 = toks.get(1);
			
			if(t1.type==Type.COLON) {
				if(size==2 || toks.get(2).type!=Type.IDENTIFIER)
					parseException("Colon (:) encountered in unexpected " +
							"location.", t1.line, t1.position);
				
				Token t2 = toks.get(2);
				tag = new Tag(t0.text,t2.text);
				
				valuesStartIndex = 3;
			} else {
				tag = new Tag(t0.text);
			}
				
			// read values
			int i =addTagValues(tag, toks, valuesStartIndex);
			
			// read attributes
			if(i<size)
				addTagAttributes(tag, toks, i);
		}

		return tag;
	}