You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2021/10/16 18:13:52 UTC
[netbeans] branch use-snakeyaml-parser-improved created (now
3b2b6c8)
This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a change to branch use-snakeyaml-parser-improved
in repository https://gitbox.apache.org/repos/asf/netbeans.git.
at 3b2b6c8 Added unittest for YamlSection.
This branch includes the following new commits:
new 4fdface Added snakeyaml-engine 2.3 as a library project
new a6ba4ab Replace JRuby YAML parser to SnakeYaml
new cae021b Made the new parser work against the tests
new c3e2a02 Working YAML Parser without auto-recovery.
new 2e9400a Made the YAML parser recover from errors.
new 3b2b6c8 Added unittest for YamlSection.
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[netbeans] 05/06: Made the YAML parser recover from errors.
Posted by lk...@apache.org.
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 2e9400a80231a4c16325a346d32bf7c3fba29c9c
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Wed Oct 13 15:50:06 2021 -0700
Made the YAML parser recover from errors.
---
.../modules/languages/yaml/YamlParser.java | 55 ++++++++++++++--------
.../modules/languages/yaml/YamlParserResult.java | 11 ++++-
.../modules/languages/yaml/YamlSection.java | 36 +++++++++-----
3 files changed, 70 insertions(+), 32 deletions(-)
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 ff230f4..9ce1ecf 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,7 +18,6 @@
*/
package org.netbeans.modules.languages.yaml;
-import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
@@ -103,7 +102,6 @@ public class YamlParser extends org.netbeans.modules.parsing.spi.Parser {
if (startReplace == -1) {
return;
}
-
while (startReplace > -1) {
int endReplace = source.indexOf(endToken, startReplace) + 1;
if (endReplace > startReplace) {
@@ -178,28 +176,45 @@ public class YamlParser extends org.netbeans.modules.parsing.spi.Parser {
YamlParserResult result = new YamlParserResult(snapshot);
- Deque<YamlSection> sources = new LinkedList<>();
+ LinkedList<YamlSection> sources = new LinkedList<>();
sources.push(new YamlSection(sb.toString()));
+ int sourceLength = Integer.MAX_VALUE;
+ int stallCounter = 0;
while (!sources.isEmpty()) {
+ int len = 0;
+ for (YamlSection source : sources) {
+ len += source.length();
+ }
- YamlSection section = sources.pop();
- try {
- List<? extends StructureItem> items = section.collectItems();
- result.addStructure(items);
- } catch (ScannerException se) {
- result.addError(section.processScannerException(snapshot, se));
-// YamlSection after = section.after(se.getProblemMark().get().getIndex());
-// YamlSection before = section.before(se.getContextMark().get().getIndex());
-// if (!after.isEmpty()) sources.push(after);
-// if (!before.isEmpty()) sources.push(before);
- } catch (ParserException pe ){
- result.addError(section.processParserException(snapshot, pe));
-// sources.addAll(section.splitOnParserException(pe));
- } catch (Exception ex) {
- String message = ex.getMessage();
- if (message != null && message.length() > 0) {
- result.addError(processError(message, snapshot, 0));
+ if (len < sourceLength) {
+ sourceLength = len;
+ stallCounter = 0;
+ } else {
+ stallCounter++;
+ }
+ if (stallCounter < 2) {
+ YamlSection section = sources.pop();
+ try {
+ List<? extends StructureItem> items = section.collectItems();
+ result.addStructure(items);
+ } catch (ScannerException se) {
+ result.addError(section.processException(snapshot, se));
+ for (YamlSection part : section.splitOnException(se)) {
+ sources.push(part);
+ }
+ } catch (ParserException pe ){
+ result.addError(section.processException(snapshot, pe));
+ for (YamlSection part : section.splitOnException(pe)) {
+ sources.push(part);
+ }
+ } catch (Exception ex) {
+ String message = ex.getMessage();
+ if (message != null && message.length() > 0) {
+ result.addError(processError(message, snapshot, 0));
+ }
}
+ } else {
+ sources.clear();
}
}
return result;
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 4010e73..08f8b7e 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
@@ -41,7 +41,16 @@ public class YamlParserResult extends ParserResult {
}
public void addError(Error error) {
- errors.add(error);
+ boolean alreadyReported = false;
+ for (Error e : errors) {
+ if ((e.getStartPosition() <= error.getStartPosition()) && (e.getEndPosition() >= error.getStartPosition())) {
+ alreadyReported = true;
+ break;
+ }
+ }
+ if (!alreadyReported) {
+ errors.add(error);
+ }
}
public void addStructure(List<? extends StructureItem> items) {
diff --git a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
index 80befe2..8ad1ed8 100644
--- a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
+++ b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
@@ -180,17 +180,21 @@ public class YamlSection {
return item;
}
- DefaultError processScannerException(Snapshot snapshot, ScannerException se) {
- int contextIndex = getIndex(se.getContextMark());
+ DefaultError processException(Snapshot snapshot, ScannerException se) {
int problemIndex = getIndex(se.getProblemMark());
- StringBuilder message = new StringBuilder(se.getContext());
- message.append(", ").append(se.getProblem());
+ int contextIndex = problemIndex;
+ StringBuilder message = new StringBuilder();
+ if (se.getContext() != null) {
+ contextIndex = getIndex(se.getContextMark());
+ message.append(se.getContext()).append(", ");
+ }
+ message.append(se.getProblem());
char upper = Character.toUpperCase(message.charAt(0));
message.setCharAt(0, upper);
return new DefaultError(null, message.toString(), null, snapshot.getSource().getFileObject(), contextIndex, problemIndex, Severity.ERROR);
}
- DefaultError processParserException(Snapshot snapshot, ParserException se) {
+ DefaultError processException(Snapshot snapshot, ParserException se) {
int problemIndex = se.getProblemMark().isPresent() ? getIndex(se.getProblemMark()) : 0;
int contextIndex = problemIndex;
StringBuilder message = new StringBuilder();
@@ -204,13 +208,23 @@ public class YamlSection {
return new DefaultError(null, message.toString(), null, snapshot.getSource().getFileObject(), contextIndex, problemIndex, Severity.ERROR);
}
- List<YamlSection> splitOnParserException(ParserException pe) {
+ List<YamlSection> splitOnException(ScannerException se) {
+ int problemIndex = se.getProblemMark().get().getIndex();
+ if (se.getContextMark().isPresent()) {
+ int contextIndex = se.getContextMark().get().getIndex();
+ return split(contextIndex, problemIndex);
+ } else {
+ return split(problemIndex, problemIndex);
+ }
+ }
+
+ List<YamlSection> splitOnException(ParserException pe) {
if (pe.getContextMark().isPresent()) {
int contextIndex = pe.getContextMark().get().getIndex();
- return split(contextIndex, contextIndex + 1);
+ return split(contextIndex, contextIndex);
} else {
int problemIndex = pe.getProblemMark().get().getIndex();
- return split(problemIndex, problemIndex + 1);
+ return split(problemIndex, problemIndex);
}
}
@@ -224,12 +238,12 @@ public class YamlSection {
if (after.isEmpty()) {
before = before.trimTail();
}
- if (!before.isEmpty()) {
- ret.add(before);
- }
if (!after.isEmpty()) {
ret.add(after);
}
+ if (!before.isEmpty()) {
+ ret.add(before);
+ }
return ret;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[netbeans] 02/06: Replace JRuby YAML parser to SnakeYaml
Posted by lk...@apache.org.
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 <la...@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-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[netbeans] 03/06: Made the new parser work against the tests
Posted by lk...@apache.org.
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 cae021baef6c203a6951af77d2aa517fffd0e333
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Tue Oct 12 11:44:08 2021 -0700
Made the new parser work against the tests
---
.../modules/languages/yaml/YamlParser.java | 167 +++++++++--------
.../modules/languages/yaml/YamlParserResult.java | 34 +---
.../modules/languages/yaml/YamlScanner.java | 183 +++----------------
.../modules/languages/yaml/YamlSection.java | 187 +++++++++++++++++++
.../languages/yaml/YamlSemanticAnalyzer.java | 67 +++----
.../modules/languages/yaml/YamlStructureItem.java | 200 +++++++++++++++++++++
.../test/unit/data/testfiles/error.yaml.errors | 2 +-
.../test/unit/data/testfiles/error2.yaml.errors | 2 +-
.../test/unit/data/testfiles/error3.yaml.errors | 2 +-
.../unit/data/testfiles/fixture3.yml.structure | 2 -
.../test/unit/data/testfiles/test5.yaml.structure | 12 +-
.../modules/languages/yaml/YamlParserTest.java | 44 +++--
12 files changed, 553 insertions(+), 349 deletions(-)
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 86db263..01bef63 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,8 +18,8 @@
*/
package org.netbeans.modules.languages.yaml;
-import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Deque;
+import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -31,26 +31,23 @@ import org.netbeans.api.lexer.TokenHierarchy;
import org.netbeans.api.lexer.TokenId;
import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.modules.csl.api.Severity;
+import org.netbeans.modules.csl.api.StructureItem;
import org.netbeans.modules.csl.spi.DefaultError;
import org.netbeans.modules.parsing.api.Snapshot;
import org.netbeans.modules.parsing.api.Task;
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;
+import org.snakeyaml.engine.v2.exceptions.MarkedYamlEngineException;
+import org.snakeyaml.engine.v2.exceptions.ParserException;
+import org.snakeyaml.engine.v2.exceptions.ScannerException;
/**
* Parser for YAML. Delegates to the YAML parser shipped with JRuby (jvyamlb)
*
* @author Tor Norbye
*/
-public class YamlParser extends Parser {
+public class YamlParser extends org.netbeans.modules.parsing.spi.Parser {
private static final Logger LOGGER = Logger.getLogger(YamlParser.class.getName());
/**
@@ -93,7 +90,7 @@ public class YamlParser extends Parser {
}
private YamlParserResult resultForTooLargeFile(Snapshot snapshot) {
- YamlParserResult result = new YamlParserResult(Collections.<Node>emptyList(), this, snapshot, false);
+ YamlParserResult result = new YamlParserResult(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);
@@ -102,68 +99,56 @@ public class YamlParser extends Parser {
}
// package private for unit tests
- static String replacePhpFragments(String source) {
- // this is a hack. The right solution would be to create a toplevel language, which
- // will have embeded yaml and php.
- // This code replaces php fragments with space, because jruby parser fails
- // on this.
- int startReplace = source.indexOf("<?");
+ static void replaceWithSpaces(StringBuilder source, String startToken, String endToken) {
+ int startReplace = source.indexOf(startToken);
if (startReplace == -1) {
- return source;
+ return;
}
- StringBuilder result = new StringBuilder(source);
-
while (startReplace > -1) {
- int endReplace = result.indexOf("?>", startReplace);
- if (endReplace > -1) {
- endReplace = endReplace + 1;
- StringBuilder spaces = new StringBuilder(endReplace - startReplace);
- for (int i = 0; i <= endReplace - startReplace; i++) {
- spaces.append(' ');
+ int endReplace = source.indexOf(endToken, startReplace) + 1;
+ if (endReplace > startReplace) {
+ for (int i = startReplace; i <= endReplace; i++) {
+ source.setCharAt(i, ' ');
}
- result.replace(startReplace, endReplace + 1, spaces.toString());
- startReplace = result.indexOf("<?", endReplace);
+ startReplace = source.indexOf(startToken, endReplace);
} else {
startReplace = -1;
}
}
- return result.toString();
+ }
+
+ static void replacePhpFragments(StringBuilder source) {
+ // this is a hack. The right solution would be to create a toplevel language, which
+ // will have embeded yaml and php.
+ // This code replaces php fragments with space, because jruby parser fails
+ // on this.
+ replaceWithSpaces(source, "<?", "?>");
}
- static String replaceMustache(String source) {
+ static void replaceMustache(StringBuilder source) {
// this is a hack. The right solution would be to create a toplevel language, which
// will have embeded yaml and something.
// This code replaces mouthstache fragments with space.
- int startReplace = source.indexOf("{{");
- if (startReplace == -1) {
- return source;
- }
+ replaceWithSpaces(source, "{{", "}}");
+ }
- StringBuilder result = new StringBuilder(source);
+ final static Pattern[] SPEC_PATTERN_REPLACEMENTS = new Pattern[]{
+ Pattern.compile("@"),
+ Pattern.compile("\\?"),
+ Pattern.compile("!(?!(omap|!omap))"),};
- while (startReplace > -1) {
- int endReplace = result.indexOf("}}", startReplace);
- if (endReplace > -1) {
- endReplace = endReplace + 1;
- StringBuilder spaces = new StringBuilder(endReplace - startReplace);
- for (int i = 0; i <= endReplace - startReplace; i++) {
- spaces.append(' ');
+ private static void replaceCommonSpecialCharacters(StringBuilder source) {
+
+ for (int i = 0; i < SPEC_PATTERN_REPLACEMENTS.length; i++) {
+ Pattern pattern = SPEC_PATTERN_REPLACEMENTS[i];
+ Matcher m = pattern.matcher(source);
+ while (m.find()) {
+ for (int idx = m.start(); idx < m.end(); idx++) {
+ source.setCharAt(idx, '_');
}
- result.replace(startReplace, endReplace + 1, spaces.toString());
- startReplace = result.indexOf("{{", endReplace);
- } else {
- startReplace = -1;
}
}
- return result.toString();
- }
-
- private static String replaceCommonSpecialCharacters(String source) {
- source = source.replace('@', '_'); //NOI18N
- source = source.replace('?', '_'); //NOI18N
- source = source.replaceAll("!(?!(omap|!omap))", "_"); //NOI18N
- return source;
}
private static String replaceInlineRegexBrackets(String source) {
@@ -180,43 +165,55 @@ public class YamlParser extends Parser {
}
// for test package private
+ YamlParserResult parse(String src, Snapshot snapshot) {
- YamlParserResult parse(String source, Snapshot snapshot) {
+ if (isTooLarge(src)) {
+ return resultForTooLargeFile(snapshot);
+ }
- source = replacePhpFragments(source);
- source = replaceMustache(source);
- source = replaceCommonSpecialCharacters(source);
- source = replaceInlineRegexBrackets(source);
+ StringBuilder sb = new StringBuilder(src);
+ replacePhpFragments(sb);
+ replaceMustache(sb);
+ replaceCommonSpecialCharacters(sb);
+// source = replaceInlineRegexBrackets(source);
- List<Node> nodes = new ArrayList<Node>();
- try {
- if (isTooLarge(source)) {
- return resultForTooLargeFile(snapshot);
- }
- 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);
+ YamlParserResult result = new YamlParserResult(snapshot, false);
+
+ Deque<YamlSection> sources = new LinkedList<>();
+ sources.push(new YamlSection(sb.toString()));
+ while (!sources.isEmpty()) {
- while (composer.hasNext()) {
- Node node = composer.next();
- if (node == null) {
- break;
+ YamlSection section = sources.pop();
+ try {
+ List<? extends StructureItem> items = section.collectItems();
+ result.addStructure(items);
+ } catch (ScannerException se) {
+ result.addError(section.processScannerException(snapshot, se));
+ YamlSection after = section.after(se.getProblemMark().get().getIndex());
+ YamlSection before = section.before(se.getContextMark().get().getIndex());
+ if (!after.isEmpty()) sources.push(after);
+ if (!before.isEmpty()) sources.push(before);
+ if ((before.getLength() + after.getLength()) == section.getLength()) {
+ LOGGER.info("Chanche to loop forever");
+ }
+ } catch (ParserException pe ){
+ result.addError(section.processParserException(snapshot, pe));
+ YamlSection after = section.after(pe.getProblemMark().get().getIndex());
+ YamlSection before = section.before(pe.getProblemMark().get().getIndex());
+ if (!after.isEmpty()) sources.push(after);
+ if (!before.isEmpty()) sources.push(before);
+ if ((before.getLength() + after.getLength()) == section.getLength()) {
+ LOGGER.info("Chanche to loop forever");
+ }
+ } catch (Exception ex) {
+ String message = ex.getMessage();
+ if (message != null && message.length() > 0) {
+ result.addError(processError(message, snapshot, 0));
}
- nodes.add(node);
- }
- //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);
- String message = ex.getMessage();
- if (message != null && message.length() > 0) {
- result.addError(processError(message, snapshot, 0));
}
- return result;
}
- }
+ return result;
+ }
private DefaultError processError(String message, Snapshot snapshot, int pos) {
// Strip off useless prefixes to make errors more readable
@@ -294,7 +291,7 @@ public class YamlParser extends Parser {
lastResult = parse(source, snapshot);
} catch (Exception ioe) {
- lastResult = new YamlParserResult(Collections.<Node>emptyList(), this, snapshot, false);
+ lastResult = new YamlParserResult(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 e289ecb..14a383a 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
@@ -22,11 +22,9 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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
@@ -35,24 +33,21 @@ import org.snakeyaml.engine.v2.nodes.Node;
*/
public class YamlParserResult extends ParserResult {
- private final List<Error> errors = new ArrayList<Error>();
- private List<Node> nodes;
- private List<? extends StructureItem> items;
+ private final List<Error> errors = new ArrayList<>();
+ private final List<StructureItem> structure = new ArrayList<>();
- public YamlParserResult(List<Node> nodes, YamlParser parser, Snapshot snapshot, boolean valid) {
+ public YamlParserResult(Snapshot snapshot, boolean valid) {
super(snapshot);
- assert nodes != null;
- this.nodes = nodes;
- }
-
- public List<Node> getRootNodes() {
- return nodes;
}
public void addError(Error error) {
errors.add(error);
}
+ public void addStructure(List<? extends StructureItem> items) {
+ structure.addAll(items);
+ }
+
@Override
public List<? extends Error> getDiagnostics() {
return Collections.unmodifiableList(errors);
@@ -65,20 +60,7 @@ public class YamlParserResult extends ParserResult {
}
public synchronized List<? extends StructureItem> getItems() {
- if (items == null) {
- items = new YamlScanner().scanStructure(this);
- }
-
- return items;
- }
-
- public void setItems(List<? extends StructureItem> items) {
- this.items = items;
+ return structure;
}
- 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 495a4fc..8237d83 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
@@ -18,24 +18,15 @@
*/
package org.netbeans.modules.languages.yaml;
-import java.io.CharConversionException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.swing.ImageIcon;
import javax.swing.text.BadLocationException;
import org.netbeans.editor.BaseDocument;
import org.netbeans.editor.Utilities;
-import org.netbeans.modules.csl.api.ElementHandle;
-import org.netbeans.modules.csl.api.ElementKind;
-import org.netbeans.modules.csl.api.HtmlFormatter;
-import org.netbeans.modules.csl.api.Modifier;
import org.netbeans.modules.csl.api.OffsetRange;
import org.netbeans.modules.csl.api.StructureItem;
import org.netbeans.modules.csl.api.StructureScanner;
@@ -43,8 +34,6 @@ import org.netbeans.modules.csl.api.StructureScanner.Configuration;
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
@@ -58,54 +47,34 @@ public class YamlScanner implements StructureScanner {
@Override
public List<? extends StructureItem> scan(ParserResult info) {
YamlParserResult result = (YamlParserResult) info;
- if (result != null) {
- return result.getItems();
- }
-
- return Collections.emptyList();
- }
-
- List<? extends StructureItem> scanStructure(YamlParserResult result) {
- List<Node> nodes = result.getRootNodes();
- if (nodes.size() > 0) {
- // Skip root node
- return YamlStructureItem.initialize(result, nodes);
- }
-
- return Collections.emptyList();
+ return result.getItems();
}
@Override
public Map<String, List<OffsetRange>> folds(ParserResult info) {
- YamlParserResult result = (YamlParserResult) info;
- if (result == null) {
- return Collections.emptyMap();
- }
-
- List<? extends StructureItem> items = result.getItems();
- if (items.isEmpty()) {
- return Collections.emptyMap();
- }
-
- 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);
-
- for (StructureItem item : items) {
- try {
- addBlocks(result, doc, result.getSnapshot().getText(), codeblocks, item);
- } catch (BadLocationException ble) {
- Exceptions.printStackTrace(ble);
- break;
+ Map<String, List<OffsetRange>> folds = Collections.emptyMap();
+ List<? extends StructureItem> items = scan(info);
+
+ if (!items.isEmpty()) {
+ folds = new HashMap<>();
+ List<OffsetRange> codeblocks = new ArrayList<>();
+ folds.put("tags", codeblocks); // NOI18N
+
+ BaseDocument doc = (BaseDocument) info.getSnapshot().getSource().getDocument(false);
+
+ for (StructureItem item : items) {
+ try {
+ addBlocks(doc, info.getSnapshot().getText(), codeblocks, item);
+ } catch (BadLocationException ble) {
+ Exceptions.printStackTrace(ble);
+ break;
+ }
}
}
-
return folds;
}
- private void addBlocks(YamlParserResult result, BaseDocument doc, CharSequence text, List<OffsetRange> codeblocks, StructureItem item) throws BadLocationException {
+ private void addBlocks(BaseDocument doc, CharSequence text, List<OffsetRange> codeblocks, StructureItem item) throws BadLocationException {
int docLength = doc == null ? text.length() : doc.getLength();
int begin = Math.min((int) item.getPosition(), docLength);
int end = Math.min((int) item.getEndPosition(), docLength);
@@ -121,7 +90,7 @@ public class YamlScanner implements StructureScanner {
int childBegin = (int) child.getPosition();
int childEnd = (int) child.getEndPosition();
if (childBegin >= begin && childEnd <= end) {
- addBlocks(result, doc, text, codeblocks, child);
+ addBlocks(doc, text, codeblocks, child);
}
}
}
@@ -131,116 +100,4 @@ public class YamlScanner implements StructureScanner {
return new Configuration(false, false, 0);
}
- private static class YamlStructureItem implements StructureItem, Comparable<YamlStructureItem> {
-
- private final String name;
- private List<YamlStructureItem> children;
- private final Node node;
-
- YamlStructureItem(Node node, String name) {
- this.node = node;
- this.name = name;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public String getSortText() {
- return getName();
- }
-
- @Override
- public String getHtml(HtmlFormatter formatter) {
- String s = getName();
- try {
- return XMLUtil.toElementContent(s);
- } catch (CharConversionException cce) {
- // fine to just log...probably some UTF8 name (e.g. russian cyrillic, etc.)
- LOGGER.log(Level.FINE, "NAME:" + s, cce);
- return s;
- }
- }
-
- @Override
- public ElementHandle getElementHandle() {
- return null;
- }
-
- @Override
- public ElementKind getKind() {
- return ElementKind.ATTRIBUTE;
- }
-
- @Override
- public Set<Modifier> getModifiers() {
- return Collections.emptySet();
- }
-
- @Override
- public boolean isLeaf() {
- return getNestedItems().isEmpty();
- }
-
- 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...
- Set<Node> seen = new HashSet<>(100);
- List<StructureItem> children = new ArrayList<>();
- for (Node root : roots) {
- YamlStructureItem fakeRoot = new YamlStructureItem(root, null);
- initializeChildren(result, fakeRoot, seen, 0);
- children.addAll(fakeRoot.children);
- }
- return children;
- }
-
- @SuppressWarnings("unchecked")
- private static void initializeChildren(YamlParserResult result, YamlStructureItem item, Set<Node> seen, int depth) {
- Node node = item.node;
- if (seen.contains(node)) {
- return;
- }
- seen.add(node);
-
- switch (node.getNodeType()) {
- case MAPPING:
- break;
- case SEQUENCE:
- break;
- case SCALAR:
- break;
- }
- item.children = Collections.emptyList();
- }
-
- @Override
- public List<? extends StructureItem> getNestedItems() {
- assert children != null;
- return children;
- }
-
- @Override
- public long getPosition() {
- return node.getStartMark().get().getPointer();
- }
-
- @Override
- public long getEndPosition() {
- return node.getEndMark().get().getPointer();
- }
-
- @Override
- public ImageIcon getCustomIcon() {
- return null;
- }
-
- @Override
- public int compareTo(YamlStructureItem other) {
- return (int) (getPosition() - other.getPosition());
- }
-
- }
}
diff --git a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
new file mode 100644
index 0000000..0c73f44
--- /dev/null
+++ b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.languages.yaml;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import org.netbeans.modules.csl.api.Severity;
+import org.netbeans.modules.csl.api.StructureItem;
+import org.netbeans.modules.csl.spi.DefaultError;
+import org.netbeans.modules.parsing.api.Snapshot;
+import org.snakeyaml.engine.v2.api.LoadSettings;
+import org.snakeyaml.engine.v2.events.AliasEvent;
+import org.snakeyaml.engine.v2.events.Event;
+import org.snakeyaml.engine.v2.events.MappingEndEvent;
+import org.snakeyaml.engine.v2.events.MappingStartEvent;
+import org.snakeyaml.engine.v2.events.ScalarEvent;
+import org.snakeyaml.engine.v2.events.SequenceEndEvent;
+import org.snakeyaml.engine.v2.events.SequenceStartEvent;
+import org.snakeyaml.engine.v2.exceptions.Mark;
+import org.snakeyaml.engine.v2.exceptions.ParserException;
+import org.snakeyaml.engine.v2.exceptions.ScannerException;
+import org.snakeyaml.engine.v2.parser.Parser;
+import org.snakeyaml.engine.v2.parser.ParserImpl;
+import org.snakeyaml.engine.v2.scanner.ScannerImpl;
+import org.snakeyaml.engine.v2.scanner.StreamReader;
+
+import static org.netbeans.modules.languages.yaml.YamlStructureItem.NodeType.*;
+/**
+ *
+ * @author lkishalmi
+ */
+public class YamlSection {
+
+ private static final LoadSettings SETTINGS = LoadSettings.builder().build();
+ final int offset;
+ final String source;
+
+ private Parser parser = null;
+
+ YamlSection(int offset, String source) {
+ this.offset = offset;
+ this.source = source;
+ }
+
+ public YamlSection(String source) {
+ this(0, source);
+ }
+
+ public YamlSection before(int index) {
+ return new YamlSection(offset, source.substring(0, index));
+ }
+
+ public YamlSection after(int index) {
+ return new YamlSection(offset + index, source.substring(index));
+ }
+
+ public boolean isEmpty() {
+ return source.isEmpty();
+ }
+
+ public int getLength() {
+ return source.length();
+ }
+
+ List<? extends StructureItem> collectItems() {
+ if (parser != null) {
+ throw new IllegalStateException("This YAML segment is already parsed.");
+ }
+ List< StructureItem> ret = new ArrayList<>();
+ ScannerImpl scanner = new ScannerImpl(SETTINGS, new StreamReader(SETTINGS, source));
+ parser = new ParserImpl(SETTINGS, scanner);
+ while (parser.hasNext()) {
+ YamlStructureItem root = processItem();
+ if (root != null) {
+ ret.addAll(root.getNestedItems());
+ }
+ }
+ return ret;
+ }
+
+ private YamlStructureItem processItem() {
+ YamlStructureItem ret = null;
+ while ((ret == null) && parser.hasNext()) {
+ switch (parser.peekEvent().getEventId()) {
+ case MappingStart:
+ ret = processMapping((MappingStartEvent) parser.next());
+ break;
+ case SequenceStart:
+ ret = processSequence((SequenceStartEvent) parser.next());
+ break;
+ case Scalar:
+ ret = processScalar((ScalarEvent) parser.next());
+ break;
+ case Alias:
+ ret = processAlias((AliasEvent) parser.next());
+ break;
+ default:
+ parser.next();
+ }
+ }
+ return ret;
+ }
+
+ private YamlStructureItem processAlias(AliasEvent evt) {
+ return new YamlStructureItem.Simple(ALIAS, evt.getAlias().getValue(), getIndex(evt.getStartMark()), getIndex(evt.getEndMark()));
+ }
+
+ private YamlStructureItem processScalar(ScalarEvent evt) {
+ return new YamlStructureItem.Simple(SCALAR,evt.getValue(), getIndex(evt.getStartMark()), getIndex(evt.getEndMark()));
+ }
+
+
+ private YamlStructureItem processMapping(MappingStartEvent evt) {
+ YamlStructureItem.Collection item = new YamlStructureItem.Collection(MAP, getIndex(evt.getStartMark()));
+ while (parser.hasNext() && !parser.checkEvent(Event.ID.MappingEnd)) {
+ YamlStructureItem keyItem = processItem();
+ YamlStructureItem valueItem = processItem();
+ item.add(new YamlStructureItem.MapEntry(keyItem, valueItem));
+ }
+ if (parser.hasNext()) {
+ MappingEndEvent eevt = (MappingEndEvent) parser.next();
+ if (evt.isFlow()) {
+ item.setEndMark(getIndex(eevt.getEndMark()));
+ }
+ }
+ return item;
+ }
+
+ private YamlStructureItem processSequence(SequenceStartEvent evt) {
+ YamlStructureItem.Collection item = new YamlStructureItem.Collection(SEQUENCE, getIndex(evt.getStartMark()));
+ while (parser.hasNext() && !parser.checkEvent(Event.ID.SequenceEnd)) {
+ item.add(processItem());
+ }
+ if (parser.hasNext()) {
+ SequenceEndEvent eevt = (SequenceEndEvent) parser.next();
+ if (evt.isFlow()) {
+ item.setEndMark(getIndex(eevt.getEndMark()));
+ }
+ }
+ return item;
+ }
+
+ DefaultError processScannerException(Snapshot snapshot, ScannerException se) {
+ int contextIndex = getIndex(se.getContextMark());
+ int problemIndex = getIndex(se.getProblemMark());
+ StringBuilder message = new StringBuilder(se.getContext());
+ message.append(", ").append(se.getProblem());
+ char upper = Character.toUpperCase(message.charAt(0));
+ message.setCharAt(0, upper);
+ return new DefaultError(null, message.toString(), null, snapshot.getSource().getFileObject(), contextIndex, problemIndex, Severity.ERROR);
+ }
+
+ DefaultError processParserException(Snapshot snapshot, ParserException se) {
+ int problemIndex = getIndex(se.getProblemMark());
+ StringBuilder message = new StringBuilder(se.getContext());
+ message.append(", ").append(se.getProblem());
+ char upper = Character.toUpperCase(message.charAt(0));
+ message.setCharAt(0, upper);
+ return new DefaultError(null, message.toString(), null, snapshot.getSource().getFileObject(), problemIndex, problemIndex, Severity.ERROR);
+ }
+
+ private int getIndex(Optional<Mark> om) {
+ return om.get().getIndex() + offset;
+ }
+
+ @Override
+ public String toString() {
+ return "" + offset + ":" + source;
+ }
+}
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 35db1e9..69af95c 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
@@ -20,23 +20,15 @@ package org.netbeans.modules.languages.yaml;
import java.util.Collections;
import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.List;
import java.util.Map;
import java.util.Set;
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.csl.api.StructureItem;
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
@@ -85,54 +77,47 @@ public class YamlSemanticAnalyzer extends SemanticAnalyzer {
}
YamlParserResult ypr = (YamlParserResult) result;
- if (ypr == null || ypr.getRootNodes().isEmpty()) {
+ if (ypr == null || ypr.getItems().isEmpty()) {
this.semanticHighlights = Collections.emptyMap();
return;
}
- List<Node> rootNodes = ypr.getRootNodes();
-
Map<OffsetRange, Set<ColoringAttributes>> highlights =
new HashMap<OffsetRange, Set<ColoringAttributes>>(100);
- IdentityHashMap<Object, Boolean> seen = new IdentityHashMap<Object, Boolean>(100);
- for (Node root : rootNodes) {
- addHighlights(ypr, root, highlights, seen, 0);
+ for (StructureItem item : ypr.getItems()) {
+ YamlStructureItem yamlItem = (YamlStructureItem) item;
+ addHighlights(yamlItem, highlights);
}
this.semanticHighlights = highlights;
}
- private void addHighlights(YamlParserResult ypr, Node node, Map<OffsetRange, Set<ColoringAttributes>> highlights, IdentityHashMap<Object, Boolean> seen, int depth) {
- if (depth > 10 || node == null) {
- // Avoid boundless recursion; some datastructures from YAML appear to be recursive
- return;
- }
- if (seen.containsKey(node)) {
- return;
- }
- 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);
- }
- break;
+ private void addHighlights(YamlStructureItem item, Map<OffsetRange, Set<ColoringAttributes>> highlights) {
+ switch (item.getType()) {
+ case MAP:
case SEQUENCE:
- SequenceNode sequence = (SequenceNode) node;
- List<Node> nodes = sequence.getValue();
- for (Node node1 : nodes) {
- addHighlights(ypr, node, highlights, seen, depth + 1);
+ YamlStructureItem.Collection coll = (YamlStructureItem.Collection) item;
+ for (YamlStructureItem child : coll.getChildren()) {
+ addHighlights(child, highlights);
}
break;
- case SCALAR:
- ScalarNode scalar = (ScalarNode) node;
- OffsetRange range = YamlParserResult.getAstRange(scalar);
- highlights.put(range, ColoringAttributes.METHOD_SET);
+ case MAPPING:
+ YamlStructureItem.MapEntry entry = (YamlStructureItem.MapEntry) item;
+ if (entry.keyItem.getType() == YamlStructureItem.NodeType.SCALAR) {
+ highlights.put(getAstRange(entry.keyItem), ColoringAttributes.METHOD_SET);
+ } else {
+ addHighlights(entry.keyItem, highlights);
+ }
+ addHighlights(entry.valueItem, highlights);
break;
}
}
+
+ private static OffsetRange getAstRange(YamlStructureItem item) {
+ int s = (int) item.getPosition();
+ int e = (int) item.getEndPosition();
+ return new OffsetRange(s, e);
+ }
+
}
diff --git a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlStructureItem.java b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlStructureItem.java
new file mode 100644
index 0000000..4412d43
--- /dev/null
+++ b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlStructureItem.java
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.languages.yaml;
+
+import java.io.CharConversionException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.ImageIcon;
+import org.netbeans.modules.csl.api.ElementHandle;
+import org.netbeans.modules.csl.api.ElementKind;
+import org.netbeans.modules.csl.api.HtmlFormatter;
+import org.netbeans.modules.csl.api.Modifier;
+import org.netbeans.modules.csl.api.StructureItem;
+import org.openide.xml.XMLUtil;
+
+/**
+ *
+ * @author lkishalmi
+ */
+public abstract class YamlStructureItem implements StructureItem {
+
+ public static enum NodeType { MAP, SEQUENCE, MAPPING, SCALAR, ALIAS };
+
+ private static final Logger LOGGER = Logger.getLogger(YamlStructureItem.class.getName());
+ private final NodeType type;
+ private final long startMark;
+
+ public YamlStructureItem(NodeType type, long startMark) {
+ this.type = type;
+ this.startMark = startMark;
+ }
+
+ public NodeType getType() {
+ return type;
+ }
+
+ @Override
+ public String getSortText() {
+ return getName();
+ }
+
+ @Override
+ public String getHtml(HtmlFormatter formatter) {
+ try {
+ return XMLUtil.toElementContent(getName());
+ } catch (CharConversionException cce) {
+ // fine to just log...probably some UTF8 name (e.g. russian cyrillic, etc.)
+ LOGGER.log(Level.FINE, "NAME:" + getName(), cce);
+ return getName();
+ }
+ }
+
+ @Override
+ public ElementHandle getElementHandle() {
+ return null;
+ }
+
+ @Override
+ public ElementKind getKind() {
+ return ElementKind.ATTRIBUTE;
+ }
+
+ @Override
+ public Set<Modifier> getModifiers() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public boolean isLeaf() {
+ return getNestedItems().isEmpty();
+ }
+
+ @Override
+ public long getPosition() {
+ return startMark;
+ }
+
+ @Override
+ public ImageIcon getCustomIcon() {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return "" + getPosition() + ": " + getName();
+ }
+
+ public final static class Simple extends YamlStructureItem {
+
+ final String name;
+ final long endMark;
+
+ public Simple(NodeType type, String name, long startMark, long endMark) {
+ super(type, startMark);
+ this.name = name;
+ this.endMark = endMark;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public List<? extends StructureItem> getNestedItems() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public long getEndPosition() {
+ return endMark;
+ }
+
+ }
+
+ public final static class Collection extends YamlStructureItem {
+ private final List<YamlStructureItem> children = new ArrayList<>();
+ private long endMark;
+
+ public Collection(NodeType type, long startMark) {
+ super(type, startMark);
+ this.endMark = startMark;
+ }
+
+ @Override
+ public String getName() {
+ return "list item";
+ }
+
+ @Override
+ public List<? extends StructureItem> getNestedItems() {
+ return children;
+ }
+
+ public List<? extends YamlStructureItem> getChildren() {
+ return children;
+ }
+
+ @Override
+ public long getEndPosition() {
+ return endMark;
+ }
+
+ public void add(YamlStructureItem item) {
+ endMark = item.getEndPosition();
+ children.add(item);
+ }
+
+ public void setEndMark(int end) {
+ endMark = end;
+ }
+ }
+
+ public final static class MapEntry extends YamlStructureItem {
+ final YamlStructureItem keyItem;
+ final YamlStructureItem valueItem;
+
+ public MapEntry(YamlStructureItem keyItem, YamlStructureItem valueItem) {
+ super(NodeType.MAPPING, keyItem.startMark);
+ this.keyItem = keyItem;
+ this.valueItem = valueItem;
+ }
+
+ @Override
+ public String getName() {
+ return keyItem.getName();
+ }
+
+ @Override
+ public List<? extends StructureItem> getNestedItems() {
+ return valueItem.getNestedItems();
+ }
+
+ @Override
+ public long getEndPosition() {
+ return valueItem.getEndPosition();
+ }
+ }
+
+}
diff --git a/ide/languages.yaml/test/unit/data/testfiles/error.yaml.errors b/ide/languages.yaml/test/unit/data/testfiles/error.yaml.errors
index 56a5dde..f1d0ebf 100644
--- a/ide/languages.yaml/test/unit/data/testfiles/error.yaml.errors
+++ b/ide/languages.yaml/test/unit/data/testfiles/error.yaml.errors
@@ -1 +1 @@
-152-152:While scanning a block mapping we had this expected <block end>, but found org.jvyamlb.tokens.PositionedScalarToken
+152-159:While scanning a simple key, could not find expected ':'
diff --git a/ide/languages.yaml/test/unit/data/testfiles/error2.yaml.errors b/ide/languages.yaml/test/unit/data/testfiles/error2.yaml.errors
index 5603088..ca350bc 100644
--- a/ide/languages.yaml/test/unit/data/testfiles/error2.yaml.errors
+++ b/ide/languages.yaml/test/unit/data/testfiles/error2.yaml.errors
@@ -1 +1 @@
-272-272:While scanning a block mapping we had this expected <block end>, but found org.jvyamlb.tokens.PositionedScalarToken
+272-279:While scanning a simple key, could not find expected ':'
diff --git a/ide/languages.yaml/test/unit/data/testfiles/error3.yaml.errors b/ide/languages.yaml/test/unit/data/testfiles/error3.yaml.errors
index 38da867..ebfa576 100644
--- a/ide/languages.yaml/test/unit/data/testfiles/error3.yaml.errors
+++ b/ide/languages.yaml/test/unit/data/testfiles/error3.yaml.errors
@@ -1 +1 @@
-31-31:While scanning a block mapping we had this expected <block end>, but found org.jvyamlb.tokens.PositionedBlockMappingStartToken
+31-31:While parsing a block mapping, expected <block end>, but found '<block mapping start>'
diff --git a/ide/languages.yaml/test/unit/data/testfiles/fixture3.yml.structure b/ide/languages.yaml/test/unit/data/testfiles/fixture3.yml.structure
index 0b359ee..c3cfeb5 100644
--- a/ide/languages.yaml/test/unit/data/testfiles/fixture3.yml.structure
+++ b/ide/languages.yaml/test/unit/data/testfiles/fixture3.yml.structure
@@ -2,9 +2,7 @@ DEFAULTS:ATTRIBUTE:[]:DEFAULTS:
created_on:ATTRIBUTE:[]:created_on:
first:ATTRIBUTE:[]:first:
<<:ATTRIBUTE:[]:<<:
- created_on:ATTRIBUTE:[]:created_on:
name:ATTRIBUTE:[]:name:
second:ATTRIBUTE:[]:second:
<<:ATTRIBUTE:[]:<<:
- created_on:ATTRIBUTE:[]:created_on:
name:ATTRIBUTE:[]:name:
diff --git a/ide/languages.yaml/test/unit/data/testfiles/test5.yaml.structure b/ide/languages.yaml/test/unit/data/testfiles/test5.yaml.structure
index cfd7817..5a30443 100644
--- a/ide/languages.yaml/test/unit/data/testfiles/test5.yaml.structure
+++ b/ide/languages.yaml/test/unit/data/testfiles/test5.yaml.structure
@@ -11,17 +11,9 @@ children:ATTRIBUTE:[]:children:
age:ATTRIBUTE:[]:age:
name:ATTRIBUTE:[]:name:
siblings:ATTRIBUTE:[]:siblings:
- list item:ATTRIBUTE:[]:list item:
- age:ATTRIBUTE:[]:age:
- children:ATTRIBUTE:[]:children:
- name:ATTRIBUTE:[]:name:
- siblings:ATTRIBUTE:[]:siblings:
- spouse:ATTRIBUTE:[]:spouse:
+ 1:ATTRIBUTE:[]:1:
list item:ATTRIBUTE:[]:list item:
age:ATTRIBUTE:[]:age:
name:ATTRIBUTE:[]:name:
siblings:ATTRIBUTE:[]:siblings:
- list item:ATTRIBUTE:[]:list item:
- age:ATTRIBUTE:[]:age:
- name:ATTRIBUTE:[]:name:
- siblings:ATTRIBUTE:[]:siblings:
+ 2:ATTRIBUTE:[]:2:
\ No newline at end of file
diff --git a/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlParserTest.java b/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlParserTest.java
index e4d8663..e17982d 100644
--- a/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlParserTest.java
+++ b/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlParserTest.java
@@ -87,7 +87,7 @@ public class YamlParserTest extends YamlTestBase {
String annotatedSource = annotateErrors(diagnostics);
assertDescriptionMatches("testfiles/" + relFilePath, annotatedSource, false, ".errors", false);
// Make sure we actually skipped parsing this large document!
- assertTrue(result.getRootNodes().size() == 0);
+ assertTrue(result.getItems().isEmpty());
}
});
}
@@ -110,21 +110,27 @@ public class YamlParserTest extends YamlTestBase {
assertNotNull("Parser result must be nonnull", parser.getResult(null));
}
+ private String replacePhpFragments(String source) {
+ StringBuilder sb = new StringBuilder(source);
+ YamlParser.replacePhpFragments(sb);
+ return sb.toString();
+ }
+
public void testReplacePhpFragments() {
- assertEquals("", YamlParser.replacePhpFragments(""));
- assertEquals("foo bar", YamlParser.replacePhpFragments("foo bar"));
- assertEquals("?>", YamlParser.replacePhpFragments("?>"));
- assertEquals("<?", YamlParser.replacePhpFragments("<?"));
- assertEquals("foo ?>", YamlParser.replacePhpFragments("foo ?>"));
- assertEquals("<? bar", YamlParser.replacePhpFragments("<? bar"));
-
- assertEquals(" ", YamlParser.replacePhpFragments("<??>"));
- assertEquals("foo: ", YamlParser.replacePhpFragments("foo:<??>"));
- assertEquals("foo: ", YamlParser.replacePhpFragments("foo:<? here goes php ?>"));
- assertEquals("foo baz", YamlParser.replacePhpFragments("foo <? bar ?> baz"));
-
- assertEquals(" ", YamlParser.replacePhpFragments("<??><??>"));
- assertEquals("foo: bar: qux", YamlParser.replacePhpFragments("foo:<??>bar:<?baz?>qux"));
+ assertEquals("", replacePhpFragments(""));
+ assertEquals("foo bar", replacePhpFragments("foo bar"));
+ assertEquals("?>", replacePhpFragments("?>"));
+ assertEquals("<?", replacePhpFragments("<?"));
+ assertEquals("foo ?>", replacePhpFragments("foo ?>"));
+ assertEquals("<? bar", replacePhpFragments("<? bar"));
+
+ assertEquals(" ", replacePhpFragments("<??>"));
+ assertEquals("foo: ", replacePhpFragments("foo:<??>"));
+ assertEquals("foo: ", replacePhpFragments("foo:<? here goes php ?>"));
+ assertEquals("foo baz", replacePhpFragments("foo <? bar ?> baz"));
+
+ assertEquals(" ", replacePhpFragments("<??><??>"));
+ assertEquals("foo: bar: qux", replacePhpFragments("foo:<??>bar:<?baz?>qux"));
}
public void testReplacePhpFragmentsPerformance() {
@@ -136,11 +142,11 @@ public class YamlParserTest extends YamlTestBase {
source.append("<? php here ?>");
}
}
- long start = System.currentTimeMillis();
- YamlParser.replacePhpFragments(source.toString());
- long time = System.currentTimeMillis() - start;
+ long start = System.nanoTime();
+ YamlParser.replacePhpFragments(source);
+ long time = System.nanoTime() - start;
// takes about 30 ms on my laptop, so I suppose 300 ms should
// be enough pretty much on any machine
- assertTrue("Slow replacing of php fragments: " + time + " ms", time < 300);
+ assertTrue("Slow replacing of php fragments: " + time + " ms", time < 300_000_000L);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[netbeans] 04/06: Working YAML Parser without auto-recovery.
Posted by lk...@apache.org.
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 c3e2a0293142578085cc5b8853b75945063efe74
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Tue Oct 12 18:10:41 2021 -0700
Working YAML Parser without auto-recovery.
---
.../modules/languages/yaml/YamlParser.java | 26 +++----
.../modules/languages/yaml/YamlParserResult.java | 2 +-
.../modules/languages/yaml/YamlSection.java | 81 ++++++++++++++++++----
.../test/unit/data/testfiles/error3.yaml.errors | 2 +-
.../test/unit/data/testfiles/error4.yaml | 7 ++
.../test/unit/data/testfiles/error4.yaml.errors | 1 +
.../modules/languages/yaml/YamlParserTest.java | 4 ++
7 files changed, 91 insertions(+), 32 deletions(-)
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 01bef63..ff230f4 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
@@ -38,7 +38,6 @@ import org.netbeans.modules.parsing.api.Task;
import org.netbeans.modules.parsing.spi.ParseException;
import org.netbeans.modules.parsing.spi.SourceModificationEvent;
import org.openide.util.NbBundle;
-import org.snakeyaml.engine.v2.exceptions.MarkedYamlEngineException;
import org.snakeyaml.engine.v2.exceptions.ParserException;
import org.snakeyaml.engine.v2.exceptions.ScannerException;
@@ -90,7 +89,7 @@ public class YamlParser extends org.netbeans.modules.parsing.spi.Parser {
}
private YamlParserResult resultForTooLargeFile(Snapshot snapshot) {
- YamlParserResult result = new YamlParserResult(snapshot, false);
+ YamlParserResult result = new YamlParserResult(snapshot);
// 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);
@@ -177,7 +176,7 @@ public class YamlParser extends org.netbeans.modules.parsing.spi.Parser {
replaceCommonSpecialCharacters(sb);
// source = replaceInlineRegexBrackets(source);
- YamlParserResult result = new YamlParserResult(snapshot, false);
+ YamlParserResult result = new YamlParserResult(snapshot);
Deque<YamlSection> sources = new LinkedList<>();
sources.push(new YamlSection(sb.toString()));
@@ -189,22 +188,13 @@ public class YamlParser extends org.netbeans.modules.parsing.spi.Parser {
result.addStructure(items);
} catch (ScannerException se) {
result.addError(section.processScannerException(snapshot, se));
- YamlSection after = section.after(se.getProblemMark().get().getIndex());
- YamlSection before = section.before(se.getContextMark().get().getIndex());
- if (!after.isEmpty()) sources.push(after);
- if (!before.isEmpty()) sources.push(before);
- if ((before.getLength() + after.getLength()) == section.getLength()) {
- LOGGER.info("Chanche to loop forever");
- }
+// YamlSection after = section.after(se.getProblemMark().get().getIndex());
+// YamlSection before = section.before(se.getContextMark().get().getIndex());
+// if (!after.isEmpty()) sources.push(after);
+// if (!before.isEmpty()) sources.push(before);
} catch (ParserException pe ){
result.addError(section.processParserException(snapshot, pe));
- YamlSection after = section.after(pe.getProblemMark().get().getIndex());
- YamlSection before = section.before(pe.getProblemMark().get().getIndex());
- if (!after.isEmpty()) sources.push(after);
- if (!before.isEmpty()) sources.push(before);
- if ((before.getLength() + after.getLength()) == section.getLength()) {
- LOGGER.info("Chanche to loop forever");
- }
+// sources.addAll(section.splitOnParserException(pe));
} catch (Exception ex) {
String message = ex.getMessage();
if (message != null && message.length() > 0) {
@@ -291,7 +281,7 @@ public class YamlParser extends org.netbeans.modules.parsing.spi.Parser {
lastResult = parse(source, snapshot);
} catch (Exception ioe) {
- lastResult = new YamlParserResult(snapshot, false);
+ lastResult = new YamlParserResult(snapshot);
}
}
}
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 14a383a..4010e73 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
@@ -36,7 +36,7 @@ public class YamlParserResult extends ParserResult {
private final List<Error> errors = new ArrayList<>();
private final List<StructureItem> structure = new ArrayList<>();
- public YamlParserResult(Snapshot snapshot, boolean valid) {
+ public YamlParserResult(Snapshot snapshot) {
super(snapshot);
}
diff --git a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
index 0c73f44..80befe2 100644
--- a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
+++ b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
@@ -19,6 +19,7 @@
package org.netbeans.modules.languages.yaml;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import org.netbeans.modules.csl.api.Severity;
@@ -42,6 +43,7 @@ import org.snakeyaml.engine.v2.scanner.ScannerImpl;
import org.snakeyaml.engine.v2.scanner.StreamReader;
import static org.netbeans.modules.languages.yaml.YamlStructureItem.NodeType.*;
+
/**
*
* @author lkishalmi
@@ -53,7 +55,7 @@ public class YamlSection {
final String source;
private Parser parser = null;
-
+
YamlSection(int offset, String source) {
this.offset = offset;
this.source = source;
@@ -71,14 +73,36 @@ public class YamlSection {
return new YamlSection(offset + index, source.substring(index));
}
+ public YamlSection trimTail() {
+ int index = source.length() - 1;
+ while ((index > 0) && Character.isWhitespace(source.charAt(index))) {
+ index--;
+ }
+ while ((index > 0) && !Character.isWhitespace(source.charAt(index))) {
+ index--;
+ }
+ return before(index);
+ }
+
+ public YamlSection trimHead() {
+ int index = 0;
+ while ((index < source.length()) && Character.isWhitespace(source.charAt(index))) {
+ index++;
+ }
+ while ((index < source.length()) && !Character.isWhitespace(source.charAt(index))) {
+ index++;
+ }
+ return after(index);
+ }
+
public boolean isEmpty() {
return source.isEmpty();
}
-
- public int getLength() {
+
+ public int length() {
return source.length();
}
-
+
List<? extends StructureItem> collectItems() {
if (parser != null) {
throw new IllegalStateException("This YAML segment is already parsed.");
@@ -87,7 +111,7 @@ public class YamlSection {
ScannerImpl scanner = new ScannerImpl(SETTINGS, new StreamReader(SETTINGS, source));
parser = new ParserImpl(SETTINGS, scanner);
while (parser.hasNext()) {
- YamlStructureItem root = processItem();
+ YamlStructureItem root = processItem();
if (root != null) {
ret.addAll(root.getNestedItems());
}
@@ -123,10 +147,9 @@ public class YamlSection {
}
private YamlStructureItem processScalar(ScalarEvent evt) {
- return new YamlStructureItem.Simple(SCALAR,evt.getValue(), getIndex(evt.getStartMark()), getIndex(evt.getEndMark()));
+ return new YamlStructureItem.Simple(SCALAR, evt.getValue(), getIndex(evt.getStartMark()), getIndex(evt.getEndMark()));
}
-
private YamlStructureItem processMapping(MappingStartEvent evt) {
YamlStructureItem.Collection item = new YamlStructureItem.Collection(MAP, getIndex(evt.getStartMark()));
while (parser.hasNext() && !parser.checkEvent(Event.ID.MappingEnd)) {
@@ -168,18 +191,52 @@ public class YamlSection {
}
DefaultError processParserException(Snapshot snapshot, ParserException se) {
- int problemIndex = getIndex(se.getProblemMark());
- StringBuilder message = new StringBuilder(se.getContext());
- message.append(", ").append(se.getProblem());
+ int problemIndex = se.getProblemMark().isPresent() ? getIndex(se.getProblemMark()) : 0;
+ int contextIndex = problemIndex;
+ StringBuilder message = new StringBuilder();
+ if (se.getContext() != null) {
+ contextIndex = getIndex(se.getContextMark());
+ message.append(se.getContext()).append(", ");
+ }
+ message.append(se.getProblem());
char upper = Character.toUpperCase(message.charAt(0));
message.setCharAt(0, upper);
- return new DefaultError(null, message.toString(), null, snapshot.getSource().getFileObject(), problemIndex, problemIndex, Severity.ERROR);
+ return new DefaultError(null, message.toString(), null, snapshot.getSource().getFileObject(), contextIndex, problemIndex, Severity.ERROR);
+ }
+
+ List<YamlSection> splitOnParserException(ParserException pe) {
+ if (pe.getContextMark().isPresent()) {
+ int contextIndex = pe.getContextMark().get().getIndex();
+ return split(contextIndex, contextIndex + 1);
+ } else {
+ int problemIndex = pe.getProblemMark().get().getIndex();
+ return split(problemIndex, problemIndex + 1);
+ }
+ }
+
+ List<YamlSection> split(int a, int b) {
+ List<YamlSection> ret = new LinkedList<>();
+ YamlSection before = before(a);
+ YamlSection after = after(b);
+ if (before.isEmpty()) {
+ after = after.trimHead();
+ }
+ if (after.isEmpty()) {
+ before = before.trimTail();
+ }
+ if (!before.isEmpty()) {
+ ret.add(before);
+ }
+ if (!after.isEmpty()) {
+ ret.add(after);
+ }
+ return ret;
}
private int getIndex(Optional<Mark> om) {
return om.get().getIndex() + offset;
}
-
+
@Override
public String toString() {
return "" + offset + ":" + source;
diff --git a/ide/languages.yaml/test/unit/data/testfiles/error3.yaml.errors b/ide/languages.yaml/test/unit/data/testfiles/error3.yaml.errors
index ebfa576..6fd938b 100644
--- a/ide/languages.yaml/test/unit/data/testfiles/error3.yaml.errors
+++ b/ide/languages.yaml/test/unit/data/testfiles/error3.yaml.errors
@@ -1 +1 @@
-31-31:While parsing a block mapping, expected <block end>, but found '<block mapping start>'
+0-31:While parsing a block mapping, expected <block end>, but found '<block mapping start>'
diff --git a/ide/languages.yaml/test/unit/data/testfiles/error4.yaml b/ide/languages.yaml/test/unit/data/testfiles/error4.yaml
new file mode 100644
index 0000000..6b54141
--- /dev/null
+++ b/ide/languages.yaml/test/unit/data/testfiles/error4.yaml
@@ -0,0 +1,7 @@
+name: John Smith
+age: 47
+spouse:
+ name: {
+ age: 35
+children:
+
diff --git a/ide/languages.yaml/test/unit/data/testfiles/error4.yaml.errors b/ide/languages.yaml/test/unit/data/testfiles/error4.yaml.errors
new file mode 100644
index 0000000..fc439a7
--- /dev/null
+++ b/ide/languages.yaml/test/unit/data/testfiles/error4.yaml.errors
@@ -0,0 +1 @@
+43-65:While parsing a flow mapping, expected ',' or '}', but got :
diff --git a/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlParserTest.java b/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlParserTest.java
index e17982d..3d8a440 100644
--- a/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlParserTest.java
+++ b/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlParserTest.java
@@ -50,6 +50,10 @@ public class YamlParserTest extends YamlTestBase {
checkErrors("testfiles/error3.yaml");
}
+ public void testErrors4() throws Exception {
+ checkErrors("testfiles/error4.yaml");
+ }
+
public void testIssue232192_01() throws Exception {
checkErrors("testfiles/issue232192_01.yaml");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[netbeans] 06/06: Added unittest for YamlSection.
Posted by lk...@apache.org.
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 3b2b6c82ebec310198ea4fa5f4f1defcf5732099
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Sat Oct 16 11:13:06 2021 -0700
Added unittest for YamlSection.
---
.../modules/languages/yaml/YamlSection.java | 57 ++++-
.../modules/languages/yaml/YamlSectionTest.java | 259 +++++++++++++++++++++
2 files changed, 308 insertions(+), 8 deletions(-)
diff --git a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
index 8ad1ed8..131e7af 100644
--- a/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
+++ b/ide/languages.yaml/src/org/netbeans/modules/languages/yaml/YamlSection.java
@@ -21,6 +21,7 @@ package org.netbeans.modules.languages.yaml;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
import org.netbeans.modules.csl.api.Severity;
import org.netbeans.modules.csl.api.StructureItem;
@@ -78,10 +79,10 @@ public class YamlSection {
while ((index > 0) && Character.isWhitespace(source.charAt(index))) {
index--;
}
- while ((index > 0) && !Character.isWhitespace(source.charAt(index))) {
+ while ((index > -1) && !Character.isWhitespace(source.charAt(index))) {
index--;
}
- return before(index);
+ return before(index + 1);
}
public YamlSection trimHead() {
@@ -228,16 +229,26 @@ public class YamlSection {
}
}
+ List<YamlSection> split(int a) {
+ List<YamlSection> ret = new LinkedList<>();
+ YamlSection before = a < source.length() ? before(a) : trimTail();
+ YamlSection after = a > 0 ? after(a) : trimHead();
+ if (!after.isEmpty()) {
+ ret.add(after);
+ }
+ if (!before.isEmpty()) {
+ ret.add(before);
+ }
+ return ret;
+ }
+
List<YamlSection> split(int a, int b) {
+ if (a == b){
+ return split(a);
+ }
List<YamlSection> ret = new LinkedList<>();
YamlSection before = before(a);
YamlSection after = after(b);
- if (before.isEmpty()) {
- after = after.trimHead();
- }
- if (after.isEmpty()) {
- before = before.trimTail();
- }
if (!after.isEmpty()) {
ret.add(after);
}
@@ -252,6 +263,36 @@ public class YamlSection {
}
@Override
+ public int hashCode() {
+ int hash = 7;
+ hash = 79 * hash + this.offset;
+ hash = 79 * hash + Objects.hashCode(this.source);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final YamlSection other = (YamlSection) obj;
+ if (this.offset != other.offset) {
+ return false;
+ }
+ if (!Objects.equals(this.source, other.source)) {
+ return false;
+ }
+ return true;
+ }
+
+
+ @Override
public String toString() {
return "" + offset + ":" + source;
}
diff --git a/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlSectionTest.java b/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlSectionTest.java
new file mode 100644
index 0000000..3940b0e
--- /dev/null
+++ b/ide/languages.yaml/test/unit/src/org/netbeans/modules/languages/yaml/YamlSectionTest.java
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.languages.yaml;
+
+import java.util.Iterator;
+import java.util.List;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.netbeans.modules.csl.api.StructureItem;
+import org.netbeans.modules.csl.spi.DefaultError;
+import org.netbeans.modules.parsing.api.Snapshot;
+import org.snakeyaml.engine.v2.exceptions.ParserException;
+import org.snakeyaml.engine.v2.exceptions.ScannerException;
+
+/**
+ *
+ * @author lkishalmi
+ */
+public class YamlSectionTest {
+
+ public YamlSectionTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of before method, of class YamlSection.
+ */
+ @Test
+ public void testBefore() {
+ YamlSection instance = new YamlSection("name: John Smith");
+ YamlSection expResult = new YamlSection("name");
+ YamlSection result = instance.before(4);
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testBeforeEmpty1() {
+ YamlSection instance = new YamlSection("name: John Smith");
+ YamlSection result = instance.before(0);
+ assertTrue(result.isEmpty());
+ }
+
+ @Test
+ public void testBeforeEmpty2() {
+ YamlSection instance = new YamlSection("");
+ YamlSection result = instance.before(0);
+ assertTrue(instance.isEmpty());
+ assertTrue(result.isEmpty());
+ }
+
+ /**
+ * Test of after method, of class YamlSection.
+ */
+ @Test
+ public void testAfter() {
+ YamlSection instance = new YamlSection("name: John Smith");
+ YamlSection expResult = new YamlSection(4, ": John Smith");
+ YamlSection result = instance.after(4);
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testAfterEmpty1() {
+ YamlSection instance = new YamlSection("name: John Smith");
+ YamlSection result = instance.after(16);
+ assertEquals(16, result.offset);
+ assertTrue(result.isEmpty());
+ }
+
+ @Test
+ public void testAfterEmpty2() {
+ YamlSection instance = new YamlSection("");
+ YamlSection result = instance.after(0);
+ assertTrue(instance.isEmpty());
+ assertTrue(result.isEmpty());
+ }
+
+ @Test
+ public void testTrimTail() {
+ YamlSection instance = new YamlSection("name: { \t\n");
+ YamlSection expResult = new YamlSection("name: ");
+ YamlSection result = instance.trimTail();
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testTrimTailEmpty1() {
+ YamlSection instance = new YamlSection("name: ");
+ YamlSection expResult = new YamlSection("");
+ YamlSection result = instance.trimTail();
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testTrimTailEmpty2() {
+ YamlSection instance = new YamlSection(42, "");
+ YamlSection expResult = new YamlSection(42, "");
+ YamlSection result = instance.trimTail();
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testTrimHead() {
+ YamlSection instance = new YamlSection("name: { \t\n");
+ YamlSection expResult = new YamlSection(5, " { \t\n");
+ YamlSection result = instance.trimHead();
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testTrimHeadEmpty3() {
+ YamlSection instance = new YamlSection("name:");
+ YamlSection expResult = new YamlSection(5, "");
+ YamlSection result = instance.trimHead();
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testTrimHeadEmpty1() {
+ YamlSection instance = new YamlSection(" {");
+ YamlSection expResult = new YamlSection(2, "");
+ YamlSection result = instance.trimHead();
+ assertEquals(expResult, result);
+ }
+
+ @Test
+ public void testTrimHeadEmpty2() {
+ YamlSection instance = new YamlSection(42, "");
+ YamlSection expResult = new YamlSection(42, "");
+ YamlSection result = instance.trimHead();
+ assertEquals(expResult, result);
+ }
+
+ /**
+ * Test of isEmpty method, of class YamlSection.
+ */
+ @Test
+ public void testIsEmpty() {
+ YamlSection instance1 = new YamlSection(42, "");
+ YamlSection instance2 = new YamlSection(42, "name:");
+ assertTrue(instance1.isEmpty());
+ assertFalse(instance2.isEmpty());
+ }
+
+ /**
+ * Test of length method, of class YamlSection.
+ */
+ @Test
+ public void testLength() {
+ YamlSection instance = new YamlSection(42, "name:");
+ assertEquals(5, instance.length());
+ }
+
+ @Test
+ public void testSplit1() {
+ YamlSection instance = new YamlSection("name: John Smith");
+ YamlSection section1 = new YamlSection("name: ");
+ YamlSection section2 = new YamlSection(11, "Smith");
+ Iterator<YamlSection> result = instance.split(6, 11).iterator();
+ assertEquals(section2, result.next());
+ assertEquals(section1, result.next());
+ assertFalse(result.hasNext());
+ }
+
+ @Test
+ public void testSplit2() {
+ YamlSection instance = new YamlSection("name: John Smith");
+ YamlSection section1 = new YamlSection("name: ");
+ YamlSection section2 = new YamlSection(6, "John Smith");
+ Iterator<YamlSection> result = instance.split(6).iterator();
+ assertEquals(section2, result.next());
+ assertEquals(section1, result.next());
+ assertFalse(result.hasNext());
+ }
+
+ @Test
+ public void testSplitEmpty1() {
+ YamlSection instance = new YamlSection("name: John Smith");
+ Iterator<YamlSection> result = instance.split(0, 11).iterator();
+ YamlSection section2 = new YamlSection(11, "Smith");
+ assertEquals(section2, result.next());
+ assertFalse(result.hasNext());
+ }
+
+ @Test
+ public void testSplitEmpty2() {
+ YamlSection instance = new YamlSection("name: John Smith");
+ YamlSection section1 = new YamlSection("name: ");
+ Iterator<YamlSection> result = instance.split(6, 16).iterator();
+ assertEquals(section1, result.next());
+ assertFalse(result.hasNext());
+ }
+
+ @Test
+ public void testSplitEmpty3() {
+ YamlSection instance = new YamlSection("name: John Smith");
+ Iterator<YamlSection> result = instance.split(0, 16).iterator();
+ assertFalse(result.hasNext());
+ }
+
+ @Test
+ public void testSplitEmpty4() {
+ YamlSection instance = new YamlSection("name: { ");
+ YamlSection section1 = new YamlSection("name: ");
+ Iterator<YamlSection> result = instance.split(8).iterator();
+ assertEquals(section1, result.next());
+ assertFalse(result.hasNext());
+ }
+
+ @Test
+ public void testSplitEmpty5() {
+ YamlSection instance = new YamlSection(" \nname: {");
+ YamlSection section1 = new YamlSection(7, " {");
+ Iterator<YamlSection> result = instance.split(0).iterator();
+ assertEquals(section1, result.next());
+ assertFalse(result.hasNext());
+ }
+
+ @Test
+ public void testSplitEmpty6() {
+ YamlSection instance = new YamlSection("");
+ assertTrue(instance.split(0).isEmpty());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[netbeans] 01/06: Added snakeyaml-engine 2.3 as a library project
Posted by lk...@apache.org.
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 4fdfacecf4fdc2c38631d843cbaae89ea636cc1b
Author: Laszlo Kishalmi <la...@gmail.com>
AuthorDate: Mon Oct 4 07:54:23 2021 -0700
Added snakeyaml-engine 2.3 as a library project
---
ide/libs.snakeyaml_engine/build.xml | 24 +++
ide/libs.snakeyaml_engine/external/binaries-list | 17 ++
.../external/snakeyaml-engine-2.3-license.txt | 207 +++++++++++++++++++++
ide/libs.snakeyaml_engine/manifest.mf | 4 +
.../nbproject/project.properties | 21 +++
ide/libs.snakeyaml_engine/nbproject/project.xml | 38 ++++
.../libs/snakeyaml_engine/Bundle.properties | 22 +++
nbbuild/cluster.properties | 1 +
8 files changed, 334 insertions(+)
diff --git a/ide/libs.snakeyaml_engine/build.xml b/ide/libs.snakeyaml_engine/build.xml
new file mode 100644
index 0000000..0bce4dc
--- /dev/null
+++ b/ide/libs.snakeyaml_engine/build.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<project name="ide/libs.snakeyaml_engine" default="build" basedir=".">
+ <import file="../../nbbuild/templates/projectized.xml"/>
+</project>
diff --git a/ide/libs.snakeyaml_engine/external/binaries-list b/ide/libs.snakeyaml_engine/external/binaries-list
new file mode 100644
index 0000000..2b6a948
--- /dev/null
+++ b/ide/libs.snakeyaml_engine/external/binaries-list
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+E6EAAFDC8DEA303778E3459707DA0E3D71E969EF org.snakeyaml:snakeyaml-engine:2.3
diff --git a/ide/libs.snakeyaml_engine/external/snakeyaml-engine-2.3-license.txt b/ide/libs.snakeyaml_engine/external/snakeyaml-engine-2.3-license.txt
new file mode 100644
index 0000000..1dba14a
--- /dev/null
+++ b/ide/libs.snakeyaml_engine/external/snakeyaml-engine-2.3-license.txt
@@ -0,0 +1,207 @@
+Name: snakeyaml-engine
+Description: YAML 1.2 parser, reader, writer library
+Origin: GitHub
+Version: 2.3
+License: Apache-2.0
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/ide/libs.snakeyaml_engine/manifest.mf b/ide/libs.snakeyaml_engine/manifest.mf
new file mode 100644
index 0000000..2791b1c
--- /dev/null
+++ b/ide/libs.snakeyaml_engine/manifest.mf
@@ -0,0 +1,4 @@
+Manifest-Version: 1.0
+OpenIDE-Module: org.netbeans.libs.snakeyaml_engine/2
+OpenIDE-Module-Localizing-Bundle: org/netbeans/libs/snakeyaml_engine/Bundle.properties
+OpenIDE-Module-Specification-Version: 2.3
diff --git a/ide/libs.snakeyaml_engine/nbproject/project.properties b/ide/libs.snakeyaml_engine/nbproject/project.properties
new file mode 100644
index 0000000..a829537
--- /dev/null
+++ b/ide/libs.snakeyaml_engine/nbproject/project.properties
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+is.autoload=true
+release.external/snakeyaml-engine-2.3.jar=modules/ext/snakeyaml-engine.jar
+
+sigtest.gen.fail.on.error=false
diff --git a/ide/libs.snakeyaml_engine/nbproject/project.xml b/ide/libs.snakeyaml_engine/nbproject/project.xml
new file mode 100644
index 0000000..5027483
--- /dev/null
+++ b/ide/libs.snakeyaml_engine/nbproject/project.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.apisupport.project</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
+ <code-name-base>org.netbeans.libs.snakeyaml_engine</code-name-base>
+ <module-dependencies>
+ </module-dependencies>
+ <public-packages>
+ <subpackages>org.snakeyaml.engine.v2</subpackages>
+ </public-packages>
+ <class-path-extension>
+ <runtime-relative-path>ext/snakeyaml-engine.jar</runtime-relative-path>
+ <binary-origin>external/snakeyaml-engine-2.3.jar</binary-origin>
+ </class-path-extension>
+ </data>
+ </configuration>
+</project>
diff --git a/ide/libs.snakeyaml_engine/src/org/netbeans/libs/snakeyaml_engine/Bundle.properties b/ide/libs.snakeyaml_engine/src/org/netbeans/libs/snakeyaml_engine/Bundle.properties
new file mode 100644
index 0000000..7625a70
--- /dev/null
+++ b/ide/libs.snakeyaml_engine/src/org/netbeans/libs/snakeyaml_engine/Bundle.properties
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+OpenIDE-Module-Name=YAML Parser Library (snakeyaml-engine)
+OpenIDE-Module-Display-Category=Libraries
+OpenIDE-Module-Short-Description=YAML Library (snakeyaml-engine)
+OpenIDE-Module-Long-Description=\
+ This module bundles the popular snakeyaml-engine library used by the YAML support.
diff --git a/nbbuild/cluster.properties b/nbbuild/cluster.properties
index 66582da..791cef9 100644
--- a/nbbuild/cluster.properties
+++ b/nbbuild/cluster.properties
@@ -445,6 +445,7 @@ nb.cluster.ide=\
libs.jvyamlb,\
libs.lucene,\
libs.smack,\
+ libs.snakeyaml_engine,\
libs.svnClientAdapter,\
libs.svnClientAdapter.javahl,\
libs.truffleapi,\
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists