Solved "Parse" own "syntax"

Discussion in 'Plugin Development' started by MisterErwin, Apr 17, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    MisterErwin

    Hello together,

    I would like to parse a syntax like those:
    The first works. But how can I get the 2nd to work?

    Here's also the code (for the first):
    Code:
            String[] eqa = eqs.split("|");
        for (String s : eqa){
            if (s.contains(":")){
                try {
                        Integer i = Integer.parseInt(s.split(":")[0]);
                         if (!this.guns.containsKey(i))
                                 this.guns.put(i, 1);
                } catch (Exception e) {
                    continue;
                }
            }else{
                try {
                    Integer i = Integer.parseInt(s.split(":")[0]);
                    Integer a = Integer.parseInt(s.split(":")[1]);
                    if (!this.guns.containsKey(i))
                        this.guns.put(i, a);
                } catch (Exception e) {
                    continue;
                }
            }
        }
    Thank you very much,

    MisterErwin

    bump...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. MisterErwin
    If I remember correctly the problem is | with regex, try split("\\|") instead.

    Also your contains(":") condition blocks might be reversed ?
     
  3. Offline

    afistofirony

    So wait, what exactly do you want to do with the {} keys?
     
  4. Offline

    MisterErwin

    Oh...

    between the brackets stands alternatives.

    I've got it right now, that it runs through every letter and checks is it is a { or a |...

    But thanks...
     
Thread Status:
Not open for further replies.

Share This Page