This is an automated email from the ASF dual-hosted git repository.

lkishalmi pushed a commit to branch use-snakeyaml-parser-improved
in repository https://gitbox.apache.org/repos/asf/netbeans.git

commit a6ba4ab4ad16a8e85b537ef19a3cfe2bbbb834c7
Author: Laszlo Kishalmi <laszlo.kisha...@gmail.com>
AuthorDate: Mon Oct 4 23:21:19 2021 -0700

    Replace JRuby YAML parser to SnakeYaml
---
 ide/languages.yaml/nbproject/project.xml           |  15 +-
 .../modules/languages/yaml/YamlParser.java         | 145 ++--------------
 .../modules/languages/yaml/YamlParserResult.java   |  60 +------
 .../modules/languages/yaml/YamlScanner.java        | 193 ++++-----------------
 .../languages/yaml/YamlSemanticAnalyzer.java       |  84 +++------
 5 files changed, 86 insertions(+), 411 deletions(-)

diff --git a/ide/languages.yaml/nbproject/project.xml 
b/ide/languages.yaml/nbproject/project.xml
index 2941904..09f58a9 100644
--- a/ide/languages.yaml/nbproject/project.xml
+++ b/ide/languages.yaml/nbproject/project.xml
@@ -35,21 +35,12 @@
                     </run-dependency>
                 </dependency>
                 <dependency>
-                    <code-name-base>org.netbeans.libs.bytelist</code-name-base>
+                    
<code-name-base>org.netbeans.libs.snakeyaml_engine</code-name-base>
                     <build-prerequisite/>
                     <compile-dependency/>
                     <run-dependency>
-                        <release-version>1</release-version>
-                        <specification-version>0.1</specification-version>
-                    </run-dependency>
-                </dependency>
-                <dependency>
-                    <code-name-base>org.netbeans.libs.jvyamlb</code-name-base>
-                    <build-prerequisite/>
-                    <compile-dependency/>
-                    <run-dependency>
-                        <release-version>1</release-version>
-                        <specification-version>0.2.2</specification-version>
+                        <release-version>2</release-version>
+                        <specification-version>2.3</specification-version>
                     </run-dependency>
                 </dependency>
                 <dependency>
diff --git 
a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlParser.java 
b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlParser.java
index 6b6d85b..86db263 100644
--- a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlParser.java
+++ b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlParser.java
@@ -18,30 +18,14 @@
  */
 package org.netbeans.modules.languages.yaml;
 
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStreamWriter;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.swing.event.ChangeListener;
-import org.jruby.util.ByteList;
-import org.jvyamlb.Composer;
-import org.jvyamlb.ParserImpl;
-import org.jvyamlb.PositioningComposerImpl;
-import org.jvyamlb.PositioningParserImpl;
-import org.jvyamlb.PositioningScannerImpl;
-import org.jvyamlb.ResolverImpl;
-import org.jvyamlb.YAMLConfig;
-import org.jvyamlb.events.Event;
-import org.jvyamlb.exceptions.PositionedComposerException;
-import org.jvyamlb.exceptions.PositionedParserException;
-import org.jvyamlb.exceptions.PositionedScannerException;
-import org.jvyamlb.nodes.Node;
 import org.netbeans.api.lexer.Token;
 import org.netbeans.api.lexer.TokenHierarchy;
 import org.netbeans.api.lexer.TokenId;
@@ -54,6 +38,12 @@ import org.netbeans.modules.parsing.spi.ParseException;
 import org.netbeans.modules.parsing.spi.Parser;
 import org.netbeans.modules.parsing.spi.SourceModificationEvent;
 import org.openide.util.NbBundle;
+import org.snakeyaml.engine.v2.api.LoadSettings;
+import org.snakeyaml.engine.v2.composer.Composer;
+import org.snakeyaml.engine.v2.nodes.Node;
+import org.snakeyaml.engine.v2.parser.ParserImpl;
+import org.snakeyaml.engine.v2.scanner.ScannerImpl;
+import org.snakeyaml.engine.v2.scanner.StreamReader;
 
 /**
  * Parser for YAML. Delegates to the YAML parser shipped with JRuby (jvyamlb)
@@ -103,7 +93,7 @@ public class YamlParser extends Parser {
     }
 
     private YamlParserResult resultForTooLargeFile(Snapshot snapshot) {
-        YamlParserResult result = new 
YamlParserResult(Collections.<Node>emptyList(), this, snapshot, false, null, 
null);
+        YamlParserResult result = new 
YamlParserResult(Collections.<Node>emptyList(), this, snapshot, false);
         // FIXME this can violate contract of DefaultError (null fo)
         DefaultError error = new DefaultError(null, 
NbBundle.getMessage(YamlParser.class, "TooLarge"), null,
                 snapshot.getSource().getFileObject(), 0, 0, Severity.WARNING);
@@ -203,122 +193,23 @@ public class YamlParser extends Parser {
             if (isTooLarge(source)) {
                 return resultForTooLargeFile(snapshot);
             }
-            ByteList byteList;
-            int[] byteToUtf8 = null;
-            int[] utf8toByte = null;
-
-            byte[] bytes = source.getBytes("UTF-8"); // NOI18N
-            if (bytes.length == source.length()) {
-                // No position translations necessary - this should be fast
-                byteList = new ByteList(bytes);
-            } else {
-                // There's some encoding happening of unicode characters.
-                // I need to produce functions to translate between a byte 
offset
-                // and a unicode offset.
-                // I couldn't find an API for this in the various Charset 
functions.
-                // So for now, here is a fantastically lame but functional way 
to do it:
-                // I'm encoding the string, one character at a time, flushing 
after
-                // each operation to compute the current byte offset. I then 
build
-                // up an array of these offsets such that I can do quick 
translations.
-                ByteArrayOutputStream out = new ByteArrayOutputStream(2 * 
source.length());
-                OutputStreamWriter writer = new OutputStreamWriter(out, 
"UTF-8"); // NOI18N
-                utf8toByte = new int[source.length()];
-                int currentPos = 0;
-                for (int i = 0, n = source.length(); i < n; i++) {
-                    writer.write(source.charAt(i));
-                    writer.flush(); // flush because otherwise we don't know 
the correct offset
-                    utf8toByte[i] = currentPos;
-                    currentPos = out.size();
-                }
-
-                if (currentPos > 0) {
-                    byteToUtf8 = new int[currentPos];
-                    for (int i = 0, n = utf8toByte.length; i < n; i++) {
-                        byteToUtf8[utf8toByte[i]] = i;
-                    }
-                    // Fill in holes - these are the middles of unicode 
encodings.
-                    int last = 0;
-                    for (int i = 0, n = byteToUtf8.length; i < n; i++) {
-                        int p = byteToUtf8[i];
-                        if (p == 0) {
-                            byteToUtf8[i] = last;
-                        } else {
-                            last = p;
-                        }
-                    }
-                } else {
-                    byteToUtf8 = new int[0];
-                }
-
-                byteList = new ByteList(out.toByteArray());
-            }
-
-            final List<DefaultError> errors = new ArrayList<>();
-            PositioningScannerImpl scanner = new 
PositioningScannerImpl(byteList) {
-                @Override
-                protected void scannerException(String when, String what, 
String note) {
-                    try {
-                        super.scannerException(when, what, note);
-                    } catch (PositionedScannerException pse) {
-                        int pos = pse.getPosition().offset;
-                        String message = pse.getMessage();
-                        if (message != null && message.length() > 0) {
-                            errors.add(processError(message, snapshot, pos));
-                        }
-                        // Move local pointer to the next char to make progress
-                        this.pointer++;
-                    }
-                }
-            };
-            PositioningParserImpl parser = new PositioningParserImpl(scanner) {
-                @Override
-                protected ParserImpl.ProductionEnvironment 
getEnvironment(YAMLConfig cfg) {
-                    return new PositioningProductionEnvironment(cfg) {
-                        @Override
-                        protected void parserException(String when, String 
what, String note, org.jvyamlb.tokens.Token t) {
-                            try {
-                                super.parserException(when, what, note, t);
-                            } catch (PositionedParserException ppe) {
-                                int pos = ppe.getPosition().offset;
-                                String message = ppe.getMessage();
-                                if (message != null && message.length() > 0) {
-                                    errors.add(processError(message, snapshot, 
pos));
-                                }
-                            }
-                        }
-                    };
-                }
-            };
-            Composer composer = new PositioningComposerImpl(parser, new 
ResolverImpl()) {
-                @Override
-                protected void composerException(String when, String what, 
String note, Event e) {
-                    try {
-                        super.composerException(when, what, note, e);
-                    } catch (PositionedComposerException pce) {
-                        int pos = pce.getPosition().offset;
-                        String message = pce.getMessage();
-                        if (message != null && message.length() > 0) {
-                            errors.add(processError(message, snapshot, pos));
-                        }
-                    }
-                }
-            };
-            Iterator iterator = composer.eachNode();
-            while (iterator.hasNext()) {
-                Node node = (Node) iterator.next();
+            LoadSettings settings = LoadSettings.builder().build();
+            ScannerImpl scanner = new ScannerImpl(settings, new 
StreamReader(settings, source));
+            ParserImpl parser = new ParserImpl(settings, scanner);
+            Composer composer = new Composer(settings, parser);
+            
+            while (composer.hasNext()) {
+                Node node = composer.next();
                 if (node == null) {
                     break;
                 }
                 nodes.add(node);
             }
-
-            YamlParserResult result = new YamlParserResult(nodes, this, 
snapshot, true, byteToUtf8, utf8toByte);
-            if (!errors.isEmpty()) {
-                result.addError(errors.get(0));
-            }
+            //TODO: add errors
+            YamlParserResult result = new YamlParserResult(nodes, this, 
snapshot, true);
             return result;
         } catch (Exception ex) {
-            YamlParserResult result = new 
YamlParserResult(Collections.<Node>emptyList(), this, snapshot, false, null, 
null);
+            YamlParserResult result = new 
YamlParserResult(Collections.<Node>emptyList(), this, snapshot, false);
             String message = ex.getMessage();
             if (message != null && message.length() > 0) {
                 result.addError(processError(message, snapshot, 0));
@@ -403,7 +294,7 @@ public class YamlParser extends Parser {
 
             lastResult = parse(source, snapshot);
         } catch (Exception ioe) {
-            lastResult = new YamlParserResult(Collections.<Node>emptyList(), 
this, snapshot, false, null, null);
+            lastResult = new YamlParserResult(Collections.<Node>emptyList(), 
this, snapshot, false);
         }
     }
 }
diff --git 
a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlParserResult.java
 
b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlParserResult.java
index 8cf51c4..e289ecb 100644
--- 
a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlParserResult.java
+++ 
b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlParserResult.java
@@ -21,14 +21,12 @@ package org.netbeans.modules.languages.yaml;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import org.jvyamlb.Position.Range;
-import org.jvyamlb.Positionable;
-import org.jvyamlb.nodes.Node;
 import org.netbeans.modules.csl.api.Error;
 import org.netbeans.modules.csl.api.OffsetRange;
 import org.netbeans.modules.csl.api.StructureItem;
 import org.netbeans.modules.csl.spi.ParserResult;
 import org.netbeans.modules.parsing.api.Snapshot;
+import org.snakeyaml.engine.v2.nodes.Node;
 
 /**
  * A result from Parsing YAML
@@ -40,15 +38,11 @@ public class YamlParserResult extends ParserResult {
     private final List<Error> errors = new ArrayList<Error>();
     private List<Node> nodes;
     private List<? extends StructureItem> items;
-    private int[] byteToUtf8;
-    private int[] utf8ToByte;
 
-    public YamlParserResult(List<Node> nodes, YamlParser parser, Snapshot 
snapshot, boolean valid, int[] byteToUtf8, int[] utf8ToByte) {
+    public YamlParserResult(List<Node> nodes, YamlParser parser, Snapshot 
snapshot, boolean valid) {
         super(snapshot);
         assert nodes != null;
         this.nodes = nodes;
-        this.byteToUtf8 = byteToUtf8;
-        this.utf8ToByte = utf8ToByte;
     }
 
     public List<Node> getRootNodes() {
@@ -82,51 +76,9 @@ public class YamlParserResult extends ParserResult {
         this.items = items;
     }
 
-    public int convertUtf8ToByte(int utf8Pos) {
-        if (utf8ToByte == null) {
-            return utf8Pos;
-        }
-        if (utf8Pos < utf8ToByte.length) {
-            return utf8ToByte[utf8Pos];
-        } else {
-            return utf8ToByte.length;
-        }
-    }
-
-    public int convertByteToUtf8(int bytePos) {
-        if (byteToUtf8 == null) {
-            return bytePos;
-        }
-        if (bytePos < byteToUtf8.length) {
-            return byteToUtf8[bytePos];
-        } else {
-            return byteToUtf8.length;
-        }
-    }
-
-    public OffsetRange getAstRange(Range range) {
-        int start = range.start.offset;
-        int end = range.end.offset;
-        if (byteToUtf8 == null) {
-            return new OffsetRange(start, end);
-        } else {
-            int s, e;
-            if (start >= byteToUtf8.length) {
-                s = byteToUtf8.length;
-            } else {
-                s = byteToUtf8[start];
-            }
-            if (end >= byteToUtf8.length) {
-                e = byteToUtf8.length;
-            } else {
-                e = byteToUtf8[end];
-            }
-
-            return new OffsetRange(s, e);
-        }
-    }
-
-    public OffsetRange getAstRange(Node node) {
-        return getAstRange(((Positionable) node).getRange());
+    public static OffsetRange getAstRange(Node node) {
+        int s = node.getStartMark().get().getPointer();
+        int e = node.getEndMark().get().getPointer();
+        return new OffsetRange(s, e);
     }
 }
diff --git 
a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlScanner.java 
b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlScanner.java
index a1e3c40..495a4fc 100644
--- 
a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlScanner.java
+++ 
b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlScanner.java
@@ -19,11 +19,10 @@
 package org.netbeans.modules.languages.yaml;
 
 import java.io.CharConversionException;
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.IdentityHashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -31,11 +30,6 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.swing.ImageIcon;
 import javax.swing.text.BadLocationException;
-import org.jruby.util.ByteList;
-import org.jvyamlb.Positionable;
-import org.jvyamlb.nodes.Node;
-import org.jvyamlb.nodes.PositionedScalarNode;
-import org.jvyamlb.nodes.PositionedSequenceNode;
 import org.netbeans.editor.BaseDocument;
 import org.netbeans.editor.Utilities;
 import org.netbeans.modules.csl.api.ElementHandle;
@@ -50,6 +44,7 @@ import org.netbeans.modules.csl.spi.GsfUtilities;
 import org.netbeans.modules.csl.spi.ParserResult;
 import org.openide.util.Exceptions;
 import org.openide.xml.XMLUtil;
+import org.snakeyaml.engine.v2.nodes.Node;
 
 /**
  * Structure Scanner for YAML
@@ -92,22 +87,20 @@ public class YamlScanner implements StructureScanner {
             return Collections.emptyMap();
         }
 
-        Map<String, List<OffsetRange>> folds = new HashMap<String, 
List<OffsetRange>>();
-        List<OffsetRange> codeblocks = new ArrayList<OffsetRange>();
+        Map<String, List<OffsetRange>> folds = new HashMap<>();
+        List<OffsetRange> codeblocks = new ArrayList<>();
         folds.put("tags", codeblocks); // NOI18N
 
         BaseDocument doc = (BaseDocument) 
result.getSnapshot().getSource().getDocument(false);
 
-        //if (doc != null) {
-            for (StructureItem item : items) {
-                try {
-                    addBlocks(result, doc, result.getSnapshot().getText(), 
codeblocks, item);
-                } catch (BadLocationException ble) {
-                    Exceptions.printStackTrace(ble);
-                    break;
-                }
+        for (StructureItem item : items) {
+            try {
+                addBlocks(result, doc, result.getSnapshot().getText(), 
codeblocks, item);
+            } catch (BadLocationException ble) {
+                Exceptions.printStackTrace(ble);
+                break;
             }
-        //}
+        }
 
         return folds;
     }
@@ -143,18 +136,10 @@ public class YamlScanner implements StructureScanner {
         private final String name;
         private List<YamlStructureItem> children;
         private final Node node;
-        private final long begin;
-        private final long end;
 
-        YamlStructureItem(Node node, String name, long begin, long end) {
+        YamlStructureItem(Node node, String name) {
             this.node = node;
             this.name = name;
-            this.begin = begin;
-            this.end = end;
-        }
-
-        YamlStructureItem(Node node, String name, OffsetRange positions) {
-            this(node, name, positions.getStart(), positions.getEnd());
         }
 
         @Override
@@ -202,10 +187,10 @@ public class YamlScanner implements StructureScanner {
         private static List<? extends StructureItem> 
initialize(YamlParserResult result, List<Node> roots) {
             // Really need IdentitySet or IdentityHashSet but there isn't one 
built in
             // or in our available libraries...
-            IdentityHashMap<Object, Boolean> seen = new 
IdentityHashMap<Object, Boolean>(100);
-            List<StructureItem> children = new ArrayList<StructureItem>();
+            Set<Node> seen = new HashSet<>(100);
+            List<StructureItem> children = new ArrayList<>();
             for (Node root : roots) {
-                YamlStructureItem fakeRoot = new YamlStructureItem(root, null, 
OffsetRange.NONE);
+                YamlStructureItem fakeRoot = new YamlStructureItem(root, null);
                 initializeChildren(result, fakeRoot, seen, 0);
                 children.addAll(fakeRoot.children);
             }
@@ -213,138 +198,22 @@ public class YamlScanner implements StructureScanner {
         }
 
         @SuppressWarnings("unchecked")
-        private static void initializeChildren(YamlParserResult result, 
YamlStructureItem item, IdentityHashMap<Object, Boolean> seen, int depth) {
-            if (depth > 20) {
-                // Avoid boundless recursion in some yaml parse trees
-                // This should already be handled now with the seen map, but
-                // leave this just in case since we're right before code freeze
-                item.children = Collections.emptyList();
-                return;
-            }
+        private static void initializeChildren(YamlParserResult result, 
YamlStructureItem item, Set<Node> seen, int depth) {
             Node node = item.node;
-            Object value = node.getValue();
-            if (value == null) {
-                item.children = Collections.emptyList();
-                return;
-            }
-
-            boolean alreadySeen = false;
-            if (seen.containsKey(value)) {
-                alreadySeen = true;
-            }
-
-            seen.put(value, Boolean.TRUE);
-            if (value instanceof Map) {
-                Map map = (Map) value;
-                List<YamlStructureItem> children = new 
ArrayList<YamlStructureItem>();
-                item.children = children;
-
-                Set<Map.Entry> entrySet = map.entrySet();
-
-                for (Map.Entry entry : entrySet) {
-
-                    Object key = entry.getKey();
-                    if (key instanceof PositionedSequenceNode) {
-                        PositionedSequenceNode psn = (PositionedSequenceNode) 
key;
-                        Object keyValue = psn.getValue();
-                        assert keyValue instanceof List;
-                        @SuppressWarnings("unchecked")
-                        List<Node> list = (List<Node>) keyValue;
-                        for (Node o : list) {
-                            //String childName = o.getValue().toString();
-                            Object childValue = o.getValue();
-                            if (childValue instanceof List || childValue 
instanceof Map) {
-                                children.add(new YamlStructureItem(o, "list 
item", result.getAstRange(o)));
-                            } else {
-                                String childName = childValue.toString();
-                                children.add(new YamlStructureItem(o, 
childName, result.getAstRange(o)));
-                            }
-                        }
-                        Object entryValue = entry.getValue();
-                        if (entryValue instanceof PositionedSequenceNode) {
-                            psn = (PositionedSequenceNode) entryValue;
-                            keyValue = psn.getValue();
-                            assert keyValue instanceof List;
-                            list = (List<Node>) keyValue;
-                            for (Node o : list) {
-                                //String childName = o.getValue().toString();
-                                Object childValue = o.getValue();
-                                if (childValue instanceof List || childValue 
instanceof Map) {
-                                    children.add(new YamlStructureItem(o, 
"list item", result.getAstRange(o)));
-                                } else {
-                                    String childName = childValue.toString();
-                                    children.add(new YamlStructureItem(o, 
childName, result.getAstRange(o)));
-                                }
-                            }
-                        }
-                    } else if (key instanceof PositionedScalarNode) {
-                        //ScalarNode scalar = (ScalarNode)key;
-                        PositionedScalarNode scalar = (PositionedScalarNode) 
key;
-                        Object childNameValue = scalar.getValue();
-                        assert childNameValue instanceof ByteList;
-                        ByteList byteListChildName = (ByteList) childNameValue;
-                        String childName = byteListChildName.toString();
-                        try {
-                            childName = new String(byteListChildName.bytes, 
"UTF-8"); //NOI18N
-                        } catch (UnsupportedEncodingException ex) {
-                            Exceptions.printStackTrace(ex);
-                        }
-                        Node child = (Node) entry.getValue();
-                        if (child != null) {
-                            int e = result.convertByteToUtf8(((Positionable) 
child).getRange().end.offset);
-                            // If you have an "empty" key, e.g.
-                            //   foo:
-                            //   bar: Hello World
-                            // here foo is "empty" but I get a child of "" 
positioned at the beginning
-                            // of "bar", which is wrong. In this case, don't 
include the child in the
-                            // position bounds.
-                            if (child.getValue() instanceof ByteList && 
((ByteList) child.getValue()).length() == 0) {
-                                e = result.convertByteToUtf8(((Positionable) 
scalar).getRange().end.offset);
-                            }
-                            children.add(new YamlStructureItem(child, 
childName.trim(),
-                                    // Range: beginning of -key- to ending of 
-value-
-                                    result.convertByteToUtf8(((Positionable) 
scalar).getRange().start.offset),
-                                    e));
-                        }
-                    }
-                }
-                // Keep the list ordered, same order as in the document!!
-                Collections.sort(children);
-            } else if (value instanceof List) {
-                @SuppressWarnings("unchecked")
-                List<Node> list = (List<Node>) value;
-
-                List<YamlStructureItem> children = new 
ArrayList<YamlStructureItem>(list.size());
-                item.children = children;
-                for (Node o : list) {
-                    //String childName = o.getValue().toString();
-                    Object childValue = o.getValue();
-                    if (childValue instanceof List || childValue instanceof 
Map) {
-                        children.add(new YamlStructureItem(o, "list item", 
result.getAstRange(o)));
-                    } else {
-                        String childName = childValue.toString();
-                        children.add(new YamlStructureItem(o, childName, 
result.getAstRange(o)));
-                    }
-                }
-            } else {
-                item.children = Collections.emptyList();
+            if (seen.contains(node)) {
+                return;                
             }
-
-            if (item.children.size() > 0) {
-                for (YamlStructureItem child : item.children) {
-                    if (alreadySeen) {
-                        // I delayed the alreadySeen abort to the creation of
-                        // children rather than processing the main node itself
-                        // such that we include one level of referenced data.
-                        // See the fixtures3.yml test for example, where we 
want
-                        // to include the created_on attribute in the sites 
that
-                        // include it <<.
-                        child.children = Collections.emptyList();
-                    } else {
-                        initializeChildren(result, child, seen, depth + 1);
-                    }
-                }
+            seen.add(node);
+            
+            switch (node.getNodeType()) {
+                case MAPPING:
+                    break;
+                case SEQUENCE:
+                    break;
+                case SCALAR:
+                    break;
             }
+            item.children = Collections.emptyList();
         }
 
         @Override
@@ -355,12 +224,12 @@ public class YamlScanner implements StructureScanner {
 
         @Override
         public long getPosition() {
-            return begin;
+            return node.getStartMark().get().getPointer();
         }
 
         @Override
         public long getEndPosition() {
-            return end;
+            return node.getEndMark().get().getPointer();
         }
 
         @Override
@@ -370,7 +239,7 @@ public class YamlScanner implements StructureScanner {
 
         @Override
         public int compareTo(YamlStructureItem other) {
-            return (int) (begin - other.begin);
+            return (int) (getPosition() - other.getPosition());
         }
 
     }
diff --git 
a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSemanticAnalyzer.java
 
b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSemanticAnalyzer.java
index b68083b..35db1e9 100644
--- 
a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSemanticAnalyzer.java
+++ 
b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSemanticAnalyzer.java
@@ -24,16 +24,19 @@ import java.util.IdentityHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import org.jvyamlb.Position.Range;
-import org.jvyamlb.nodes.Node;
-import org.jvyamlb.nodes.PositionedScalarNode;
-import org.jvyamlb.nodes.PositionedSequenceNode;
 import org.netbeans.modules.csl.api.ColoringAttributes;
 import org.netbeans.modules.csl.api.OffsetRange;
 import org.netbeans.modules.csl.api.SemanticAnalyzer;
 import org.netbeans.modules.parsing.spi.Parser.Result;
 import org.netbeans.modules.parsing.spi.Scheduler;
 import org.netbeans.modules.parsing.spi.SchedulerEvent;
+import org.snakeyaml.engine.v2.nodes.MappingNode;
+import org.snakeyaml.engine.v2.nodes.Node;
+import org.snakeyaml.engine.v2.nodes.NodeTuple;
+
+import static org.snakeyaml.engine.v2.nodes.NodeType.*;
+import org.snakeyaml.engine.v2.nodes.ScalarNode;
+import org.snakeyaml.engine.v2.nodes.SequenceNode;
 
 /**
  * Semantic Analyzer for YAML
@@ -105,62 +108,31 @@ public class YamlSemanticAnalyzer extends 
SemanticAnalyzer {
             // Avoid boundless recursion; some datastructures from YAML appear 
to be recursive
             return;
         }
-        Object value = node.getValue();
-        if (seen.containsKey(value)) {
+        if (seen.containsKey(node)) {
             return;
         }
-        seen.put(value, Boolean.TRUE);
-
-        if (value instanceof Map) {
-            Map map = (Map) value;
-            Set<Map.Entry> entrySet = map.entrySet();
-
-            for (Map.Entry entry : entrySet) {
-                Object key = entry.getKey();
-                if (key instanceof PositionedSequenceNode) {
-                    PositionedSequenceNode psn = (PositionedSequenceNode) key;
-                    Object keyValue = psn.getValue();
-                    assert keyValue instanceof List;
-                    List<Node> list = (List<Node>) keyValue;
-                    for (Node child : list) {
-                        if (child == node) {
-                            // Circularity??
-                            return;
-                        }
-                        addHighlights(ypr, child, highlights, seen, depth + 1);
-                    }
-                    Object entryValue = entry.getValue();
-                    if (entryValue instanceof PositionedSequenceNode) {
-                        psn = (PositionedSequenceNode) entryValue;
-                        keyValue = psn.getValue();
-                        assert keyValue instanceof List;
-                        list = (List<Node>) keyValue;
-                        for (Node o : list) {
-                            if (o == node) {
-                                // Circularity??
-                                return;
-                            }
-                            addHighlights(ypr, o, highlights, seen, depth + 1);
-                        }
-                    }
-                } else if (key instanceof PositionedScalarNode){
-                    PositionedScalarNode scalar = (PositionedScalarNode) key;
-                    Range r = scalar.getRange();
-                    OffsetRange range = ypr.getAstRange(r);
-                    highlights.put(range, ColoringAttributes.METHOD_SET);
-                    Node child = (Node) entry.getValue();
-                    addHighlights(ypr, child, highlights, seen, depth + 1);
+        seen.put(node, Boolean.TRUE);
+
+        switch (node.getNodeType()) {
+            case MAPPING:
+                MappingNode mappings = (MappingNode) node;
+                List<NodeTuple> tuples = mappings.getValue();
+                for (NodeTuple tuple : tuples) {
+                    addHighlights(ypr, tuple.getValueNode(), highlights, seen, 
depth + 1);
                 }
-            }
-        } else if (value instanceof List) {
-            List<Node> list = (List<Node>) value;
-            for (Node child : list) {
-                if (child == node) {
-                    // Circularity??
-                    return;
+                break;
+            case SEQUENCE:
+                SequenceNode sequence = (SequenceNode) node;
+                List<Node> nodes = sequence.getValue();
+                for (Node node1 : nodes) {
+                    addHighlights(ypr, node, highlights, seen, depth + 1);
                 }
-                addHighlights(ypr, child, highlights, seen, depth + 1);
-            }
+                break;
+            case SCALAR:
+                ScalarNode scalar = (ScalarNode) node;
+                OffsetRange range = YamlParserResult.getAstRange(scalar);
+                highlights.put(range, ColoringAttributes.METHOD_SET);
+                break;
         }
     }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to