Exemplo n.º 1
0
 public Context(DocumentContext document, int startLineNumber, int startLinePosition, int startPosition, int endLineNumber, int endLinePosition, int endPosition, JSToken token)
     : this(document)
 {
     StartLineNumber = startLineNumber;
     StartLinePosition = startLinePosition;
     StartPosition = startPosition;
     EndLineNumber = endLineNumber;
     EndLinePosition = endLinePosition;
     EndPosition = endPosition;
     Token = token;
 }
Exemplo n.º 2
0
        internal DocumentContext DifferentFileContext(string fileContext)
        {
            // use the SAME parser and reported variable dictionary
            var documentContext = new DocumentContext(m_parser, Source)
            {
                IsGenerated = this.IsGenerated,
                FileContext = fileContext
            };

            documentContext.m_reportedVariables = this.m_reportedVariables;
            return documentContext;
        }
Exemplo n.º 3
0
        public Context(DocumentContext document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            Document = document;

            StartLineNumber = 1;
            EndLineNumber = 1;
            EndPosition = Document.Source.IfNotNull(s => s.Length);

            Token = JSToken.None;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates an instance of the JSParser class that can be used to parse the given source code.
        /// </summary>
        /// <param name="source">Source code to parse.</param>
        public JSParser(string source)
        {
            m_severity = 5;
            m_blockType = new List<BlockType>(16);
            m_labelTable = new Dictionary<string, LabelInfo>();
            m_noSkipTokenSet = new NoSkipTokenSet();
            m_importantComments = new List<Context>();

            m_document = new DocumentContext(this, source);
            m_scanner = new JSScanner(new Context(m_document));
            m_currentToken = new Context(m_document);

            // if the scanner encounters a special "globals" comment, it'll fire this event
            // at which point we will define a field with that name in the global scope. 
            m_scanner.GlobalDefine += (sender, ea) =>
                {
                    var globalScope = GlobalScope;
                    if (globalScope[ea.Name] == null)
                    {
                        var field = globalScope.CreateField(ea.Name, null, FieldAttributes.SpecialName);
                        globalScope.AddField(field);
                    }
                };

            // this event is fired whenever a ///#SOURCE comment is encountered
            m_scanner.NewModule += (sender, ea) =>
                {
                    m_newModule = true;
                };
        }