DocumentWodBinding binding = new DocumentWodBinding(savedRulePosition, rulePosition, element); element.addBinding(binding);
if (element == null) { syntaxError = true; } else { DocumentWodBinding binding = new DocumentWodBinding(savedRulePosition, rulePosition, element); element.addBinding(binding); }
  protected synchronized void parse() {    myElements.clear();    myProblems.clear();    WodScanner scanner = WodScanner.wodScannerForDocument(myDocument);    DocumentWodElement element = null;    RulePosition savedRulePosition = null;    RulePosition lastRulePosition = null;    RulePosition rulePosition;    while ((rulePosition = scanner.nextRulePosition()) != null) {      boolean whitespace = false;      boolean syntaxError = false;      if (RulePosition.isRulePositionOfType(rulePosition, WhitespaceRule.class)) {        whitespace = true;      }      else if (RulePosition.isRulePositionOfType(rulePosition, ElementNameRule.class)) {        if (lastRulePosition != null && !RulePosition.isOperatorOfType(lastRulePosition, CloseDefinitionWordDetector.class)) {          addProblem("The element name '" + rulePosition._getTextWithoutException() + "' can only appear at the beginning of the document or after a '}'", rulePosition);          syntaxError = true;        }        savedRulePosition = rulePosition;        element = null;        syntaxError = false;      }      else if (RulePosition.isOperatorOfType(rulePosition, ElementTypeOperatorWordDetector.class)) {        if (!RulePosition.isRulePositionOfType(lastRulePosition, ElementNameRule.class)) {          addProblem("A ':' can only appear after an element name", rulePosition);          syntaxError = true;        }      }      else if (RulePosition.isRulePositionOfType(rulePosition, ElementTypeRule.class)) {        if (!RulePosition.isOperatorOfType(lastRulePosition, ElementTypeOperatorWordDetector.class)) {          addProblem("The element type '" + rulePosition._getTextWithoutException() + "' can only appear after a ':'", rulePosition);          syntaxError = true;        }        else if (!syntaxError) {          element = new DocumentWodElement(savedRulePosition, rulePosition, this);          addElement(element);        }      }      else if (RulePosition.isOperatorOfType(rulePosition, OpenDefinitionWordDetector.class)) {        if (!RulePosition.isRulePositionOfType(lastRulePosition, ElementTypeRule.class)) {          addProblem("A '{' can only appear after an element type", rulePosition);          syntaxError = true;        }      }      else if (RulePosition.isRulePositionOfType(rulePosition, BindingNameRule.class)) {        if (!RulePosition.isOperatorOfType(lastRulePosition, OpenDefinitionWordDetector.class) && !RulePosition.isOperatorOfType(lastRulePosition, EndAssignmentWordDetector.class)) {          addProblem("The binding name '" + rulePosition._getTextWithoutException() + "' can only appear after a '{' or a ';'", rulePosition);          syntaxError = true;        }        else if (!syntaxError) {          savedRulePosition = rulePosition;        }      }      else if (RulePosition.isOperatorOfType(rulePosition, AssignmentOperatorWordDetector.class)) {        if (!RulePosition.isRulePositionOfType(lastRulePosition, BindingNameRule.class)) {          addProblem("An '=' can only appear after a binding name", rulePosition);          syntaxError = true;        }      }      else if (RulePosition.isRulePositionOfType(rulePosition, BindingValueRule.class) || RulePosition.isRulePositionOfType(rulePosition, ConstantBindingValueRule.class)) {        if (!RulePosition.isOperatorOfType(lastRulePosition, AssignmentOperatorWordDetector.class)) {          addProblem("The binding value '" + rulePosition._getTextWithoutException() + "' can only appear after an '='", rulePosition);          syntaxError = true;        }        else if (!syntaxError) {          DocumentWodBinding binding = new DocumentWodBinding(savedRulePosition, rulePosition, element);          element.addBinding(binding);        }      }      else if (RulePosition.isOperatorOfType(rulePosition, EndAssignmentWordDetector.class)) {        if (!RulePosition.isRulePositionOfType(lastRulePosition, BindingValueRule.class) && !RulePosition.isRulePositionOfType(lastRulePosition, ConstantBindingValueRule.class)) {          addProblem("A ';' can only appear after a binding value", rulePosition);          syntaxError = true;        }      }      else if (RulePosition.isOperatorOfType(rulePosition, CloseDefinitionWordDetector.class)) {        if (!RulePosition.isOperatorOfType(lastRulePosition, OpenDefinitionWordDetector.class) && !RulePosition.isOperatorOfType(lastRulePosition, EndAssignmentWordDetector.class)) {          addProblem("A '}' can only appear after a ';' or a '{'", rulePosition);          syntaxError = true;        }        else {          element = null;        }      }      else {        addProblem("'" + rulePosition._getTextWithoutException() + "' is an unknown keyword", rulePosition);        syntaxError = true;      }      if (!whitespace) {        lastRulePosition = rulePosition;      }    }    if (lastRulePosition != null && !RulePosition.isOperatorOfType(lastRulePosition, CloseDefinitionWordDetector.class)) {      addProblem("The last entry in a WOD file must be a '}'.", lastRulePosition);    }  }