aboutsummaryrefslogtreecommitdiff
path: root/src/main/model/html
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/model/html')
-rw-r--r--src/main/model/html/HtmlLexer.java68
-rw-r--r--src/main/model/html/HtmlTree.java33
2 files changed, 0 insertions, 101 deletions
diff --git a/src/main/model/html/HtmlLexer.java b/src/main/model/html/HtmlLexer.java
deleted file mode 100644
index 8cad425..0000000
--- a/src/main/model/html/HtmlLexer.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package model.html;
-
-import java.util.ArrayList;
-
-/**
- * We'll tokenize HTML by tags: disregarding the contents of the tag and attributes within the tag.
- * The file is also considered to be free-form here: whitespace duplicates are disregarded.
- */
-public class HtmlLexer {
-
- // Takes a String of raw HTML, and tokenizes it for our parser.
- public static ArrayList<String> lex(String input) {
- String token = "";
- ArrayList<String> tokens = new ArrayList<>();
- boolean inTag = false;
- boolean inSingleQuotes = false;
- boolean inDoubleQuotes = false;
-
- for (char i : input.toCharArray()) {
- token += i;
- switch (i) {
- case '<':
- if (!inSingleQuotes && !inDoubleQuotes) {
- inTag = true;
- if (!token.equals("<")) {
- tokens.add(token.substring(0, token.length() - 1));
- token = "<";
- }
- } else if (inTag) {
- System.out.printf("Probably failing parser");
- }
- break;
- case '>':
- if (!inSingleQuotes && !inDoubleQuotes) {
- if (!inTag) {
- System.out.printf("Probably failing parser");
- }
- inTag = false;
- tokens.add(token);
- token = "";
- }
- break;
- case '"':
- if (!inSingleQuotes) {
- inDoubleQuotes = !inDoubleQuotes;
- }
- break;
- case '\'':
- if (!inDoubleQuotes) {
- inSingleQuotes = !inSingleQuotes;
- }
- break;
- }
- }
- /**
- * When lexing invalid HTML: we may end up with trailing garbage: either an unfinished tag or extra text
- * (those are the only two options since this is just the lex step)
- */
- if (!token.equals("")) {
- if (inTag) {
- tokens.add(token + ">");
- } else {
- tokens.add(token);
- }
- }
- return tokens;
- }
-}
diff --git a/src/main/model/html/HtmlTree.java b/src/main/model/html/HtmlTree.java
deleted file mode 100644
index 1aae0a8..0000000
--- a/src/main/model/html/HtmlTree.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package model.html;
-
-import model.util.AbstractTree;
-import org.javatuples.Pair;
-
-import java.util.ArrayList;
-import java.util.Optional;
-
-/**
- * Representation of HTML as a tree of nodes. Sorry about the generics.
- */
-public class HtmlTree extends AbstractTree<Pair<String, ArrayList<Pair<String, String>>>> {
- private String tag;
- private ArrayList<Pair<String, String>> attributes;
- private Optional<HtmlTree> parent = Optional.empty();
- private Optional<HtmlTree> sibling = Optional.empty();
-
- // I don't quite know why I can't say ArrayList<HtmlTree> children.
- public HtmlTree(String tag, ArrayList<Pair<String, String>> attributes,
- ArrayList<AbstractTree<Pair<String, ArrayList<Pair<String, String>>>>> children,
- Optional<HtmlTree> parent, Optional<HtmlTree> sibling) {
- super(new Pair<>(tag, attributes), children);
- this.tag = tag;
- this.attributes = attributes;
- this.parent = parent;
- this.sibling = sibling;
- }
-
- public HtmlTree(String tag, ArrayList<Pair<String, String>> attributes) {
- this(tag, attributes, new ArrayList<AbstractTree<Pair<String, ArrayList<Pair<String, String>>>>>(),
- Optional.empty(), Optional.empty());
- }
-}