Package org.objectstyle.wolips.wodclipse.core.parser

Examples of org.objectstyle.wolips.wodclipse.core.parser.RulePosition


  public int getNewBindingIndent() {
    int indent = 2;
    List<IWodBinding> bindings = getBindings();
    if (bindings.size() > 0) {
      DocumentWodBinding lastBinding = (DocumentWodBinding)bindings.get(bindings.size() - 1);
      RulePosition nameRulePosition = lastBinding.getNameRulePosition();
      if (nameRulePosition != null) {
        int startOffset = lastBinding.getStartOffset();
        try {
          IRegion lineInformation = nameRulePosition.getDocument().getLineInformationOfOffset(startOffset);
          indent = startOffset - lineInformation.getOffset();
        }
        catch (BadLocationException e) {
          e.printStackTrace();
        }
View Full Code Here


    clear();

    WodScanner scanner = WodScanner.wodScannerForDocument(_document);
    DocumentWodBinding lastBinding = null;
    DocumentWodElement element = null;
    RulePosition tentativeElementName = null;
    RulePosition savedRulePosition = null;
    RulePosition savedRulePosition2 = null;
    RulePosition savedRulePosition3 = null;
    RulePosition lastRulePosition = null;
    ForgivingStack<RulePosition> rulePositions = new ForgivingStack<RulePosition>();
    // boolean stringLiteralIsABindingName = false;
    RulePosition rulePosition;
    while ((rulePosition = scanner.nextRulePosition()) != null) {
      boolean whitespace = false;
      boolean comment = false;
      if (RulePosition.isRulePositionOfType(rulePosition, WhitespaceRule.class)) {
        whitespace = true;
      }
      else if (RulePosition.isRulePositionOfType(rulePosition, ICommentRule.class)) {
        comment = true;
        if (lastBinding != null) {
          String commentText = rulePosition._getTextWithoutException();
          if (commentText != null && commentText.startsWith("//")) {
            commentText = commentText.substring(2).trim();
            if ("VALID".equalsIgnoreCase(commentText)) {
              lastBinding.setValidate(false);
            }
          }
        }
        else {
          String commentText = rulePosition._getTextWithoutException();
          if (commentText != null && commentText.startsWith("//")) {
            commentText = commentText.substring(2).trim();
            if (commentText.toLowerCase().startsWith("inherit ")) {
              String componentName = commentText.substring("inherit ".length()).trim();
              try {
                WodParserCache inheritCache = WodParserCache.parser(_wodFile.getProject(), componentName);
                WodCacheEntry wodCacheEntry = inheritCache.getWodEntry();
                IWodModel parentWodModel = wodCacheEntry.getModel();
                for (IWodElement parentWodElement : parentWodModel.getElements()) {
                  SimpleWodElement inheritedWodElement = new SimpleWodElement(parentWodElement);
                  inheritedWodElement.setInherited(true);
                  addElement(inheritedWodElement);
                }
              }
              catch (Throwable t) {
                addParseProblem(element, "WOD inheritance of '" + componentName + "' failed: " + t.getMessage() + ".", rulePosition, false);
              }
            }
          }
        }
      }
      else if (RulePosition.isRulePositionOfType(rulePosition, ElementNameRule.class)) {
        if (RulePosition.isOperatorOfType(lastRulePosition, OpenDefinitionWordDetector.class) || RulePosition.isOperatorOfType(lastRulePosition, EndAssignmentWordDetector.class)) {
          savedRulePosition2 = rulePosition;
          if (lastRulePosition != null && !RulePosition.isOperatorOfType(lastRulePosition, CloseDefinitionWordDetector.class)) {
            tentativeElementName = rulePosition;
          }
          // leave old savedRulePosition
        }
        else {
          if (lastRulePosition != null && !RulePosition.isOperatorOfType(lastRulePosition, CloseDefinitionWordDetector.class)) {
            addParseProblem(element, "The element name '" + rulePosition._getTextWithoutException() + "' must start a WOD declaration", rulePosition, false);
          }
          savedRulePosition = rulePosition;
          element = null;
        }
      }
      else if (RulePosition.isOperatorOfType(rulePosition, ElementTypeOperatorWordDetector.class)) {
        if (!RulePosition.isRulePositionOfType(lastRulePosition, ElementNameRule.class) && !RulePosition.isRulePositionOfType(lastRulePosition, BindingValueNamespaceRule.class)) {
          addParseProblem(element, "A ':' can only appear after an element name or a binding value namespace.", rulePosition, false);
        }
      }
      else if (RulePosition.isRulePositionOfType(rulePosition, ElementTypeRule.class)) {
        if (tentativeElementName != null) {
           addParseProblem(element, "The element name ' " + tentativeElementName._getTextWithoutException() + "' must start a WOD declaration", tentativeElementName, false);
          tentativeElementName = null;
          savedRulePosition = null;
        }
        else if (!RulePosition.isOperatorOfType(lastRulePosition, ElementTypeOperatorWordDetector.class)) {
          addParseProblem(element, "The element type '" + rulePosition._getTextWithoutException() + "' can only appear after a ':'", rulePosition, false);
        }
        else {
          rulePositions.clear();
          element = new DocumentWodElement(savedRulePosition, rulePosition);
          addElement(element);
          savedRulePosition = null;
        }
      }
      else if (RulePosition.isOperatorOfType(rulePosition, OpenDefinitionWordDetector.class)) {
        if (!RulePosition.isRulePositionOfType(lastRulePosition, ElementTypeRule.class)) {
          addParseProblem(element, "A '{' can only appear after an element type", rulePosition, false);
        }
      }
      else if (RulePosition.isRulePositionOfType(rulePosition, WOOGNLRule.class)) {
        boolean ognlIsValue = RulePosition.isOperatorOfType(lastRulePosition, AssignmentOperatorWordDetector.class);
        boolean ognlIsName = !ognlIsValue && (RulePosition.isOperatorOfType(lastRulePosition, EndAssignmentWordDetector.class) || RulePosition.isOperatorOfType(lastRulePosition, OpenDefinitionWordDetector.class));
        if (!ognlIsValue && !ognlIsName) {
          addParseProblem(element, "The OGNL value " + rulePosition._getTextWithoutException() + " can only appear after a '{', '=', or ';'.", rulePosition, false);
          savedRulePosition = null;
        }
        else if (ognlIsName) {
          savedRulePosition = rulePosition;
        }
        else if (ognlIsValue) {
          lastBinding = addBinding(element, savedRulePosition2, savedRulePosition, null, rulePosition, scanner);
          savedRulePosition = null;
          savedRulePosition2 = null;
          savedRulePosition3 = null;
        }
      }
      else if (RulePosition.isRulePositionOfType(rulePosition, StringLiteralRule.class)) {
        boolean literalIsValue = RulePosition.isOperatorOfType(lastRulePosition, AssignmentOperatorWordDetector.class);
        boolean literalIsName = !literalIsValue && (RulePosition.isOperatorOfType(rulePositions.peek(), EndAssignmentWordDetector.class) || RulePosition.isOperatorOfType(rulePositions.peek(), OpenDefinitionWordDetector.class));
        if (!literalIsValue && !literalIsName) {
          addParseProblem(element, "The string literal '" + rulePosition._getTextWithoutException() + "' can only appear after a '{', '=', or ';'.", rulePosition, false);
          savedRulePosition = null;
        }
        else if (literalIsName) {
          savedRulePosition = rulePosition;
        }
        else if (literalIsValue) {
          lastBinding = addBinding(element, savedRulePosition2, savedRulePosition, null, rulePosition, scanner);
          savedRulePosition = null;
          savedRulePosition2 = null;
          savedRulePosition3 = null;
        }
        tentativeElementName = null;
      }
      else if (RulePosition.isRulePositionOfType(rulePosition, BindingNameRule.class)) {
        if (!RulePosition.isOperatorOfType(lastRulePosition, OpenDefinitionWordDetector.class) && !RulePosition.isOperatorOfType(lastRulePosition, EndAssignmentWordDetector.class) && !RulePosition.isOperatorOfType(lastRulePosition, ElementTypeOperatorWordDetector.class)) {
          addParseProblem(element, "The binding name '" + rulePosition._getTextWithoutException() + "' can only appear after a '{' or a ';'", rulePosition, false);
        }
        savedRulePosition = rulePosition;
        lastBinding = null;
      }
      else if (RulePosition.isOperatorOfType(rulePosition, AssignmentOperatorWordDetector.class)) {
        if (!RulePosition.isRulePositionOfType(lastRulePosition, BindingNameRule.class) && !RulePosition.isRulePositionOfType(lastRulePosition, StringLiteralRule.class)) {
          addParseProblem(element, "An '=' can only appear after a binding name", rulePosition, false);
        }
      }
      else if (RulePosition.isRulePositionOfType(rulePosition, BindingValueNamespaceRule.class)) {
        if (!RulePosition.isOperatorOfType(lastRulePosition, AssignmentOperatorWordDetector.class)) {
          addParseProblem(element, "The binding value namespace '" + rulePosition._getTextWithoutException() + "' can only appear after an '='", rulePosition, false);
        }
        else {
          savedRulePosition3 = rulePosition;
        }
      }
      else if (RulePosition.isRulePositionOfType(rulePosition, BindingValueRule.class)) {
        if (!RulePosition.isOperatorOfType(lastRulePosition, AssignmentOperatorWordDetector.class) && !(RulePosition.isOperatorOfType(lastRulePosition, ElementTypeOperatorWordDetector.class) && RulePosition.isRulePositionOfType(savedRulePosition3, BindingValueNamespaceRule.class))) {
          addParseProblem(element, "The binding value '" + rulePosition._getTextWithoutException() + "' can only appear after an '=' or a 'xxx:'", rulePosition, false);
        }
        else {
          lastBinding = addBinding(element, savedRulePosition2, savedRulePosition, savedRulePosition3, rulePosition, scanner);
        }
        savedRulePosition = null;
        savedRulePosition2 = null;
        savedRulePosition3 = null;
      }
      else if (RulePosition.isOperatorOfType(rulePosition, EndAssignmentWordDetector.class)) {
        if (!RulePosition.isRulePositionOfType(lastRulePosition, BindingValueRule.class) && !RulePosition.isRulePositionOfType(lastRulePosition, StringLiteralRule.class) && !RulePosition.isRulePositionOfType(lastRulePosition, WOOGNLRule.class)) {
          addParseProblem(element, "A ';' can only appear after a binding value", rulePosition, false);
        }
      }
      else if (RulePosition.isOperatorOfType(rulePosition, CloseDefinitionWordDetector.class)) {
        if (element != null) {
          element.setEndOffset(rulePosition.getTokenOffset() + 1);
        }
        if (!RulePosition.isOperatorOfType(lastRulePosition, OpenDefinitionWordDetector.class) && !RulePosition.isOperatorOfType(lastRulePosition, EndAssignmentWordDetector.class) && !RulePosition.isRulePositionOfType(lastRulePosition, BindingValueRule.class) && !RulePosition.isRulePositionOfType(lastRulePosition, StringLiteralRule.class) && !RulePosition.isRulePositionOfType(lastRulePosition, WOOGNLRule.class)) {
          addParseProblem(element, "A '}' can only appear after a ';' or a '{'", rulePosition, false);
        }
        else {
          element = null;
        }
        lastBinding = null;
      }
      else {
        addParseProblem(element, "'" + rulePosition._getTextWithoutException() + "' is an unknown keyword", rulePosition, false);
      }

      if (!whitespace && !comment) {
        lastRulePosition = rulePosition;
        rulePositions.push(rulePosition);
View Full Code Here

        // token we're dealing with.
        IRegion lineRegion = document.getLineInformationOfOffset(offset);
        WodScanner scanner = WodScanner.newWODScanner();
        scanner.setRange(document, lineRegion.getOffset(), lineRegion.getLength());
        boolean foundToken = false;
        RulePosition rulePosition = null;
        while (!foundToken && (rulePosition = scanner.nextRulePosition()) != null) {
          int tokenOffset = rulePosition.getTokenOffset();
          if (offset == lineRegion.getOffset() && offset == tokenOffset) {
            foundToken = true;
          } else if (offset > tokenOffset && offset <= rulePosition.getTokenEndOffset()) {
            foundToken = true;
          }
        }

        // We can't reliably use rulePosition here because it might be
        // null ...
        int tokenOffset = scanner.getTokenOffset();
        int tokenLength = scanner.getTokenLength();
        IRule rule = (rulePosition == null) ? null : rulePosition.getRule();
        // If you make a completion request in the middle of whitespace,
        // we don't want to select the whitespace, so zero out the
        // whitespace token offsets.
        if (rule instanceof WhitespaceRule) {
          int partialOffset = (offset - tokenOffset);
          offset += partialOffset;
          tokenOffset += partialOffset;
          tokenLength = 0;
        } else {
          viewer.setSelectedRange(offset, tokenLength - (offset - tokenOffset));
        }
        String token = document.get(tokenOffset, tokenLength);
        String tokenType = null;
        if (foundToken && rulePosition != null) {
          if (rulePosition.isRuleOfType(ElementNameRule.class)) {
            tokenType = PreferenceConstants.ELEMENT_NAME;
          } else if (rulePosition.isRuleOfType(ElementTypeRule.class)) {
            tokenType = PreferenceConstants.ELEMENT_TYPE;
          } else if (rulePosition.isRuleOfType(BindingNameRule.class)) {
            tokenType = PreferenceConstants.BINDING_NAME;
          } else if (rulePosition.isRuleOfType(BindingValueRule.class)) {
            tokenType = PreferenceConstants.BINDING_VALUE;
          } else if (rulePosition.isRuleOfType(OperatorRule.class)) {
            tokenOffset += tokenLength;
            tokenLength = 0;
            if (RulePosition.isOperatorOfType(rulePosition, CloseDefinitionWordDetector.class)) {
              tokenType = PreferenceConstants.ELEMENT_NAME;
            } else if (RulePosition.isOperatorOfType(rulePosition, ElementTypeOperatorWordDetector.class)) {
View Full Code Here

    while (offset != -1 && type == null) {
      offset = WodCompletionProcessor.scanBackFor(_document, offset, new char[] { '{' }, false, true);
      int colonOffset = WodCompletionProcessor.scanBackFor(_document, offset, new char[] { ':' }, false, true);
      if (colonOffset != -1) {
        _scanner.setRange(_document, colonOffset, _offset - colonOffset);
        RulePosition elementRulePosition = _scanner.getFirstRulePositionOfType(ElementTypeRule.class);
        if (elementRulePosition != null) {
          String elementTypeName = elementRulePosition.getText();
          type = BindingReflectionUtils.findElementType(_project, elementTypeName, false, cache);
          offset = -1;
        } else {
          // we didn't find a ElementTypeRule
          offset--;
View Full Code Here

  private ISelection _selection;

  public void run() {
    if (_selection instanceof TextSelection) {
      RulePosition rulePosition;
      try {
        TextSelection selection = (TextSelection) _selection;
        ITextEditor textEditor = (ITextEditor) _activeEditor;
        IEditorInput editorInput = textEditor.getEditorInput();
        IDocument document = textEditor.getDocumentProvider().getDocument(editorInput);

        WodScanner scanner = WodScanner.wodScannerForDocument(document);
        rulePosition = scanner.getRulePositionAtOffset(selection.getOffset());

        IProject project = null;
        if (editorInput instanceof FileEditorInput) {
          IFile file = ((FileEditorInput) editorInput).getFile();
          project = file.getProject();
        }

        IRule rule = rulePosition.getRule();
        if (rule instanceof ElementTypeRule) {
          String elementTypeName = rulePosition.getText();
          ComponentLocateScope componentLocateScope = new ComponentLocateScope(project, elementTypeName, true);
          LocalizedComponentsLocateResult localizedComponentsLocateResult = new LocalizedComponentsLocateResult();
          Locate locate = new Locate(componentLocateScope, localizedComponentsLocateResult);
          locate.locate();
View Full Code Here

    protected void parse(IDocument document) {
      try {
        List elementNameRulePositions = WodScanner.getRulePositionsOfType(document, ElementNameRule.class);
        Iterator elementNameRulePositionsIter = elementNameRulePositions.iterator();
        while (elementNameRulePositionsIter.hasNext()) {
          RulePosition rulePosition = (RulePosition) elementNameRulePositionsIter.next();
          Position p = rulePosition.getPosition();
          document.addPosition(SEGMENTS, p);
          fContent.add(new Segment(rulePosition.getText(), p));
        }
      } catch (BadPositionCategoryException e) {
        WodclipsePlugin.getDefault().log(e);
      } catch (BadLocationException e) {
        WodclipsePlugin.getDefault().log(e);
View Full Code Here

TOP

Related Classes of org.objectstyle.wolips.wodclipse.core.parser.RulePosition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.