annotate src/luan/modules/parsers/Html.java @ 1289:8d54bcc0b6d3

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