コード例 #1
0
ファイル: SourceStream.cs プロジェクト: pusp/o2platform
 public void SetText(string text, int offset, bool keepLineNumbering) {
   Text = text;
   //For line-by-line input, automatically increment line# for every new line
   var line = keepLineNumbering ? _location.Line + 1 : 0;
   Location = new SourceLocation(offset, line, 0);
   _nextNewLinePosition = text.IndexOfAny(_scannerData.LineTerminatorsArray, offset);
 }
コード例 #2
0
ファイル: IndentFilter.cs プロジェクト: bgare89/OpenBYOND-1
 public override IEnumerable<Token> BeginFiltering(ParsingContext context, IEnumerable<Token> tokens)
 {
     this.pcontext = context;
     foreach (Token t in tokens)
     {
         Console.WriteLine(" -> {0} ({1})", t, bracket_indent_level);
         currentLoc = t.Location;
         if (t.Terminal == grammar.Eof)
         {
             Console.WriteLine("CLI: {0}, CIL: {1}", current_line_indent, current_indent_level);
             current_line_indent = 0;
             while(current_indent_level > 0)
             {
                 current_indent_level--;
                 Console.WriteLine(" <- DEDENT");
                 yield return new Token(grammar.Dedent,currentLoc,string.Empty,null);
             }
             yield return t;
             break;
         }
         if (bracket_indent_level == 0)
         {
             while (ProcessToken(t)) { ;}
             while (OutputTokens.Count > 0)
                 yield return OutputTokens.Pop();
             continue;
         }
         if (t.Terminal == opening_bracket) { bracket_indent_level++; yield return new Token(grammar.Indent, currentLoc, string.Empty, null); continue; }
         else if (t.Terminal == closing_bracket) { Debug.Assert(bracket_indent_level > 0); bracket_indent_level--; yield return new Token(grammar.Dedent, currentLoc, string.Empty, null); continue; }
         yield return t;
     }
 }
コード例 #3
0
 public static SourceLocation ToLocation(this Irony.Parsing.SourceLocation srcLoc)
 {
     // somehow Irony's location line and column are zero based
     return(new SourceLocation()
     {
         Line = srcLoc.Line + 1, Column = srcLoc.Column + 1
     });
 }
コード例 #4
0
ファイル: CodeOutlineFilter.cs プロジェクト: anukat2015/sones
 public override void Reset() {
   base.Reset();
   Indents.Clear();
   Indents.Push(0);
   OutputTokens.Clear();
   PreviousToken = null;
   CurrentToken = null;
   PreviousTokenLocation = new SourceLocation();
 }
コード例 #5
0
ファイル: SourceStream.cs プロジェクト: mauve/Pash
 public SourceStream(string text, bool caseSensitive, int tabWidth, SourceLocation initialLocation) {
   _text = text;
   _textLength = _text.Length; 
   _chars = Text.ToCharArray(); 
   _stringComparison = caseSensitive ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase;
   _tabWidth = tabWidth; 
   _location = initialLocation;
   _previewPosition = _location.Position;
   if (_tabWidth <= 1) 
     _tabWidth = 8;
 }
コード例 #6
0
 protected TextSpan CreateSpanFor(SourceLocation location, int endPosition, Source source)
 {
     var span = new TextSpan
     {
         iStartLine = location.Line,
         iStartIndex = location.Column,
     };
     if (source != null)
         source.GetLineIndexOfPosition(endPosition, out span.iEndLine, out span.iEndIndex);
     return span;
 }
コード例 #7
0
ファイル: ScriptExtent.cs プロジェクト: bitwiseman/Pash
 public ScriptExtent(SourceSpan origSpan, int startOffset, int endOffset)
 {
     if (startOffset == 0 && endOffset == 0)
     {
         _span = origSpan;
         return;
     }
     // create a new span with offsets
     var location = origSpan.Location;
     // we don't adjust line and column for artifical offsets. This is hopefully okay.
     var newLocation = new SourceLocation(location.Position + startOffset, location.Line, location.Column);
     // don't forget to subtract the start offset here
     _span = new SourceSpan(newLocation, origSpan.Length + endOffset - startOffset);
 }
コード例 #8
0
        public SourceStream(string text, bool caseSensitive, int tabWidth, SourceLocation initialLocation)
        {
            Text = text;
            _textLength = Text.Length;
            _chars = Text.ToCharArray();
#if DNXCORE50
            _stringComparison = caseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
#else
            _stringComparison = caseSensitive
                ? StringComparison.InvariantCulture
                : StringComparison.InvariantCultureIgnoreCase;
#endif
            _tabWidth = tabWidth;
            Location = initialLocation;
            PreviewPosition = Location.Position;
            if (_tabWidth <= 1)
                _tabWidth = 8;
        }
コード例 #9
0
 internal void Reset()
 {
     CurrentParserState = Parser.InitialState;
     CurrentParserInput = null;
     CurrentCommentTokens = new TokenList();
     ParserStack.Clear();
     HasErrors = false;
     ParserStack.Push(new ParseTreeNode(CurrentParserState));
     CurrentParseTree = null;
     OpenBraces.Clear();
     ParserTrace.Clear();
     CurrentTerminals.Clear();
     CurrentToken = null;
     PreviousToken = null;
     PreviousLineStart = new SourceLocation(0, -1, 0);
     BufferedTokens.Clear();
     PreviewTokens.Clear();
     Values.Clear();
     foreach (var filter in TokenFilters)
         filter.Reset();
 }
コード例 #10
0
ファイル: Scanner.cs プロジェクト: cg123/xenko
 /// <summary>
 /// Begins the preview.
 /// </summary>
 public virtual void BeginPreview()
 {
     Context.Status = ParserStatus.Previewing;
     previewTokens.Clear();
     previewStartLocation = Location;
 }
コード例 #11
0
 public ScriptException(string message, Exception inner, SourceLocation location, ScriptStackTrace stack) 
        : base(message, inner)  {
   Location = location;
   ScriptStackTrace = stack; 
 }
コード例 #12
0
 public SourceSpan(SourceLocation location, int length) {
   Location = location;
   Length = length;
 }
コード例 #13
0
 private void PushOutlineToken(Terminal term, SourceLocation location)
 {
     OutputTokens.Push(new Token(term, location, string.Empty, null));
 }
コード例 #14
0
 public void AddParserMessage(ErrorLevel level, SourceLocation location, string message, params object[] args)
 {
     if (CurrentParseTree == null) return;
     if (CurrentParseTree.ParserMessages.Count >= MaxErrors) return;
     if (args != null && args.Length > 0)
         message = string.Format(message, args);
     CurrentParseTree.ParserMessages.Add(new LogMessage(level, location, message, CurrentParserState));
     if (TracingEnabled)
         AddTrace(true, message);
 }
コード例 #15
0
ファイル: SourceStream.cs プロジェクト: mauve/Pash
 //Computes the Location info (line, col) for a new source position.
 private void SetNewPosition(int newPosition) {
   if (newPosition < Position)
     throw new Exception(Resources.ErrCannotMoveBackInSource); 
   int p = Position; 
   int col = Location.Column;
   int line = Location.Line; 
   while(p <  newPosition) {
     var curr = _chars[p];
     switch (curr) {
       case '\n': line++; col = 0; break;
       case '\r': break; 
       case '\t': col = (col / _tabWidth + 1) * _tabWidth;     break;
       default: col++; break; 
     } //switch
     p++;
   }
   Location = new SourceLocation(p, line, col); 
 }
コード例 #16
0
ファイル: Scanner.cs プロジェクト: gregberns/Irony
 //Switches Scanner into preview mode
 public void BeginPreview()
 {
     Context.Status        = ParserStatus.Previewing;
     _previewStartLocation = Context.SourceStream.Location;
     Context.PreviewTokens.Clear();
 }
コード例 #17
0
 public static int ByLocation(ParserMessage x, ParserMessage y)
 {
     return(SourceLocation.Compare(x.Location, y.Location));
 }
コード例 #18
0
 public void AddParserMessage(ParserErrorLevel level, SourceLocation location, string message, params object[] args) {
   if (CurrentParseTree == null) return; 
   if (CurrentParseTree.ParserMessages.Count >= MaxErrors) return;
   if (args != null && args.Length > 0)
     message = string.Format(message, args);
   CurrentParseTree.ParserMessages.Add(new ParserMessage(level, location, message, CurrentParserState));
   if (OptionIsSet(ParseOptions.TraceParser)) 
     ParserTrace.Add( new ParserTraceEntry(CurrentParserState, ParserStack.Top, CurrentParserInput, message, true));
 }
コード例 #19
0
        private Token CompleteMatch(ParsingContext context, ISourceStream source, byte level)
        {
            string text = source.Text.Substring(source.PreviewPosition);
            var matches = Regex.Matches(text, @"\](=*)\]");
            foreach(Match match in matches) 
            {
                if (match.Groups[1].Value.Length == (int)level)
                {
                    source.PreviewPosition += match.Index + match.Length;


                    if (context.VsLineScanState.Value != 0)
                    {
                        SourceLocation tokenStart = new SourceLocation();
                        tokenStart.Position = 0;

                        string lexeme = source.Text.Substring(0, source.PreviewPosition);

                        context.VsLineScanState.Value = 0;
                        return new Token(this, tokenStart, lexeme, null);
                    }
                    else
                    {
                        return source.CreateToken(this.OutputTerminal); 
                    }
                }
            }

            context.VsLineScanState.TerminalIndex = this.MultilineIndex;
            context.VsLineScanState.TokenSubType = level;
            return null;
        }
コード例 #20
0
    }//method

    public void ResetLocationAndClearInput(SourceLocation location, int position) {
      Context.CurrentParserInput = null;
      Context.ParserInputStack.Clear();
      Context.SetSourceLocation(location);
    }
コード例 #21
0
 private void PushOutlineToken(Terminal term, SourceLocation location)
 {
     OutputTokens.Push(new Token(term, location, string.Empty, null));
 }
コード例 #22
0
ファイル: fmGrammarExplorer.cs プロジェクト: BigEd/DCPUC
 private void ShowSourceLocation(SourceLocation location, int length)
 {
     if (location.Position < 0) return;
       txtSource.SelectionStart = location.Position;
       txtSource.SelectionLength = length;
       //txtSource.Select(location.Position, length);
       txtSource.ScrollToCaret();
       if (tabGrammar.SelectedTab != pageTest)
     tabGrammar.SelectedTab = pageTest;
       txtSource.Focus();
       //lblLoc.Text = location.ToString();
 }
コード例 #23
0
ファイル: AstContext.cs プロジェクト: androdev4u/XLParser
 public void AddMessage(ErrorLevel level, SourceLocation location, string message, params object[] args) {
   if (args != null && args.Length > 0)
     message = string.Format(message, args);
   Messages.Add(new LogMessage(level, location, message, null));
 }
コード例 #24
0
ファイル: ParseTree.cs プロジェクト: pusp/o2platform
    }//method

    public void CopyMessages(ParserMessageList others, SourceLocation baseLocation, string messagePrefix) {
      foreach(var other in others) 
        this.ParserMessages.Add(new ParserMessage(other.Level, baseLocation + other.Location, messagePrefix + other.Message, other.ParserState)); 
    }//
コード例 #25
0
ファイル: Scanner.cs プロジェクト: gregberns/Irony
 private bool NeedLineStartToken(SourceLocation forLocation)
 {
     return(_grammar.FlagIsSet(LanguageFlags.EmitLineStartToken) && forLocation.Line > Context.PreviousLineStart.Line);
 }
コード例 #26
0
ファイル: Scanner.cs プロジェクト: pusp/o2platform
 //Switches Scanner into preview mode
 public void BeginPreview() {
   Context.Status = ParserStatus.Previewing;
   _previewStartLocation = Context.SourceStream.Location;
   Context.PreviewTokens.Clear();
 }
コード例 #27
0
ファイル: RuntimeException.cs プロジェクト: anukat2015/sones
 public RuntimeException(string message, Exception inner, SourceLocation location) : base(message, inner) {
   Location = location;
 }
コード例 #28
0
        }//method

        public void ResetLocationAndClearInput(SourceLocation location, int position)
        {
            Context.CurrentParserInput = null;
            Context.ParserInputStack.Clear();
            Context.SetSourceLocation(location);
        }
コード例 #29
0
ファイル: DefaultScanner.cs プロジェクト: cg123/xenko
 private bool NeedLineStartToken(SourceLocation forLocation) {
   return Grammar.FlagIsSet(LanguageFlags.EmitLineStartToken) && forLocation.Line > Context.PreviousLineStart.Line;
 }
コード例 #30
0
        } //method

        private void SetCurrentToken(Token token)
        {
            _doubleEof = CurrentToken != null && CurrentToken.Terminal == _grammar.Eof
                         && token.Terminal == _grammar.Eof;
            //Copy CurrentToken to PreviousToken
            if (CurrentToken != null && CurrentToken.Category == TokenCategory.Content)
            {
                //remember only content tokens
                PreviousToken = CurrentToken;
                _prevIsContinuation = _isContinuation;
                _prevIsOperator = _isOperator;
                if (PreviousToken != null)
                    PreviousTokenLocation = PreviousToken.Location;
            }
            CurrentToken = token;
            _isContinuation = (token.Terminal == ContinuationTerminal && ContinuationTerminal != null);
            _isOperator = token.Terminal.Flags.IsSet(TermFlags.IsOperator);
            if (!_isContinuation)
                OutputTokens.Push(token); //by default input token goes to output, except continuation symbol
        }
コード例 #31
0
ファイル: DefaultScanner.cs プロジェクト: cg123/xenko
 //Switches Scanner into preview mode
 public override void BeginPreview() {
   base.BeginPreview();
   _previewStartLocation = SourceStream.Location;
 }
コード例 #32
0
        private Token CompleteMatch(ParsingContext context, ISourceStream source, byte commentLevel)
        {
            if (commentLevel == 0)
            {
                var line_breaks = new char[] { '\n', '\r', '\v' };
                var firstCharPos = source.Text.IndexOfAny(line_breaks, source.PreviewPosition);
                if (firstCharPos > 0)
                {
                    source.PreviewPosition = firstCharPos;
                }
                else
                {
                    source.PreviewPosition = source.Text.Length;
                }

                return source.CreateToken(this.OutputTerminal);
            }

            while (!source.EOF())
            {      
               string text = source.Text.Substring(source.PreviewPosition);
                var matches = Regex.Matches(text, @"\](=*)\]");
                foreach (Match match in matches)
                {
                    if (match.Groups[1].Value.Length == (int)commentLevel - 1)
                    {
                        source.PreviewPosition += match.Index + match.Length;

                        if (context.VsLineScanState.Value != 0)
                        {
                            SourceLocation tokenStart = new SourceLocation();
                            tokenStart.Position = 0;

                            string lexeme = source.Text.Substring(0, source.PreviewPosition);

                            context.VsLineScanState.Value = 0;
                            return new Token(this, tokenStart, lexeme, null);
                        }
                        else
                        {
                            return source.CreateToken(this.OutputTerminal);
                        }
                    }
                }

                source.PreviewPosition++;
            }
            
			context.VsLineScanState.TokenSubType = commentLevel;
            return null;
        }
コード例 #33
0
 public static int Compare(SourceLocation x, SourceLocation y) {
   if (x.Position < y.Position) return -1;
   if (x.Position == y.Position) return 0;
   return 1;
 }
コード例 #34
0
ファイル: Scanner.cs プロジェクト: androdev4u/XLParser
 public void VsSetSource(string text, int offset) {
   var line = Context.Source==null ? 0 : Context.Source.Location.Line;
   var newLoc = new SourceLocation(offset, line + 1, 0);
   Context.Source = new SourceStream(text, Context.Language.Grammar.CaseSensitive, Context.TabWidth, newLoc); 
 }
コード例 #35
0
ファイル: fmGrammarExplorer.cs プロジェクト: BigEd/DCPUC
 private void ShowSourceLocationAndTraceToken(SourceLocation location, int length)
 {
     ShowSourceLocation(location, length);
       //find token in trace
       for (int i = 0; i < lstTokens.Items.Count; i++) {
     var tkn = lstTokens.Items[i] as Token;
     if (tkn.Location.Position == location.Position) {
       lstTokens.SelectedIndex = i;
       return;
     }//if
       }//for i
 }
コード例 #36
0
 public void SetSourceLocation(SourceLocation location) {
   foreach (var filter in TokenFilters)
     filter.OnSetSourceLocation(location); 
   SourceStream.Location = location;
 }
コード例 #37
0
ファイル: Token.cs プロジェクト: Delphi79/UO98-SVN
 public MultiToken(Terminal term, SourceLocation location, TokenList childTokens) : base(term, location, string.Empty, null)
 {
     ChildTokens = childTokens;
 }