Changeset 35291 in osm for applications
- Timestamp:
- 2020-01-13T21:45:35+01:00 (5 years ago)
- Location:
- applications/editors/josm/plugins/comfort0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/comfort0/src/net/simon04/comfort0/level0l/Level0LParser.jj
r35290 r35291 1 1 options { 2 2 STATIC = false; 3 OUTPUT_DIRECTORY = "parsergen";4 3 } 5 4 … … 15 14 16 15 <DEFAULT> //HEADER 17 SKIP: { " " }18 19 <DEFAULT> //HEADER20 16 TOKEN: { 21 < H_EOL: ("\n" | "\r" | "\r\n") >: DATA22 | < H_ID: (["0"-"9"])+ >17 <EOL: ("\n" | "\r" | "\r\n") > 18 | <ID: (["0"-"9"])+ > 23 19 | <NODE: "node" > 24 20 | <WAY: "way" > 25 21 | <RELATION: "relation" > 22 | <WY: "wy" > 23 | <ND: "nd" > 24 | <REL: "rel" > 25 | <EQ: "=" > : VALUE 26 | <IDENT: ["a"-"z", "A"-"Z", "_"] (["a"-"z", "A"-"Z", "_", ":", "-", "0"-"9"])* > 26 27 | <FLOAT: ("+" | "-")? (["0"-"9"])+ ("." (["0"-"9"])+)? > 27 28 | <COLON: ":" > 28 29 | <COMMA: "," > 30 | <WHITESPACE: ([" ", "\t"])+ > 29 31 | <COMMENT_START: "#"> : COMMENT 30 32 } … … 35 37 <COMMENT> 36 38 TOKEN: { 37 <C_EOL: ("\n" | "\r" | "\r\n") > : DATA 38 } 39 40 <DATA> 41 TOKEN: { 42 <D_EOL: ("\n" | "\r" | "\r\n") > 43 | <D_SPACE: " " > 44 | <D_ID: (["0"-"9"])+ > 45 | <WY: "wy" > 46 | <ND: "nd" > 47 | <REL: "rel" > 48 | <EQ: "=" > : VALUE 49 | <IDENT: ["a"-"z", "A"-"Z", "_"] (["a"-"z", "A"-"Z", "_", "-", "0"-"9"])* > 50 | <D_COMMENT_START: "#"> : COMMENT 39 <C_EOL: ("\n" | "\r" | "\r\n") > : DEFAULT 51 40 } 52 41 53 42 <VALUE> 54 43 TOKEN: { 55 <V_EOL: ("\n" | "\r" | "\r\n") > : D ATA44 <V_EOL: ("\n" | "\r" | "\r\n") > : DEFAULT 56 45 | <TEXT: (~["\n", "\r"])+ > 57 46 } … … 64 53 { 65 54 ( 66 (p = node() | p = way() | p = relation())55 p = node() 67 56 { primitives.add(p); } 57 | 58 p = way() 59 { primitives.add(p); } 60 | 61 p = relation() 62 { primitives.add(p); } 63 | 64 <COMMENT_START> <C_EOL> | <EOL> 68 65 )* 69 66 <EOF> … … 79 76 <NODE> 80 77 { r = new NodeData(); } 81 id=<H_ID> 78 ( <WHITESPACE> )+ 79 id=<ID> 82 80 { r.setId(Long.parseLong(id.image)); } 81 ( <WHITESPACE> )* 83 82 <COLON> 83 ( <WHITESPACE> )* 84 84 lat=<FLOAT> 85 ( <WHITESPACE> )* 85 86 <COMMA> 87 ( <WHITESPACE> )* 86 88 lon=<FLOAT> 87 89 { r.setCoor(new LatLon(Double.parseDouble(lat.image), Double.parseDouble(lon.image))); } 88 ( <COMMENT_START> <C_EOL> | <H_EOL> ) 89 ( <D_SPACE> <D_SPACE> tag(r) )* 90 ( <WHITESPACE> )* 91 ( <COMMENT_START> <C_EOL> | <EOL> ) 92 ( tag(r) )* 90 93 { return r; } 91 94 } … … 98 101 { 99 102 <WAY> 103 ( <WHITESPACE> )+ 100 104 { r = new WayData(); } 101 id=< H_ID>105 id=<ID> 102 106 { r.setId(Long.parseLong(id.image)); } 103 ( <COMMENT_START> <C_EOL> | <H_EOL> ) 107 ( <WHITESPACE> )* 108 ( <COMMENT_START> <C_EOL> | <EOL> ) 104 109 way_data(r) 105 110 { return r; } … … 113 118 { 114 119 <RELATION> 120 ( <WHITESPACE> )+ 115 121 { r = new RelationData(); } 116 id=< H_ID>122 id=<ID> 117 123 { r.setId(Long.parseLong(id.image)); } 118 ( <COMMENT_START> <C_EOL> | <H_EOL> ) 124 ( <WHITESPACE> )* 125 ( <COMMENT_START> <C_EOL> | <EOL> ) 119 126 relation_data(r) 120 127 { return r; } … … 124 131 {} 125 132 { 126 ( 127 <D_SPACE> <D_SPACE> 128 ( way_node(r) | tag(r) ) 129 )* 133 ( LOOKAHEAD(3) way_node(r) | tag(r) )* 130 134 } 131 135 … … 135 139 } 136 140 { 141 ( <WHITESPACE> )+ 137 142 <ND> 138 ( < D_SPACE> )+139 id=< D_ID>143 ( <WHITESPACE> )+ 144 id=<ID> 140 145 { r.getNodeIds().add(Long.parseLong(id.image)); } 141 ( < D_SPACE> )*142 ( < D_COMMENT_START> <C_EOL> | <D_EOL> )146 ( <WHITESPACE> )* 147 ( <COMMENT_START> <C_EOL> | <EOL> ) 143 148 } 144 149 … … 146 151 {} 147 152 { 148 ( 149 <D_SPACE> <D_SPACE> 150 ( relation_member(r) | tag(r) ) 151 )* 153 ( LOOKAHEAD(3) relation_member(r) | tag(r) )* 152 154 } 153 155 … … 159 161 } 160 162 { 163 ( <WHITESPACE> )+ 161 164 ( 162 165 <ND> { type = OsmPrimitiveType.NODE; } … … 166 169 <REL> { type = OsmPrimitiveType.RELATION; } 167 170 ) 168 <D_SPACE>169 id=< D_ID>171 ( <WHITESPACE> )+ 172 id=<ID> 170 173 ( 171 <D_SPACE> 172 ( 173 role=<IDENT> ( <D_SPACE> )* 174 | 175 ( <D_SPACE> )* 176 ) 174 LOOKAHEAD(2) 175 ( <WHITESPACE> )+ 176 role=<IDENT> 177 177 )? 178 178 { r.getMembers().add(new RelationMemberData(role != null ? role.image : "", type, Long.parseLong(id.image))); } 179 ( <D_COMMENT_START> <C_EOL> | <D_EOL> ) 179 ( <WHITESPACE> )* 180 ( <COMMENT_START> <C_EOL> | <EOL> ) 180 181 } 181 182 … … 185 186 } 186 187 { 188 ( <WHITESPACE> )+ 187 189 k=<IDENT> 188 ( < D_SPACE> )190 ( <WHITESPACE> )* 189 191 <EQ> 192 ( <WHITESPACE> )* 190 193 v=<TEXT> 191 194 <V_EOL> -
applications/editors/josm/plugins/comfort0/test/unit/net/simon04/comfort0/level0l/parsergen/Level0LParserTest.java
r35288 r35291 1 1 package net.simon04.comfort0.level0l.parsergen; 2 2 3 import static org.CustomMatchers.hasSize; 3 4 import static org.hamcrest.CoreMatchers.is; 4 5 import static org.junit.Assert.assertThat; 5 6 6 7 import java.io.StringReader; 8 import java.util.List; 7 9 8 10 import org.junit.Test; 9 11 import org.openstreetmap.josm.data.osm.NodeData; 10 12 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 13 import org.openstreetmap.josm.data.osm.PrimitiveData; 11 14 import org.openstreetmap.josm.data.osm.RelationData; 12 15 import org.openstreetmap.josm.data.osm.WayData; … … 73 76 assertThat(relation.getKeys().size(), is(6)); 74 77 } 78 79 @Test 80 public void testExampleFromDocs() throws Exception { 81 // https://wiki.openstreetmap.org/wiki/Level0L#Examples 82 final String level0l = "" + 83 "node 298884269: 54.0901746, 12.2482632 # made by user SvenHRO (46882) in changeset 676636 on 2008-09-21T21:37:45Z\n" + 84 "node 261728686: 54.0906309, 12.2441924 # versions should be stored server-side\n" + 85 "node 1831881213: 54.0900666, 12.2539381 # comments are not allowed in tag values, '=' is screened (\\=) only in keys\n" + 86 " name = Neu Broderstorf\n" + 87 " traffic_sign = city_limit\n" + 88 "\n" + 89 "node 298884272: 54.0901447, 12.2516513\n" + 90 "\n" + 91 "way 26659127\n" + 92 " nd 292403538\n" + 93 " nd 298884289\n" + 94 " nd 261728686\n" + 95 " highway = unclassified\n" + 96 " name = Pastower Straße\n" + 97 "\n" + 98 "relation 56688 # member types: nd, wy, rel; roles are put after ids\n" + 99 " nd 294942404\n" + 100 " nd 364933006\n" + 101 " wy 4579143 forward\n" + 102 " nd 249673494\n" + 103 " name = Küstenbus Linie 123\n" + 104 " network = VVW\n" + 105 " operator = Regionalverkehr Küste\n" + 106 " ref = 123\n" + 107 " route = bus\n" + 108 " type = route\n"; 109 final List<PrimitiveData> primitives = new Level0LParser(new StringReader(level0l)).primitives(); 110 assertThat(primitives, hasSize(6)); 111 assertThat(primitives.get(0).toString(), is("298884269 null V NODE LatLon[lat=54.0901746,lon=12.2482632]")); 112 assertThat(primitives.get(1).toString(), is("261728686 null V NODE LatLon[lat=54.0906309,lon=12.2441924]")); 113 assertThat(primitives.get(2).toString(), is("1831881213 [name, Neu Broderstorf, traffic_sign, city_limit] V NODE LatLon[lat=54.0900666,lon=12.2539381]")); 114 assertThat(primitives.get(3).toString(), is("298884272 null V NODE LatLon[lat=54.0901447,lon=12.2516513]")); 115 assertThat(primitives.get(4).toString(), is("26659127 [highway, unclassified, name, Pastower Straße] V WAY[292403538, 298884289, 261728686]")); 116 assertThat(primitives.get(5).toString(), is("56688 [name, Küstenbus Linie 123, network, VVW, operator, Regionalverkehr Küste, ref, 123, route, bus, type, route] V REL [node 294942404, node 364933006, way 4579143, node 249673494]")); 117 } 118 75 119 }
Note:
See TracChangeset
for help on using the changeset viewer.