Mercurial Hosting > luan
annotate src/luan/modules/parsers/Html.java @ 1518:f989778ca9e1
stringify, json_string
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 19 Jun 2020 17:50:25 -0600 |
parents | 27efb1fcbcb5 |
children | b89212fd04b5 |
rev | line source |
---|---|
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 package luan.modules.parsers; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 import java.util.List; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 import java.util.ArrayList; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 import java.util.Set; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 import java.util.HashSet; |
1333
25746915a241
merge Luan and LuanState
Franklin Schmidt <fschmidt@gmail.com>
parents:
1330
diff
changeset
|
7 import luan.Luan; |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 import luan.LuanTable; |
1330 | 9 import luan.LuanException; |
1402
27efb1fcbcb5
move luan.lib to goodjava
Franklin Schmidt <fschmidt@gmail.com>
parents:
1333
diff
changeset
|
10 import goodjava.parser.Parser; |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 public final class Html { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 |
1333
25746915a241
merge Luan and LuanState
Franklin Schmidt <fschmidt@gmail.com>
parents:
1330
diff
changeset
|
15 public static LuanTable toList(Luan luan,String text,LuanTable containerTagsTbl) { |
1330 | 16 try { |
17 return new Html(luan,text,containerTagsTbl).parse(); | |
18 } catch(LuanException e) { | |
19 throw new RuntimeException(e); | |
20 } | |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 |
1333
25746915a241
merge Luan and LuanState
Franklin Schmidt <fschmidt@gmail.com>
parents:
1330
diff
changeset
|
23 private final Luan luan; |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 private final Parser parser; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 private final Set<String> containerTags = new HashSet<String>(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 |
1333
25746915a241
merge Luan and LuanState
Franklin Schmidt <fschmidt@gmail.com>
parents:
1330
diff
changeset
|
27 private Html(Luan luan,String text,LuanTable containerTagsTbl) { |
1267 | 28 this.luan = luan; |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 this.parser = new Parser(text); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 for( Object v : containerTagsTbl.asList() ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 containerTags.add((String)v); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 |
1330 | 35 private LuanTable parse() throws LuanException { |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 List list = new ArrayList(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 StringBuilder sb = new StringBuilder(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 while( !parser.endOfInput() ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 if( parser.test('<') ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 LuanTable tbl = parseTag(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 if( tbl != null ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 String tagName = (String)tbl.rawGet("name"); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 if( containerTags.contains(tagName) ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 LuanTable container = parseContainer(tbl); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 if( container != null ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 tbl = container; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 if( tbl != null |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
49 || (tbl = parseComment()) != null |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 || (tbl = parseCdata()) != null |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 if( sb.length() > 0 ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 list.add(sb.toString()); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
54 sb.setLength(0); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
55 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
56 list.add(tbl); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
57 continue; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
58 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
59 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
60 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
61 sb.append( parser.currentChar() ); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
62 parser.anyChar(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
63 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
64 if( sb.length() > 0 ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
65 list.add(sb.toString()); |
1267 | 66 return new LuanTable(luan,list); |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
67 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
68 |
1330 | 69 private LuanTable parseComment() throws LuanException { |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
70 parser.begin(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
71 if( !parser.match("<!--") ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
72 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
73 int start = parser.currentIndex(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
74 while( !parser.test("-->") ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
75 if( !parser.anyChar() ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
76 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
77 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
78 String text = parser.textFrom(start); |
1267 | 79 LuanTable tbl = new LuanTable(luan); |
1330 | 80 tbl.put("type","comment"); |
81 tbl.put("text",text); | |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
82 return parser.success(tbl); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
83 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
84 |
1330 | 85 private LuanTable parseCdata() throws LuanException { |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
86 parser.begin(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
87 if( !parser.match("<![CDATA[") ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
88 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
89 int start = parser.currentIndex(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
90 while( !parser.test("]]>") ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
91 if( !parser.anyChar() ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
92 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
93 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
94 String text = parser.textFrom(start); |
1267 | 95 LuanTable tbl = new LuanTable(luan); |
1330 | 96 tbl.put("type","cdata"); |
97 tbl.put("text",text); | |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
98 return parser.success(tbl); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
99 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
100 |
1330 | 101 private LuanTable parseContainer(LuanTable tag) throws LuanException { |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
102 String endTagName = '/' + (String)tag.rawGet("name"); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
103 int start = parser.begin(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
104 int end; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
105 while(true) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
106 if( parser.test('<') ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
107 end = parser.currentIndex(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
108 LuanTable tag2 = parseTag(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
109 String s = (String)tag2.rawGet("name"); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
110 if( s.equals(endTagName) ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
111 break; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
112 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
113 if( !parser.anyChar() ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
114 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
115 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
116 String text = parser.text.substring(start,end); |
1267 | 117 LuanTable tbl = new LuanTable(luan); |
1330 | 118 tbl.put("type","container"); |
119 tbl.put("tag",tag); | |
120 tbl.put("text",text); | |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
121 return parser.success(tbl); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
122 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
123 |
1330 | 124 private LuanTable parseTag() throws LuanException { |
1289
8d54bcc0b6d3
add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents:
1279
diff
changeset
|
125 LuanTable tbl = new LuanTable(luan); |
1330 | 126 tbl.put("type","tag"); |
1279 | 127 int tagStart = parser.begin(); |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
128 if( !parser.match('<') ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
129 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
130 int start = parser.currentIndex(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
131 parser.match('/'); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
132 if( !matchNameChar() ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
133 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
134 while( matchNameChar() ); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
135 String name = parser.textFrom(start).toLowerCase(); |
1330 | 136 tbl.put("name",name); |
1267 | 137 LuanTable attributes = new LuanTable(luan); |
1330 | 138 tbl.put("attributes",attributes); |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
139 String attrName; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
140 while( (attrName = parseAttrName()) != null ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
141 String attrValue = parseAttrValue(); |
1330 | 142 attributes.put( attrName, attrValue!=null ? attrValue : true ); |
1289
8d54bcc0b6d3
add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents:
1279
diff
changeset
|
143 if( attrName.equals("style") && attrValue!=null ) { |
8d54bcc0b6d3
add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents:
1279
diff
changeset
|
144 LuanTable style = Css.style(luan,attrValue); |
8d54bcc0b6d3
add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents:
1279
diff
changeset
|
145 if( style!=null ) |
1330 | 146 tbl.put("style",style); |
1289
8d54bcc0b6d3
add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents:
1279
diff
changeset
|
147 } |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
148 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
149 while( matchSpace() ); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
150 boolean isEmpty = parser.match('/'); |
1330 | 151 tbl.put("is_empty",isEmpty); |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
152 if( !parser.match('>') ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
153 return parser.failure(null); |
1279 | 154 String raw = parser.textFrom(tagStart); |
1330 | 155 tbl.put("raw",raw); |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
156 return parser.success(tbl); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
157 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
158 |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
159 private String parseAttrName() { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
160 parser.begin(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
161 if( !matchSpace() ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
162 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
163 while( matchSpace() ); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
164 int start = parser.currentIndex(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
165 if( !matchNameChar() ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
166 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
167 while( matchNameChar() ); |
1289
8d54bcc0b6d3
add css style parser
Franklin Schmidt <fschmidt@gmail.com>
parents:
1279
diff
changeset
|
168 String name = parser.textFrom(start).toLowerCase(); |
625
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
169 return parser.success(name); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
170 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
171 |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
172 private String parseAttrValue() { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
173 parser.begin(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
174 while( matchSpace() ); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
175 if( !parser.match('=') ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
176 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
177 while( matchSpace() ); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
178 if( parser.anyOf("\"'") ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
179 char quote = parser.lastChar(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
180 int start = parser.currentIndex(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
181 while( !parser.test(quote) ) { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
182 if( !parser.anyChar() ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
183 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
184 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
185 String value = parser.textFrom(start); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
186 parser.match(quote); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
187 return parser.success(value); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
188 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
189 int start = parser.currentIndex(); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
190 if( !matchValueChar() ) |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
191 return parser.failure(null); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
192 while( matchValueChar() ); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
193 String value = parser.textFrom(start); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
194 return parser.success(value); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
195 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
196 |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
197 private boolean matchNameChar() { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
198 return parser.inCharRange('a','z') |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
199 || parser.inCharRange('A','Z') |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
200 || parser.inCharRange('0','9') |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
201 || parser.anyOf("_.-:") |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
202 ; |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
203 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
204 |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
205 private boolean matchValueChar() { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
206 return parser.noneOf(" \t\r\n\"'>/="); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
207 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
208 |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
209 private boolean matchSpace() { |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
210 return parser.anyOf(" \t\r\n"); |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
211 } |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
212 |
a3c1e11fb6aa
rewrite much of Html to be more understandable;
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
213 } |