Skip to content

Commit

Permalink
Fixed parsing of epsilon character in an input file. It turns out the…
Browse files Browse the repository at this point in the history
…re are two different Unicode symbols for lowercase epsilon.
  • Loading branch information
sylvainhalle committed Aug 5, 2015
1 parent b574670 commit cad1443
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Source/Parsing/src/ca/uqac/lif/bullwinkle/BnfParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void setStartRule(final NonTerminalToken token)
if (!alt_it.hasNext())
{
// We succeeded in parsing the complete string: done
if (level > 0 || n_input.length() == 0)
if (level > 0 || (level == 0 && n_input.toString().trim().length() == 0))
{
break;
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Parsing/src/ca/uqac/lif/bullwinkle/BnfRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ public static BnfRule parseRule(String input) throws BnfRule.InvalidRuleExceptio
Token to_add = new NonTerminalToken(trimmed_word);
alternative_to_add.add(to_add);
}
else if (trimmed_word.compareTo("ε") == 0)
else if (trimmed_word.compareTo("\uCEB5") == 0 || trimmed_word.compareTo("\u03B5") == 0)
{
// There are two "lowercase epsilon" code points in Unicode; check for both
Token to_add = new EpsilonTerminalToken();
alternative_to_add.add(to_add);
}
Expand Down
40 changes: 38 additions & 2 deletions Source/ParsingTest/src/ca/uqac/lif/bullwinkle/GrammarTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void parseGrammar2a()
public void parseGrammar2b()
{
String expression = "SELECT a FROM (SELECT b FROM t)";
ParseNode node = parseIt("data/Grammar-1.bnf", "<S>", expression, true);
ParseNode node = parseIt("data/Grammar-1.bnf", "<S>", expression, false);
int size = node.getSize();
int expected_size = 19;
if (size != expected_size)
Expand Down Expand Up @@ -120,6 +120,13 @@ public void parseGrammar4()
assertEquals("Incorrect parse tree size for expression " + expression, 5, node.getSize());
}

@Test
public void parseGrammar5()
{
String expression = "a WHERE";
parseItNot("data/Grammar-10.bnf", "<S>", expression, false);
}

@Test
public void parseGrammarLtlFo1()
{
Expand All @@ -137,7 +144,7 @@ public void parseGrammarLtlFo1()
public void parseGrammarWithEpsilon1()
{
String expression = "hello hello";
ParseNode node = parseIt("data/Grammar-3.bnf", "<S>", expression, false);
ParseNode node = parseIt("data/Grammar-3.bnf", "<S>", expression, true);
int size = node.getSize();
int expected_size = 6;
if (size != expected_size)
Expand Down Expand Up @@ -218,6 +225,13 @@ private ParseNode parseIt(String grammar_filename, String start_symbol, String e
return node;
}

private void parseItNot(String grammar_filename, String start_symbol, String expression, boolean debug_mode)
{
BnfParser parser = readGrammar(grammar_filename, start_symbol, debug_mode);
shouldNotParse(expression, parser);
}


private ParseNode shouldParseAndNotNull(final String expression, final BnfParser parser)
{
ParseNode node = shouldParse(expression, parser);
Expand Down Expand Up @@ -248,6 +262,28 @@ private ParseNode shouldParse(final String expression, final BnfParser parser)
}
return node;
}

/**
* Attempts to parse an expression with the given parser, and
* expects the parsing not to raise an exception or to return null.
* @param expression The expression to parse
* @param parser The parser to use
*/
private void shouldNotParse(final String expression, final BnfParser parser)
{
ParseNode node = null;
try
{
node = parser.parse(expression);
}
catch (BnfParser.ParseException e)
{
}
if (node != null)
{
fail("The parsing of " + expression + " should have failed");
}
}

public static BnfParser readGrammar(final String filename, final String start_rule, boolean debug_mode)
{
Expand Down
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<mkdir dir="${build.test.bindir}"/>
<javac
target="1.6" source="1.6"
bootclasspath="${java6.boot.classpath}"
srcdir="${build.test.srcdir}"
destdir="${build.test.bindir}"
includeantruntime="false">
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<name>Bullwinkle</name>

<!-- The project's version number -->
<version>1.1.3</version>
<version>1.1.4</version>

<!-- The project's author. Currently this only
shows up in the footer of the Javadoc documentation. -->
Expand Down

0 comments on commit cad1443

Please sign in to comment.