Changeset 517 in josm for trunk/src


Ignore:
Timestamp:
2008-01-09T11:37:58+01:00 (16 years ago)
Author:
gebner
Message:

SearchCompiler: Report errors.

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  
    8585                }
    8686        }
    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                }
    101105    }
    102106}
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r515 r517  
    165165                @Override public String toString() {return "incomplete";}
    166166        }
     167
     168        public static class ParseError extends Exception {
     169                public ParseError(String msg) {
     170                        super(msg);
     171                }
     172        }
    167173       
    168         public static Match compile(String searchStr, boolean caseSensitive) {
     174        public static Match compile(String searchStr, boolean caseSensitive)
     175                        throws ParseError {
    169176                return new SearchCompiler(caseSensitive,
    170177                                new PushbackTokenizer(
     
    173180        }
    174181
    175         public Match parse() {
     182        public Match parse() throws ParseError {
    176183                Match m = parseJuxta();
    177184                if (!tokenizer.readIfEqual(null)) {
    178                         throw new RuntimeException("Unexpected token: " + tokenizer.nextToken());
     185                        throw new ParseError("Unexpected token: " + tokenizer.nextToken());
    179186                }
    180187                return m;
    181188        }
    182189
    183         private Match parseJuxta() {
     190        private Match parseJuxta() throws ParseError {
    184191                Match juxta = new Always();
    185192
     
    192199        }
    193200
    194         private Match parseOr() {
     201        private Match parseOr() throws ParseError {
    195202                Match a = parseNot();
    196203                if (tokenizer.readIfEqual("|")) {
    197204                        Match b = parseNot();
    198205                        if (a == null || b == null) {
    199                                 throw new RuntimeException("Missing arguments for or.");
     206                                throw new ParseError("Missing arguments for or.");
    200207                        }
    201208                        return new Or(a, b);
     
    204211        }
    205212
    206         private Match parseNot() {
     213        private Match parseNot() throws ParseError {
    207214                if (tokenizer.readIfEqual("-")) {
    208215                        Match m = parseParens();
    209216                        if (m == null) {
    210                                 throw new RuntimeException("Missing argument for not.");
     217                                throw new ParseError("Missing argument for not.");
    211218                        }
    212219                        return new Not(m);
     
    215222        }
    216223
    217         private Match parseParens() {
     224        private Match parseParens() throws ParseError {
    218225                if (tokenizer.readIfEqual("(")) {
    219226                        Match m = parseJuxta();
    220227                        if (!tokenizer.readIfEqual(")")) {
    221                                 throw new RuntimeException("Expected closing paren");
     228                                throw new ParseError("Expected closing paren");
    222229                        }
    223230                        return m;
Note: See TracChangeset for help on using the changeset viewer.