/// <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<JsContext>(); m_document = new JsDocumentContext(this, source); m_scanner = new JsScanner(new JsContext(m_document)); m_currentToken = new JsContext(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; // we also want to assume that we found a newline character after // the comment m_foundEndOfLine = true; }; }
public JsContext(JsDocumentContext 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; }
internal JsDocumentContext DifferentFileContext(string fileContext) { // use the SAME parser and reported variable dictionary var documentContext = new JsDocumentContext(m_parser, Source) { IsGenerated = this.IsGenerated, FileContext = fileContext }; documentContext.m_reportedVariables = this.m_reportedVariables; return(documentContext); }
internal JsDocumentContext DifferentFileContext(string fileContext) { // use the SAME parser and reported variable dictionary var documentContext = new JsDocumentContext(m_parser, Source) { IsGenerated = this.IsGenerated, FileContext = fileContext }; documentContext.m_reportedVariables = this.m_reportedVariables; return documentContext; }
public JsContext(JsDocumentContext document) { if (document == null) { throw new ArgumentNullException("document"); } Document = document; StartLineNumber = 1; EndLineNumber = 1; EndPosition = Document.Source.IfNotNull(s => s.Length); Token = JsToken.None; }