- Timestamp:
- 2008-01-09T11:37:58+01:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions/search
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r460 r517 85 85 } 86 86 } 87 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 88 SearchCompiler.Match matcher = SearchCompiler.compile(search, caseSensitive); 89 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) { 90 if (mode == SearchMode.replace) { 91 if (matcher.match(osm)) 92 sel.add(osm); 93 else 94 sel.remove(osm); 95 } else if (mode == SearchMode.add && !osm.selected && matcher.match(osm)) 96 sel.add(osm); 97 else if (mode == SearchMode.remove && osm.selected && matcher.match(osm)) 98 sel.remove(osm); 99 } 100 Main.ds.setSelected(sel); 87 try { 88 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 89 SearchCompiler.Match matcher = SearchCompiler.compile(search, caseSensitive); 90 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) { 91 if (mode == SearchMode.replace) { 92 if (matcher.match(osm)) 93 sel.add(osm); 94 else 95 sel.remove(osm); 96 } else if (mode == SearchMode.add && !osm.selected && matcher.match(osm)) 97 sel.add(osm); 98 else if (mode == SearchMode.remove && osm.selected && matcher.match(osm)) 99 sel.remove(osm); 100 } 101 Main.ds.setSelected(sel); 102 } catch (SearchCompiler.ParseError e) { 103 JOptionPane.showMessageDialog(Main.parent, e.getMessage()); 104 } 101 105 } 102 106 } -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r515 r517 165 165 @Override public String toString() {return "incomplete";} 166 166 } 167 168 public static class ParseError extends Exception { 169 public ParseError(String msg) { 170 super(msg); 171 } 172 } 167 173 168 public static Match compile(String searchStr, boolean caseSensitive) { 174 public static Match compile(String searchStr, boolean caseSensitive) 175 throws ParseError { 169 176 return new SearchCompiler(caseSensitive, 170 177 new PushbackTokenizer( … … 173 180 } 174 181 175 public Match parse() {182 public Match parse() throws ParseError { 176 183 Match m = parseJuxta(); 177 184 if (!tokenizer.readIfEqual(null)) { 178 throw new RuntimeException("Unexpected token: " + tokenizer.nextToken());185 throw new ParseError("Unexpected token: " + tokenizer.nextToken()); 179 186 } 180 187 return m; 181 188 } 182 189 183 private Match parseJuxta() {190 private Match parseJuxta() throws ParseError { 184 191 Match juxta = new Always(); 185 192 … … 192 199 } 193 200 194 private Match parseOr() {201 private Match parseOr() throws ParseError { 195 202 Match a = parseNot(); 196 203 if (tokenizer.readIfEqual("|")) { 197 204 Match b = parseNot(); 198 205 if (a == null || b == null) { 199 throw new RuntimeException("Missing arguments for or.");206 throw new ParseError("Missing arguments for or."); 200 207 } 201 208 return new Or(a, b); … … 204 211 } 205 212 206 private Match parseNot() {213 private Match parseNot() throws ParseError { 207 214 if (tokenizer.readIfEqual("-")) { 208 215 Match m = parseParens(); 209 216 if (m == null) { 210 throw new RuntimeException("Missing argument for not.");217 throw new ParseError("Missing argument for not."); 211 218 } 212 219 return new Not(m); … … 215 222 } 216 223 217 private Match parseParens() {224 private Match parseParens() throws ParseError { 218 225 if (tokenizer.readIfEqual("(")) { 219 226 Match m = parseJuxta(); 220 227 if (!tokenizer.readIfEqual(")")) { 221 throw new RuntimeException("Expected closing paren");228 throw new ParseError("Expected closing paren"); 222 229 } 223 230 return m;
Note:
See TracChangeset
for help on using the changeset viewer.