Skip to content

Commit

Permalink
Merge pull request #23 from ndw/update-199
Browse files Browse the repository at this point in the history
API and documentation updates for the 1.99.x APIs
  • Loading branch information
ndw committed Jun 28, 2022
2 parents 384c611 + be8add6 commit d231d6c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 22 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
sacksName=coffeesacks
sacksTitle=CoffeeSacks
sacksVersion=1.1.0
sacksVersion=1.99.7

filterName=coffeefilter
filterVersion=1.1.0
filterVersion=1.99.7

grinderName=coffeegrinder
grinderVersion=1.1.0
grinderVersion=1.99.7

xmlresolverVersion=4.2.0
xmlresolverVersion=4.3.0
docbookVersion=5.2b12
xslTNGversion=1.6.0

Expand Down
56 changes: 40 additions & 16 deletions src/main/java/org/nineml/coffeesacks/ParserOptionsFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import net.sf.saxon.value.BooleanValue;
import net.sf.saxon.value.SequenceType;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.*;

/**
* A Saxon extension function to change the parser options.
Expand Down Expand Up @@ -74,24 +71,39 @@ public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPa
throw new XPathException("Argument to CoffeeSacks parser-options function must be a map");
}

Set<String> validOptions = new HashSet<>(Arrays.asList("ignoreTrailingWhitespace",
"suppressAmbiguousState", "suppressPrefixState", "allowUndefinedSymbols"));
Set<String> booleanOptions = new HashSet<>(Arrays.asList("ignoreTrailingWhitespace",
"allowUndefinedSymbols", "allowUnreachableSymbols", "allowUnproductiveSymobls",
"allowMultipleDefinitions", "showMarks", "showBnfNonterminals",
"suppressAmbiguousState", "suppressPrefixState"));

Set<String> stringOptions = new HashSet<>(Collections.singletonList("parser"));

boolean changed = false;
boolean ok = true;
for (String key : options.keySet()) {
String value = options.get(key);
Boolean bool = null;

if (validOptions.contains(key)) {
if ("true".equals(value) || "yes".equals(value) || "1".equals(value)) {
bool = true;
} else if ("false".equals(value) || "no".equals(value) || "0".equals(value)) {
bool = false;
final boolean bool;

if (booleanOptions.contains(key) || stringOptions.contains(key)) {
if (booleanOptions.contains(key)) {
if ("true".equals(value) || "yes".equals(value) || "1".equals(value)) {
bool = true;
} else if ("false".equals(value) || "no".equals(value) || "0".equals(value)) {
bool = false;
} else {
parserOptions.getLogger().warn(logcategory, "Ignoring unexpected value: %s=%s", key, value);
ok = false;
continue;
}
} else {
parserOptions.getLogger().warn(logcategory, "Ignoring unexpected value: %s=%s", key, value);
ok = false;
continue;
bool = false; // irrelevant, but make the IDE happy
if ("parser".equals(key)) {
if (!"GLL".equals(value) && !"Earley".equals(value)) {
parserOptions.getLogger().warn(logcategory, "Ignoring unexpected value: %s=%s", key, value);
ok = false;
continue;
}
}
}

switch (key) {
Expand Down Expand Up @@ -131,6 +143,18 @@ public Sequence call(XPathContext xPathContext, Sequence[] sequences) throws XPa
changed = changed || parserOptions.getAllowMultipleDefinitions() != bool;
parserOptions.setAllowMultipleDefinitions(bool);
break;
case "showMarks":
changed = changed || parserOptions.getShowMarks() != bool;
parserOptions.setShowMarks(bool);
break;
case "showBnfNonterminals":
changed = changed || parserOptions.getShowBnfNonterminals() != bool;
parserOptions.setShowBnfNonterminals(bool);
break;
case "parser":
changed = changed || !value.equals(parserOptions.getParserType());
parserOptions.setParserType(value);
break;
default:
parserOptions.getLogger().warn(logcategory, "Ignoring unexpected option: %s", key);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/nineml/coffeesacks/StylesheetTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.nineml.coffeefilter.utils.CommonBuilder;
import org.nineml.coffeefilter.InvisibleXml;

public class StylesheetTests extends TestConfiguration {
public static final QName ixml_state = new QName(CommonBuilder.ixml_prefix, CommonBuilder.ixml_ns, "state");
public static final QName ixml_state = new QName(InvisibleXml.ixml_prefix, InvisibleXml.ixml_ns, "state");

@Test
public void stringInputXmlOutput() {
Expand Down
32 changes: 32 additions & 0 deletions src/website/xml/coffeesacks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,38 @@ multiple definitions for a given nonterminal.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><code>allowMultipleDefinitions</code>, boolean</term>
<listitem>
<para>If true, the parser will attempt to use a grammar that contains
multiple definitions for a given nonterminal.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><code>showMarks</code>, boolean</term>
<listitem>
<para>If true, the parser will return all of the nonterminals in your
grammar as elements, irrespective of their marks. The actual mark will
be returned in an <code>ixml:mark</code> attribute.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><code>showBnfNonterminals</code>, boolean</term>
<listitem>
<para>If true, the parser will return all of the otherwise hidden nonterminals
used in the parse.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><code>parser</code>, string</term>
<listitem>
<para>Selects the parser type, “<code>Earley</code>” for the Earley parser
and “<code>GLL</code>” for the GLL parser. The Earley parser is the default.
</para>
</listitem>
</varlistentry>
</variablelist>

<para>The function will log errors (unrecognized options or values).
Expand Down

0 comments on commit d231d6c

Please sign in to comment.