Skip to content

Commit

Permalink
Merge branch 'feature/lex-one-2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Nov 24, 2017
2 parents dc45253 + 67b57ab commit 818595a
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
10 changes: 7 additions & 3 deletions README-CHANGES.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<c:changelog xmlns:c="urn:com.io7m.changelog:4.0" project="com.io7m.jsx">
<?xml version="1.0" encoding="UTF-8"?><c:changelog xmlns:c="urn:com.io7m.changelog:4.0" project="com.io7m.jsx">
<c:releases>
<c:release date="2015-03-28T00:00:00+00:00" ticket-system="com.github.io7m.jsx" version="0.2.0">
<c:changes>
Expand Down Expand Up @@ -57,13 +56,18 @@
<c:change compatible="false" date="2017-11-16T00:00:00+00:00" summary="Removed dependency on com.io7m.jnull."/>
</c:changes>
</c:release>
<c:release date="2017-11-24T13:17:34+00:00" ticket-system="com.github.io7m.jsx" version="0.9.0">
<c:release date="2017-11-24T14:51:40+00:00" ticket-system="com.github.io7m.jsx" version="0.9.0">
<c:changes>
<c:change date="2017-11-24T00:00:00+00:00" summary="Add configurable comment tokens">
<c:tickets>
<c:ticket id="1"/>
</c:tickets>
</c:change>
<c:change date="2017-11-24T14:51:40+00:00" summary="Optionally start lexical positions at a given line">
<c:tickets>
<c:ticket id="2"/>
</c:tickets>
</c:change>
</c:changes>
</c:release>
</c:releases>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,15 @@ default EnumSet<JSXLexerComment> comments()
{
return EnumSet.noneOf(JSXLexerComment.class);
}

/**
* @return The starting line number (for lexical information)
*/

@Value.Parameter(order = 4)
@Value.Default
default int startAtLine()
{
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ private JSXLexer(
this.buffer =
new StringBuilder(256);
this.position =
LexicalPositionMutable.create(0, 0, Optional.empty());
LexicalPositionMutable.create(c.startAtLine(), 0, Optional.empty());
this.buffer_position =
LexicalPositionMutable.create(0, 0, Optional.empty());
LexicalPositionMutable.create(c.startAtLine(), 0, Optional.empty());

this.position.setFile(c.file());
this.buffer_position.setFile(c.file());
Expand Down Expand Up @@ -149,8 +149,7 @@ private JSXLexerNewLinesInStringsException errorNewLinesNotInQuotedStrings()
{
return new JSXLexerNewLinesInStringsException(
this.snapshotPosition(),
"Lexer configuration does not permit newlines (U+000A or U+000D) in "
+ "quoted strings");
"Lexer configuration does not permit newlines (U+000A or U+000D) in quoted strings");
}

private JSXLexerNotHexCharException errorNotHexChar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,67 @@ public void testComments0()

final TokenEOF t = (TokenEOF) lex.token();
}

@Test
public void testStartAt0()
throws Exception
{
final JSXLexerConfiguration.Builder cb =
JSXLexerConfiguration.builder();
cb.setFile(Optional.of(Paths.get("file.txt")));
cb.setStartAtLine(0);

final JSXLexerConfiguration c = cb.build();

final JSXLexerType lex = JSXLexer.newLexer(c, LexerTest.stringReader("("));
final TokenLeftParenthesis t = (TokenLeftParenthesis) lex.token();
System.out.println(t);

Assert.assertEquals(
Optional.of(Paths.get("file.txt")), t.lexical().file());
Assert.assertEquals(0L, (long) t.lexical().line());
Assert.assertEquals(1L, (long) t.lexical().column());
}

@Test
public void testStartAt1()
throws Exception
{
final JSXLexerConfiguration.Builder cb =
JSXLexerConfiguration.builder();
cb.setFile(Optional.of(Paths.get("file.txt")));
cb.setStartAtLine(1);

final JSXLexerConfiguration c = cb.build();

final JSXLexerType lex = JSXLexer.newLexer(c, LexerTest.stringReader("("));
final TokenLeftParenthesis t = (TokenLeftParenthesis) lex.token();
System.out.println(t);

Assert.assertEquals(
Optional.of(Paths.get("file.txt")), t.lexical().file());
Assert.assertEquals(1L, (long) t.lexical().line());
Assert.assertEquals(1L, (long) t.lexical().column());
}

@Test
public void testStartAt100()
throws Exception
{
final JSXLexerConfiguration.Builder cb =
JSXLexerConfiguration.builder();
cb.setFile(Optional.of(Paths.get("file.txt")));
cb.setStartAtLine(100);

final JSXLexerConfiguration c = cb.build();

final JSXLexerType lex = JSXLexer.newLexer(c, LexerTest.stringReader("("));
final TokenLeftParenthesis t = (TokenLeftParenthesis) lex.token();
System.out.println(t);

Assert.assertEquals(
Optional.of(Paths.get("file.txt")), t.lexical().file());
Assert.assertEquals(100L, (long) t.lexical().line());
Assert.assertEquals(1L, (long) t.lexical().column());
}
}

0 comments on commit 818595a

Please sign in to comment.