Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1226)

Side by Side Diff: tools/codemirror/dart/lib/codemirror.dart

Issue 9034030: Codemirror dart port StringStream datatype babysteps. (Closed) Base URL: http://dart.googlecode.com/svn/experimental/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/codemirror/dart/test/codemirror_tests.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
mattsh 2011/12/30 13:48:16 maybe include a reference back to the original cod
4
5 #library('codemirror');
6
7 #import('dart:html');
8 #import('dart:core');
9
10 /* The character stream used by a [Mode]'s parser. */
11 class StringStream {
12 int _pos, start;
13 String _string;
14
15 StringStream(this._string) { _pos = 0; start = 0; }
16
17 bool eol() => _pos >= _string.length;
18
19 bool sol() => _pos == 0;
20
21 String peek() => _string[_pos];
22
23 String next() {
24 if (_pos < _string.length) return _string[_pos++];
25 return null;
26 }
27
28 String eat(match) {
29 var ch = peek();
30 //TODO(pquitslund): patterns?
31 if (ch == match){
32 ++_pos;
33 return ch;
34 }
35 return null;
36 }
37
38 bool eatWhile(match) {
39 var start = _pos;
40 while (eat(match) != null){}
41 return _pos > start;
42 }
43
44 bool eatSpace() {
45 return eatWhile(' ');
46 }
47
48 void skipToEnd() {
49 _pos = _string.length;
50 }
51
52 bool skipTo(ch) {
53 int found = _string.indexOf(ch, _pos);
54 if (found == -1) return false;
55 _pos = found;
56 return true;
57 }
58
59 void backUp(n) {
60 _pos -= n;
61 }
62
63 int column() => countColumn(_string, start);
64
65 int indentation() => countColumn(_string);
66
67 bool match(String pattern, [bool consume =false,
mattsh 2011/12/30 13:48:16 space before false
68 bool caseInsensitive = false]) {
69
70 if (caseInsensitive) {
71 String cased(str) => caseInsensitive ? str.toLowerCase() : str;
72 if (cased(_string).indexOf(cased(pattern), _pos) != _pos) return false;
mattsh 2011/12/30 13:48:16 my personal preference is braces around all 'if' b
Bob Nystrom 2012/01/04 00:22:40 I believe we generally don't do braces for single-
73 }
74 else if (!_string.substring(_pos).contains(pattern)) return false;
75
76 if (consume) _pos += pattern.length;
77 return true;
78 }
79
80 String current() => _string.substring(start, _pos);
81 }
82
83 //TODO(pquitslund): the codemirror default, surely gets overwritten...
84 var tabSize = 8;
mattsh 2011/12/30 13:48:16 int instead of var
85
86 // Counts the column offset in a string, taking tabs into account.
87 // Used mostly to find indentation.
88 int countColumn(String string, [int end = null]) {
89 if (end == null) {
90 end = string.indexOf(' ');
91 if (end == -1) end = string.length;
92 }
93 int n = 0;
94 for (int i = 0; i < end; ++i) {
95 if (string[i] == "\t") {
96 n += tabSize - (n % tabSize);
97 } else{
98 ++n;
99 }
100 }
101 return n;
102 }
103
104 //TODO(pquitslund): remove once frog doesn't require a main in libs
105 void main(){
106
107 }
OLDNEW
« no previous file with comments | « no previous file | tools/codemirror/dart/test/codemirror_tests.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698