OSDN Git Service

アウトライン解析処理を修正
authorbatxo <batxo@users.sourceforge.jp>
Wed, 15 Dec 2010 15:47:11 +0000 (00:47 +0900)
committerbatxo <batxo@users.sourceforge.jp>
Wed, 15 Dec 2010 15:47:11 +0000 (00:47 +0900)
icons/field_private_obj.gif [new file with mode: 0644]
src/coboled/editors/CobolElement.java
src/coboled/editors/CobolLabelProvider.java
src/coboled/editors/CobolParser.java

diff --git a/icons/field_private_obj.gif b/icons/field_private_obj.gif
new file mode 100644 (file)
index 0000000..1fe064e
Binary files /dev/null and b/icons/field_private_obj.gif differ
index 731e3ab..c77a82a 100644 (file)
@@ -6,8 +6,6 @@ import java.util.List;
 
 public class CobolElement {
        
-       public enum CobolElementType {DIVISION, SECTION, OTHER}; 
-
        private String name = null;
 
        private CobolElement parent = null;
index f032587..aa2ccb8 100644 (file)
@@ -13,19 +13,24 @@ public class CobolLabelProvider extends LabelProvider {
        private Image sectionImage = Activator.getImageDescriptor(
                        "icons/protected_co.gif").createImage();
 
-       private Image otherImage = Activator.getImageDescriptor(
+       private Image paragraphImage = Activator.getImageDescriptor(
                        "icons/private_co.gif").createImage();
+       
+       private Image dataImage = Activator.getImageDescriptor(
+                       "icons/field_private_obj.gif").createImage();
 
        @Override
        public Image getImage(Object element) {
                if (element instanceof CobolElement) {
-                       switch (((CobolElement) element).getType()) {
-                       case DIVISION:
+                       switch (((CobolElement)element).getType().getLebel()) {
+                       case 1:
                                return divisionImage;
-                       case SECTION:
+                       case 2:
                                return sectionImage;
-                       case OTHER:
-                               return otherImage;
+                       case 3:
+                               return paragraphImage;
+                       case 4:
+                               return dataImage;
                        default:
                                return null;
                        }
@@ -45,7 +50,7 @@ public class CobolLabelProvider extends LabelProvider {
        public void dispose() {
                divisionImage.dispose();
                sectionImage.dispose();
-               otherImage.dispose();
+               paragraphImage.dispose();
                super.dispose();
        }
 }
index 759c2f2..6827ac8 100644 (file)
@@ -6,67 +6,83 @@ import java.io.StringReader;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import coboled.editors.CobolElement.CobolElementType;
-
 public class CobolParser {
 
        public CobolElement parse(String source) {
-               CobolElement root = new CobolElement("root", CobolElementType.OTHER);
+               CobolElement root = new CobolElement("root", CobolElementType.ROOT);
                try {
                        BufferedReader reader = new BufferedReader(new StringReader(source));
                        int offset = 0;
                        String line = null;
+                       CobolElement work = root;
                        while ((line = reader.readLine()) != null) {
-
                                // 部の記述があった場合
-                               Pattern pattern = Pattern.compile("^.{6}\\s(\\s{0,3}[^\\s].*?DIVISION)\\.",
-                                               Pattern.CASE_INSENSITIVE);
+                               Pattern pattern = Pattern.compile("^.{6}\\s\\s{0,3}([^\\s]*)\\s+(DIVISION)\\.", Pattern.CASE_INSENSITIVE);
                                Matcher matcher = pattern.matcher(line);
                                boolean match = matcher.matches();
                                if (match) {
-                                       CobolElement divisionElement = new CobolElement(matcher
-                                                       .group(1).trim(), CobolElementType.DIVISION);
-                                       divisionElement.setParent(root);
-                                       divisionElement.setOffset(offset);
-                                       root.appendChild(divisionElement);
+                                       String name = matcher.group(1) + " " + matcher.group(2); 
+                                       CobolElement element = new CobolElement(name, CobolElementType.DIVISION);
+                                       CobolElement parent = getParentElement(work, element);
+                                       element.setParent(parent);
+                                       element.setOffset(offset);
+                                       root.appendChild(element);
+                                       work = element;
                                        offset = offset + line.length() + 1;
                                        continue;
                                }
 
                                // 節の記述があった場合
-                               Pattern pattern2 = Pattern.compile("^.{6}\\s(\\s{0,3}[^\\s].*?SECTION)\\.",
-                                               Pattern.CASE_INSENSITIVE);
+                               Pattern pattern2 = Pattern.compile("^.{6}\\s\\s{0,3}([^\\s]*)\\s+(SECTION)\\.", Pattern.CASE_INSENSITIVE);
                                Matcher matcher2 = pattern2.matcher(line);
                                boolean match2 = matcher2.matches();
                                if (match2) {
-                                       CobolElement sectionElement = new CobolElement(matcher2
-                                                       .group(1).trim(), CobolElementType.SECTION);
-                                       CobolElement parent = getLastElement(root);
-                                       sectionElement.setParent(parent);
-                                       sectionElement.setOffset(offset);
-                                       parent.appendChild(sectionElement);
+                                       String name = matcher2.group(1) + " " + matcher2.group(2);
+                                       CobolElement element = new CobolElement(name, CobolElementType.SECTION);
+                                       CobolElement parent = getParentElement(work, element);
+                                       element.setParent(parent);
+                                       parent.appendChild(element);
+                                       element.setOffset(offset);
+                                       work = element;
                                        offset = offset + line.length() + 1;
                                        continue;
                                }
-
-                               // その他
-                               Pattern pattern3 = Pattern.compile("^.{6}\\s(\\s{0,3}[^\\s].*)",
-                                               Pattern.CASE_INSENSITIVE);
+                               
+                               // データ定義
+                               Pattern pattern4 = Pattern.compile("^.{6}\\s\\s{0,3}([0-9][0-9]\\s+[^\\s]*)(.*)", Pattern.CASE_INSENSITIVE);
+                               Matcher matcher4 = pattern4.matcher(line);
+                               boolean match4 = matcher4.matches();
+                               if (match4) {
+                                       String name = matcher4.group(1);
+                                       CobolElement element = new CobolElement(name, CobolElementType.DATA);
+                                       CobolElement parent = getParentElement(work, element);
+                                       element.setParent(parent);
+                                       element.setOffset(offset);
+                                       parent.appendChild(element);
+                                       work = element;
+                                       offset = offset + line.length() + 1;
+                                       continue;
+                               }
+                               
+                               // 段落
+                               Pattern pattern3 = Pattern.compile("^.{6}\\s\\s{0,3}([^\\s]+)\\s*(.*)", Pattern.CASE_INSENSITIVE);
                                Matcher matcher3 = pattern3.matcher(line);
                                boolean match3 = matcher3.matches();
                                if (match3) {
-                                       CobolElement sectionElement = new CobolElement(matcher3
-                                                       .group(1), CobolElementType.OTHER);
-                                       CobolElement parent = getLastElement(root);
-                                       sectionElement.setParent(parent);
-                                       sectionElement.setOffset(offset);
-                                       parent.appendChild(sectionElement);
-                                       offset = offset + line.length() + 1;
-                                       continue;
+                                       String name = matcher3.group(1);
+                                       if(name.indexOf("-EXIT") == -1) {
+                                               CobolElement element = new CobolElement(name, CobolElementType.PARAGRAPH);
+                                               CobolElement parent = getParentElement(work, element);
+                                               element.setParent(parent);
+                                               element.setOffset(offset);
+                                               parent.appendChild(element);
+                                               work = element;
+                                               offset = offset + line.length() + 1;
+                                               continue;
+                                       }
                                }
-
+                               
                                offset = offset + line.length() + 1;
-
                        }
                } catch (IOException e) {
                        // TODO 自動生成された catch ブロック
@@ -74,12 +90,16 @@ public class CobolParser {
                }
                return root;
        }
-
-       private static CobolElement getLastElement(CobolElement element) {
-               if (element.getChildren() != null && element.getChildren().length != 0) {
-                       int lastIndex = element.getChildren().length - 1;
-                       return element.getChildren()[lastIndex];
+       
+       private CobolElement getParentElement(CobolElement element, CobolElement element2) {
+               CobolElementType type = element.getType();
+               CobolElementType type2 = element2.getType(); 
+               if(type.compareTo(type2) > 0) {
+                       return element;
+               } else if(type.compareTo(type2) == 0) {
+                       return element.getParent();
+               } else {
+                       return getParentElement(element.getParent(), element2);
                }
-               return element;
        }
 }