Exemple #1
0
        protected override void RuleDidSucceed(object result, StringParserState.Element stateAtStart, StringParserState.Element stateAtEnd)
        {
            // Apply DebugMetadata based on the state at the start of the rule
            // (i.e. use line number as it was at the start of the rule)
            var parsedObj = result as Parsed.Object;
            if ( parsedObj) {
                var md = new Runtime.DebugMetadata ();
                md.startLineNumber = stateAtStart.lineIndex + 1;
                md.endLineNumber = stateAtEnd.lineIndex + 1;
                md.fileName = _filename;
                parsedObj.debugMetadata = md;
                return;
            }

            // A list of objects that doesn't already have metadata?
            var parsedListObjs = result as List<Parsed.Object>;
            if (parsedListObjs != null) {
                foreach (var parsedListObj in parsedListObjs) {
                    if (!parsedListObj.hasOwnDebugMetadata) {
                        var md = new Runtime.DebugMetadata ();
                        md.startLineNumber = stateAtStart.lineIndex + 1;
                        md.endLineNumber = stateAtEnd.lineIndex + 1;
                        md.fileName = _filename;
                        parsedListObj.debugMetadata = md;
                    }
                }
            }
        }
Exemple #2
0
        protected override void RuleDidSucceed(object result, StringParserState.Element stateAtStart, StringParserState.Element stateAtEnd)
        {
            // Apply DebugMetadata based on the state at the start of the rule
            // (i.e. use line number as it was at the start of the rule)
            var parsedObj = result as Parsed.Object;

            if (parsedObj)
            {
                var md = new Runtime.DebugMetadata();
                md.startLineNumber      = stateAtStart.lineIndex + 1;
                md.endLineNumber        = stateAtEnd.lineIndex + 1;
                md.fileName             = _filename;
                parsedObj.debugMetadata = md;
                return;
            }

            // A list of objects that doesn't already have metadata?
            var parsedListObjs = result as List <Parsed.Object>;

            if (parsedListObjs != null)
            {
                foreach (var parsedListObj in parsedListObjs)
                {
                    if (!parsedListObj.hasOwnDebugMetadata)
                    {
                        var md = new Runtime.DebugMetadata();
                        md.startLineNumber          = stateAtStart.lineIndex + 1;
                        md.endLineNumber            = stateAtEnd.lineIndex + 1;
                        md.fileName                 = _filename;
                        parsedListObj.debugMetadata = md;
                    }
                }
            }
        }
        protected Runtime.DebugMetadata CreateDebugMetadata(StringParserState.Element stateAtStart, StringParserState.Element stateAtEnd)
        {
            var md = new Runtime.DebugMetadata();

            md.startLineNumber      = stateAtStart.lineIndex + 1;
            md.endLineNumber        = stateAtEnd.lineIndex + 1;
            md.startCharacterNumber = stateAtStart.characterInLineIndex + 1;
            md.endCharacterNumber   = stateAtEnd.characterInLineIndex + 1;
            md.fileName             = _filename;
            return(md);
        }
Exemple #4
0
        protected override void RuleDidSucceed(object result, StringParserState.Element stateAtStart, StringParserState.Element stateAtEnd)
        {
            // Apply DebugMetadata based on the state at the start of the rule
            // (i.e. use line number as it was at the start of the rule)
            var parsedObj = result as Parsed.Object;

            if (parsedObj)
            {
                var md = new Runtime.DebugMetadata();
                md.startLineNumber      = stateAtStart.lineIndex + 1;
                md.endLineNumber        = stateAtEnd.lineIndex + 1;
                md.fileName             = _filename;
                parsedObj.debugMetadata = md;
            }
        }
        // Currently only used in VariableReference in order to
        // merge the debug metadata of a Path.Of.Indentifiers into
        // one single range.
        public DebugMetadata Merge(DebugMetadata dm)
        {
            var newDebugMetadata = new DebugMetadata();

            // These are not supposed to be differ between 'this' and 'dm'.
            newDebugMetadata.fileName   = fileName;
            newDebugMetadata.sourceName = sourceName;

            if (startLineNumber < dm.startLineNumber)
            {
                newDebugMetadata.startLineNumber      = startLineNumber;
                newDebugMetadata.startCharacterNumber = startCharacterNumber;
            }
            else if (startLineNumber > dm.startLineNumber)
            {
                newDebugMetadata.startLineNumber      = dm.startLineNumber;
                newDebugMetadata.startCharacterNumber = dm.startCharacterNumber;
            }
            else
            {
                newDebugMetadata.startLineNumber      = startLineNumber;
                newDebugMetadata.startCharacterNumber = Math.Min(startCharacterNumber, dm.startCharacterNumber);
            }

            if (endLineNumber > dm.endLineNumber)
            {
                newDebugMetadata.endLineNumber      = endLineNumber;
                newDebugMetadata.endCharacterNumber = endCharacterNumber;
            }
            else if (endLineNumber < dm.endLineNumber)
            {
                newDebugMetadata.endLineNumber      = dm.endLineNumber;
                newDebugMetadata.endCharacterNumber = dm.endCharacterNumber;
            }
            else
            {
                newDebugMetadata.endLineNumber      = endLineNumber;
                newDebugMetadata.endCharacterNumber = Math.Max(endCharacterNumber, dm.endCharacterNumber);
            }

            return(newDebugMetadata);
        }
        Runtime.DebugMetadata DebugMetadataForContentAtOffset(int offset)
        {
            int currOffset = 0;

            Runtime.DebugMetadata lastValidMetadata = null;
            foreach (var range in _debugSourceRanges)
            {
                if (range.debugMetadata != null)
                {
                    lastValidMetadata = range.debugMetadata;
                }

                if (offset >= currOffset && offset < currOffset + range.length)
                {
                    return(lastValidMetadata);
                }

                currOffset += range.length;
            }

            return(null);
        }
Exemple #7
0
 protected override void RuleDidSucceed(object result, StringParserState.Element stateAtStart, StringParserState.Element stateAtEnd)
 {
     // Apply DebugMetadata based on the state at the start of the rule
     // (i.e. use line number as it was at the start of the rule)
     var parsedObj = result as Parsed.Object;
     if ( parsedObj) {
         var md = new Runtime.DebugMetadata ();
         md.startLineNumber = stateAtStart.lineIndex + 1;
         md.endLineNumber = stateAtEnd.lineIndex + 1;
         md.fileName = _filename;
         parsedObj.debugMetadata = md;
     }
 }