annotate src/luan/modules/parsers/Html.java @ 1562:b89212fd04b5

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