1. Stephen McKamey
  2. duel

Commits

Stephen McKamey  committed 8b32ba6

- fixing case where entity starts literal

  • Participants
  • Parent commits 5c9681a
  • Branches default

Comments (0)

Files changed (2)

File src/org/duelengine/duel/parsing/DuelLexer.java

View file
  • Ignore whitespace
 		try {
 			switch (this.token.getToken()) {
 				case START:
+				case LITERAL:
+				case UNPARSED:
 					switch (this.ch) {
 						case DuelGrammar.OP_ELEM_BEGIN:
 							if (this.tryScanTag()) {
 
 		// reset the buffer
 		this.buffer.setLength(0);
-		this.buffer.append((char)this.ch);
-		this.nextChar();
 
 		while (true) {
 			switch (this.ch) {
-				case DuelGrammar.OP_ELEM_BEGIN:
 				case DuelGrammar.EOF:
 					// flush the buffer
 					return DuelToken.Literal(this.buffer.toString());
 					this.decodeEntity();
 					break;
 
+				case DuelGrammar.OP_ELEM_BEGIN:
+					if (this.buffer.length() != 0) {
+						// flush the buffer
+						return DuelToken.Literal(this.buffer.toString());
+					}
+
+					this.buffer.append((char)this.ch);
+					this.nextChar();
+					break;
+
 				default:
 					// consume until reach a special char
 					this.buffer.append((char)this.ch);

File test/org/duelengine/duel/parsing/DuelLexerTests.java

View file
  • Ignore whitespace
 	}
 
 	@Test
+	public void entityOnlyTest() {
+
+		String input = "|;,";
+
+		Object[] expected = {
+				DuelToken.Literal("|;,")
+			};
+
+		Object[] actual = new DuelLexer(input).toList().toArray();
+
+		assertArrayEquals(expected, actual);
+	}
+
+	@Test
 	public void entityDecimalTest() {
 
 		String input = "This is 'just <literal te"xt & some entities>.";
 
 		assertArrayEquals(expected, actual);
 	}
+
+	@Test
+	public void singleElemTest() {
+
+		String input = "<div>";
+
+		Object[] expected = {
+				DuelToken.ElemBegin("div")
+			};
+
+		Object[] actual = new DuelLexer(input).toList().toArray();
+
+		assertArrayEquals(expected, actual);
+	}
 }