Ejemplo n.º 1
0
        public void ReadChordValid(string Input, string ExpectedOutput)
        {
            SyntaxReader SR     = new SyntaxReader(new RuntimeManager("Test"));
            Chord        a      = SR.ReadChord(Input);
            string       Output = a.ToString().Trim('^', ' ');

            Assert.AreEqual(ExpectedOutput, Output);
        }
Ejemplo n.º 2
0
        public void SetReseveredWordsToUpperCase()
        {
            Regex        r = new Regex(@"\w+|[^A-Za-z0-9_ \f\t\v]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            Match        m;
            SyntaxReader syntaxReader = new SyntaxReader();

            for (m = r.Match(this.Text); m.Success; m = m.NextMatch())
            {
                if (syntaxReader.IsReservedWord(m.Value.ToUpper()))
                {
                    this.Document.Replace(m.Index, m.Length, m.Value.ToUpper());
                }
            }
        }
		public override IResource GetResource(IResourceLocation location)
		{
			FileLocation l = location as FileLocation;
			if (l == null) return null;
			if (!l.FileName.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase))
			{
				ExternalLocation el = l as ExternalLocation;
				if (el == null || el.Mime == null || (!el.Mime.EndsWith("/javascript", StringComparison.InvariantCultureIgnoreCase) && !el.Mime.EndsWith("/x-javascript", StringComparison.InvariantCultureIgnoreCase)))
					return null;
			}

			Stream s = l.GetStream();
			if (s == null) return null;

			SyntaxReader reader;
			using (TextReader r = new StreamReader(s))
				reader = new SyntaxReader(r, true, location, ".js");

			Compress compress = reader.Compress == null ? Compress.Release : (Compress)Enum.Parse(typeof(Compress), reader.Compress, true);
			bool cmpr = (compress == Compress.Always || (compress == Compress.Release && !Configuration.DebugMode));

			var includes = new List<IResource>();
			var builds = new List<IResource>();
			var references = new List<IResource>();
			if (reader.References != null)
				foreach (var rl in reader.References)
				{
					var resource = Configuration.GetResource(rl);
					if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl));
					if (resource is IJavaScriptResource && !((IJavaScriptResource)resource).CanReferenceJavaScript)
						includes.Add(resource);
					else if (!references.Contains(resource))
						references.Add(resource);
				}
			if (reader.Includes != null)
				foreach (var rl in reader.Includes)
				{
					var resource = Configuration.GetResource(rl);
					if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl));
					if (resource is IJavaScriptResource && (!Configuration.DebugMode || !((IJavaScriptResource)resource).CanReferenceJavaScript))
						includes.Add(resource);
					else if (!references.Contains(resource))
						references.Add(resource);
				}
			if (reader.Builds != null)
				foreach (var rl in reader.Builds)
				{
					var resource = Configuration.GetResource(rl);
					if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl));
					if (resource is IJavaScriptResource)
					{
						if (!Configuration.DebugMode)
							builds.Add(resource);
						else if (!((IJavaScriptResource)resource).CanReferenceJavaScript)
							includes.Add(resource);
						else if (!references.Contains(resource))
							references.Add(resource);
					}
					else if (!references.Contains(resource))
						references.Add(resource);
				}

			IResourceLocation rf = FileResourceHelper.GetRelatedResourceLocation(location);
			if (rf != null)
			{
				IResource rs = Configuration.GetResource(rf);
				if (rs != null)
				{
					if (rs is IJavaScriptResource && !Configuration.DebugMode)
						includes.Add(rs);
					else
						references.Add(rs);
				}
			}

			if ((reader.Compress == null || compress == Compress.Never) && includes.Count == 0 && builds.Count == 0 && !(l is EmbeddedLocation))
				return new PlainJavaScriptResource(references.Count > 0 ? references.ToArray() : null, l, reader.HasContent);
			else
				return new ExtendedJavaScriptResource(
					reader.Compress == null ? (bool?)null : cmpr,
					!Configuration.DebugMode,
					references.Count > 0 ? references.ToArray() : null,
					includes.Count > 0 ? includes.ToArray() : null,
					builds.Count > 0 ? builds.ToArray() : null,
					l,
					reader.HasContent);
		}
		public override IResource GetResource(IResourceLocation location)
		{
			FileLocation l = location as FileLocation;
			if (l == null) return null;
			if (!l.FileName.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase))
			{
				ExternalLocation el = l as ExternalLocation;
				if (el == null || el.Mime == null || !el.Mime.EndsWith("/css", StringComparison.InvariantCultureIgnoreCase))
					return null;
			}

			Stream s = l.GetStream();
			if (s == null) return null;

			SyntaxReader reader;
			using (TextReader r = new StreamReader(s))
				reader = new SyntaxReader(r, false, location, null);

			Compress compress = reader.Compress == null ? Compress.Release : (Compress)Enum.Parse(typeof(Compress), reader.Compress, true);
			bool cmpr = (compress == Compress.Always || (compress == Compress.Release && !Configuration.DebugMode));

			var includes = new List<ICSSResource>();
			var imageIncludes = new List<IImageResource>();
			var builds = new List<ICSSResource>();
			var references = new List<IResource>();
			if (reader.References != null)
				foreach (var rl in reader.References)
				{
					var resource = Configuration.GetResource(rl);
					if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl));
					if (resource is ICSSResource && !((ICSSResource)resource).CanReferenceCSS)
						includes.Add((ICSSResource)resource);
					else if (!references.Contains(resource))
						references.Add(resource);
				}
			if (reader.Includes != null)
				foreach (var rl in reader.Includes)
				{
					if (location.Equals(rl)) continue;
					var resource = Configuration.GetResource(rl);
					if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl));
					if (resource is ICSSResource && (!Configuration.DebugMode || !((ICSSResource)resource).CanReferenceCSS))
						includes.Add((ICSSResource)resource);
					else if (resource is IImageResource)
					{
						if (!Configuration.DebugMode)
							imageIncludes.Add((IImageResource)resource);
					}
					else if (!references.Contains(resource))
						references.Add(resource);
				}
			if (reader.Builds != null)
				foreach (var rl in reader.Builds)
				{
					var resource = Configuration.GetResource(rl);
					if (resource == null) throw new Exception(String.Format("Resource '{0}' is not a valid resource.", rl));
					if (resource is ICSSResource)
					{
						if (!Configuration.DebugMode)
							builds.Add((ICSSResource)resource);
						else if (!((ICSSResource)resource).CanReferenceCSS)
							includes.Add((ICSSResource)resource);
						else if (!references.Contains(resource))
							references.Add(resource);
					}
					else if (resource is IImageResource)
					{
						if (!Configuration.DebugMode)
							imageIncludes.Add((IImageResource)resource);
					}
					else if (!references.Contains(resource))
						references.Add(resource);
				}
			if ((reader.Compress == null || compress == Compress.Never) && imageIncludes.Count == 0 && includes.Count == 0 && builds.Count == 0 && l is VirtualPathLocation)
				return new PlainCSSResource(references.Count > 0 ? references.ToArray() : null, l, reader.HasContent);
			else
				return new ExtendedCSSResource(
					reader.Compress == null ? (bool?)null : cmpr,
					!Configuration.DebugMode,
					references.Count > 0 ? references.ToArray() : null,
					imageIncludes.Count > 0 ? imageIncludes.ToArray() : null,
					includes.Count > 0 ? includes.ToArray() : null,
					builds.Count > 0 ? builds.ToArray() : null,
					l,
					reader.HasContent);
		}