Пример #1
0
 public Shell(IAbstractEditor editor)
 {
     _editor = editor;
     _editor.TextChanged += HandleTextChanged;
     _text = new TextWithChanges(_editor);
     _selectedTreeStack = new CowList<ParseTree>();
     _chordBuffer = new Queue<Synpl.EditorAbstraction.Key>();
     _structureModeAction = "m";
     _inStructureMode = false;
 }
Пример #2
0
 public ParseTreeQuote(int startPosition, 
                       int endPosition, 
                       ParseTree quotedTree,
                       Synpl.Core.Parser parser,
                       ParseTree parent,
                       TextWithChanges text)
     : base(startPosition,
            endPosition,
            MakeList(quotedTree),
            parser,
            parent,
            text,
            "' (quote)")
 {
 }
Пример #3
0
 public ParseTreeList(int startPosition, 
                       int endPosition, 
                       CowList<ParseTree> members,
                       Synpl.Core.Parser parser,
                       ParseTree parent,
                       TextWithChanges text)
     : base(startPosition,
            endPosition,
            members,
            parser,
            parent,
            text,
            "() (list)")
 {
 }
Пример #4
0
 public ParseTreeAtom(int startPosition,
                      int endPosition,
                      string content,
                      Synpl.Core.Parser parser,
                      ParseTree parent,
                      TextWithChanges text)
     : base(startPosition, 
            endPosition, 
            new CowList<ParseTree>(),
            parser,
            parent,
            text,
            content)
 {
     _content = content;
 }
Пример #5
0
 public ParseTree(int startPosition, 
                  int endPosition, 
                  CowList<ParseTree> subTrees, 
                  Parser parser,
                  ParseTree parent,
                  TextWithChanges text,
                  string label)
 {
     _startPosition = startPosition;
     _endPosition = endPosition;
     _subTrees = subTrees;
     _parser = parser;
     _parent = parent;
     _text = text;
     _label = label;
     foreach (ParseTree node in _subTrees)
     {
         node._parent = this;
     }
 }
Пример #6
0
 public void AddTwc(TextWithChanges twc)
 {
     _text.InsertSliceWithChanges(_text.GetActualLength(), twc);
 }
Пример #7
0
 public void AddText(string text)
 {
     TextWithChanges twc = new TextWithChanges();
     twc.SetText(text);
     AddTwc(twc);
 }
Пример #8
0
 public TwcBuilder()
 {
     _text = new TextWithChanges();
 }
Пример #9
0
 public static void ParseGlobal(CowList<Token> tokens, 
                               TextWithChanges text,
                               out ParseTree parseTree,
                               out CowList<Token> remainingTokens)
 {
     CowList<ParseTree> trees = new CowList<ParseTree>();
     remainingTokens = tokens;
     while (remainingTokens.Count > 0)
     {
         ParseTree tree;
         ParseLocal(remainingTokens, text, out tree, out remainingTokens);
         trees.Add(tree);
     }
     if (trees.Count == 0)
     {
         throw new ParseException("No tokens in stream.");
     }
     parseTree = new ParseTreeList(tokens[0].StartPosition,
                                   trees.Last.EndPosition,
                                   trees,
                                   SexpParser.GetInstance(ParseType.Global),
                                   null,
                                   text);
 }
Пример #10
0
 public static void ParseLocal(CowList<Token> tokens, 
                               TextWithChanges text,
                               out ParseTree parseTree,
                               out CowList<Token> remainingTokens)
 {
     if (tokens.Count == 0)
     {
         throw new ParseException("No tokens in stream.");
     }
     switch ((TokenTypes)tokens[0].Kind)
     {
     case TokenTypes.Quote:
         ParseTree quotedTree;
         ParseLocal(tokens.Tail,
                    text,
                    out quotedTree,
                    out remainingTokens);
         parseTree = new ParseTreeQuote(tokens[0].StartPosition,
                                        quotedTree.EndPosition,
                                        quotedTree,
                                        SexpParser.GetInstance(ParseType.Sexp),
                                        null,
                                        text);
         return;
     case TokenTypes.OpenParen:
         CowList<ParseTree> members = new CowList<ParseTree>();
         CowList<Token> iterTokens = tokens.Tail;
         while (iterTokens.Count > 0
                && (TokenTypes)iterTokens[0].Kind != TokenTypes.CloseParen)
         {
             ParseTree member;
             CowList<Token> nextIterTokens;
             ParseLocal(iterTokens, text, out member, out nextIterTokens);
             iterTokens = nextIterTokens;
             members.Add(member);
         }
         if (iterTokens.Count == 0)
         {
             throw new ParseException("No tokens left in stream, expected a ')'.");
         }
         remainingTokens = iterTokens.Tail;
         parseTree = new ParseTreeList(tokens[0].StartPosition,
                                       iterTokens[0].EndPosition,
                                       members,
                                       SexpParser.GetInstance(ParseType.Sexp),
                                       null,
                                       text);
         return;
     case TokenTypes.CloseParen:
         throw new ParseException("Unexpected ')'.");
     case TokenTypes.Atom:
         remainingTokens = tokens.Tail;
         parseTree = new ParseTreeAtom(tokens[0].StartPosition,
                                       tokens[0].EndPosition,
                                       tokens[0].Content,
                                       SexpParser.GetInstance(ParseType.Sexp),
                                       null,
                                       text);
         return;
     default:
         throw new ParseException(String.Format("Unknown token '{0}'.",
                                                tokens[0].ToString()));
     }
 }
Пример #11
0
 public void InsertSliceWithChanges(int position, TextWithChanges slice, bool sendToEditor)
 {
     if (_editor != null && sendToEditor)
     {
         CowList<CharWithPosition> sliceText = slice.GetCurrentSlice(0, slice.GetActualLength());
         StringBuilder sb = new StringBuilder();
         foreach (CharWithPosition cwp in sliceText)
         {
             sb.Append(cwp.Char);
         }
         _editor.InsertText(position, sb.ToString(), true);
     }
     int oldPosition = ConvertActualPositionToOld(position);
     CowList<TextChange> newChanges = new CowList<TextChange>();
     // Select changes before the insert position.
     int i;
     for (i = 0; i < _changes.Count; i++)
     {
         if (_changes[i].Position < oldPosition)
         {
             newChanges.Add(_changes[i]);
         }
         else
         {
             break;
         }
     }
     // Add changes from the inserted slice.
     foreach (TextChange change in slice._changes)
     {
         newChanges.Add(change.Moved(oldPosition));
     }
     // Add changes that were after the insert position.
     for (; i < _changes.Count; i++)
     {
         newChanges.Add(_changes[i].Moved(slice._text.Length));
     }
     _changes = newChanges;
     _text = _text.Substring(0, oldPosition) + slice._text + _text.Substring(oldPosition);
 }
Пример #12
0
 public void InsertSliceWithChanges(int position, TextWithChanges slice)
 {
     InsertSliceWithChanges(position, slice, false);
 }
Пример #13
0
 public TextWithChanges GetSliceWithChanges(int start, int end)
 {
     int oldStart = ConvertActualPositionToOld(start);
     int oldEnd = ConvertActualPositionToOld(end, true);
     TextWithChanges result = new TextWithChanges();
     foreach (TextChange change in _changes)
     {
         if (change.IsBetween(oldStart, oldEnd)) {
             result._changes.Add(change.Moved(-oldStart));
         }
     }
     result._text = _text.Substring(oldStart, oldEnd - oldStart);
     return result;
 }
Пример #14
0
 public void Init()
 {
     _textWc = new TextWithChanges();
     _textWc.SetText("Ana re mere.");
 }
Пример #15
0
 // The following functions are debugging helpers, they are not
 // used normally.
 #pragma warning disable 0169
 private static void ShowChanges(TextWithChanges twc)
 {
     Console.WriteLine("\n***");
     foreach (TextChange change in twc.GetChanges())
     {
         Console.WriteLine("{0}, {1}", change.Position, change.IsDeletion);
     }
 }