Changeset 35285 in osm for applications


Ignore:
Timestamp:
2020-01-13T21:45:18+01:00 (5 years ago)
Author:
simon04
Message:

JOSM/comfort0: parse ways

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

    r35284 r35285  
    4646    | <EQ: "=" > : VALUE
    4747    | <IDENT: ["a"-"z", "A"-"Z", "_"] (["a"-"z", "A"-"Z", "_", "-", "0"-"9"])* >
     48    | <D_COMMENT_START: "#"> : COMMENT
    4849}
    4950
     
    6970    lon=<FLOAT>
    7071    { r.setCoor(new LatLon(Double.parseDouble(lat.image), Double.parseDouble(lon.image))); }
    71     (<COMMENT_START> | <H_EOL>)
    72     tags(r)
     72    ( <COMMENT_START> | <H_EOL> )
     73    ( tag(r) )*
    7374    { return r; }
    7475}
    7576
    76 void tags(PrimitiveData r):
     77WayData way():
     78{
     79    WayData r;
     80    Token id;
     81}
     82{
     83    <WAY>
     84    { r = new WayData(); }
     85    id=<H_ID>
     86    { r.setId(Long.parseLong(id.image)); }
     87    ( <COMMENT_START> | <H_EOL> )
     88    way_data(r)
     89    { return r; }
     90}
     91
     92void way_data(WayData r):
    7793{}
    7894{
     95    LOOKAHEAD(3)
     96    ( way_node(r) way_data(r) ) // TODO avoid recursive call to way_data
     97    |
    7998    ( tag(r) )*
     99}
     100
     101void way_node(WayData r):
     102{
     103    Token id;
     104}
     105{
     106    <D_SPACE> <D_SPACE>
     107    <ND>
     108    ( <D_SPACE> )+
     109    id=<D_ID>
     110    { r.getNodeIds().add(Long.parseLong(id.image)); }
     111    ( <D_SPACE> )*
     112    ( <D_COMMENT_START> | <D_EOL> )
    80113}
    81114
  • applications/editors/josm/plugins/comfort0/test/unit/net/simon04/comfort0/level0l/parsergen/Level0LParserTest.java

    r35284 r35285  
    88import org.junit.Test;
    99import org.openstreetmap.josm.data.osm.NodeData;
     10import org.openstreetmap.josm.data.osm.WayData;
    1011
    1112public class Level0LParserTest {
     
    2425        assertThat(node.getKeys().get("traffic_sign"), is("city_limit"));
    2526    }
     27
     28    @Test
     29    public void testWay() throws Exception {
     30        final String level0l = "" +
     31                "way 26659127\n" +
     32                "  nd 292403538\n" +
     33                "  nd 298884289\n" +
     34                "  nd 261728686\n" +
     35                "  highway = unclassified\n" +
     36                "  name = Pastower Straße\n";
     37        final WayData way = new Level0LParser(new StringReader(level0l)).way();
     38        assertThat(way.getId(), is(26659127L));
     39        assertThat(way.getNodesCount(), is(3));
     40        assertThat(way.getNodeId(0), is(292403538L));
     41        assertThat(way.getNodeId(1), is(298884289L));
     42        assertThat(way.getNodeId(2), is(261728686L));
     43        assertThat(way.getKeys().size(), is(2));
     44        assertThat(way.getKeys().get("highway"), is("unclassified"));
     45        assertThat(way.getKeys().get("name"), is("Pastower Straße"));
     46    }
    2647}
Note: See TracChangeset for help on using the changeset viewer.