Beispiel #1
0
        /// <summary>
        /// Generates a globals list from import directives
        /// </summary>
        /// <returns></returns>
        private string GetGlobals()
        {
            StringBuilder globals = new StringBuilder();

            this.Imports.Insert(0, "JsonML.BST");

            foreach (string import in this.Imports)
            {
                string ident = EcmaScriptIdentifier.EnsureValidIdentifier(import, true);

                if (String.IsNullOrEmpty(ident))
                {
                    continue;
                }

                if (globals.Length > 0)
                {
                    globals.Append(", ");
                }

                int dot = ident.IndexOf('.');
                globals.Append((dot < 0) ? ident : ident.Substring(0, dot));
            }

            return(globals.ToString());
        }
Beispiel #2
0
        private void ProcessDirective(string directiveName, IDictionary <string, string> attribs, int lineNumber)
        {
            if (String.IsNullOrEmpty(directiveName))
            {
                return;
            }

            switch (directiveName.ToLowerInvariant())
            {
            case "page":
            case "control":
            {
                this.JbstName = attribs.ContainsKey("name") ?
                                EcmaScriptIdentifier.EnsureValidIdentifier(attribs["name"], true) :
                                null;

                if (attribs.ContainsKey("AutoMarkup"))
                {
                    try
                    {
                        this.AutoMarkup = (AutoMarkupType)Enum.Parse(typeof(AutoMarkupType), attribs["AutoMarkup"], true);
                    }
                    catch
                    {
                        throw new ArgumentException("\"" + attribs["AutoMarkup"] + "\" is an invalid value for AutoMarkup.");
                    }
                }
                else
                {
                    this.AutoMarkup = AutoMarkupType.None;
                }

                string package = attribs.ContainsKey("import") ? attribs["import"] : null;
                if (!String.IsNullOrEmpty(package))
                {
                    string[] packages = package.Split(ImportDelim, StringSplitOptions.RemoveEmptyEntries);
                    this.Imports.AddRange(packages);
                }
                break;
            }

            case "import":
            {
                string package = attribs.ContainsKey("namespace") ? attribs["namespace"] : null;
                if (!String.IsNullOrEmpty(package))
                {
                    this.Imports.Add(package);
                }
                break;
            }

            default:
            {
                // not implemented
                break;
            }
            }
        }
Beispiel #3
0
 // TODO: create a custom TypeConverter to allow simple declarative assignment
 /// <summary>
 /// Gets and sets values in the JavaScript global namespace.
 /// </summary>
 /// <param name="varName"></param>
 /// <returns></returns>
 public object this[string varName]
 {
     get
     {
         if (!this.Data.ContainsKey(varName))
         {
             return(null);
         }
         return(this.Data[varName]);
     }
     set
     {
         varName            = EcmaScriptIdentifier.EnsureValidIdentifier(varName, true);
         this.Data[varName] = value;
     }
 }
Beispiel #4
0
 /// <summary>
 /// Ensures is a valid EcmaScript variable expression.
 /// </summary>
 /// <param name="varExpr">the variable expression</param>
 /// <returns>varExpr</returns>
 public static string EnsureValidIdentifier(string varExpr, bool nested)
 {
     return(EcmaScriptIdentifier.EnsureValidIdentifier(varExpr, nested, true));
 }
Beispiel #5
0
 /// <summary>
 /// Ctor
 /// </summary>
 public EcmaScriptIdentifier(string ident)
 {
     this.identifier = String.IsNullOrEmpty(ident) ? String.Empty :
                       EcmaScriptIdentifier.EnsureValidIdentifier(ident, true);
 }
 public JsonNameAttribute(string jsonName)
 {
     this.jsonName = EcmaScriptIdentifier.EnsureValidIdentifier(jsonName, nested: false);
 }