Changeset 35284 in osm for applications


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

JOSM/comfort0: parse tags

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

    r35283 r35284  
    1717<DEFAULT> //HEADER
    1818TOKEN: {
    19     <H_EOL: ("\n" | "\r" | "\r\n") >
     19    <H_EOL: ("\n" | "\r" | "\r\n") > : DATA
    2020    | <H_ID: (["0"-"9"])+ >
    2121    | <NODE: "node" >
     
    3939TOKEN: {
    4040    <D_EOL: ("\n" | "\r" | "\r\n") >
     41    | <D_SPACE: " " >
    4142    | <D_ID: (["0"-"9"])+ >
    4243    | <WY: "wy" >
    4344    | <ND: "nd" >
    4445    | <REL: "rel" >
    45     | <EQ: "=" >
     46    | <EQ: "=" > : VALUE
    4647    | <IDENT: ["a"-"z", "A"-"Z", "_"] (["a"-"z", "A"-"Z", "_", "-", "0"-"9"])* >
     48}
     49
     50<VALUE>
     51TOKEN: {
     52    <V_EOL: ("\n" | "\r" | "\r\n") > : DATA
     53    | <TEXT: (~["\n", "\r"])+ >
    4754}
    4855
     
    6370    { r.setCoor(new LatLon(Double.parseDouble(lat.image), Double.parseDouble(lon.image))); }
    6471    (<COMMENT_START> | <H_EOL>)
     72    tags(r)
    6573    { return r; }
    6674}
     75
     76void tags(PrimitiveData r):
     77{}
     78{
     79    ( tag(r) )*
     80}
     81
     82void tag(PrimitiveData r):
     83{
     84    Token k, v;
     85}
     86{
     87    <D_SPACE> <D_SPACE>
     88    k=<IDENT>
     89    ( <D_SPACE> ) *
     90    <EQ>
     91    v=<TEXT>
     92    <V_EOL>
     93    { r.put(k.image.trim(), v.image.trim()); }
     94}
  • applications/editors/josm/plugins/comfort0/test/unit/net/simon04/comfort0/level0l/parsergen/Level0LParserTest.java

    r35283 r35284  
    22
    33import static org.hamcrest.CoreMatchers.is;
    4 import static org.junit.Assert.*;
     4import static org.junit.Assert.assertThat;
    55
    66import java.io.StringReader;
     
    1212    @Test
    1313    public void testNode() throws Exception {
    14         final NodeData node = new Level0LParser(new StringReader("node 298884272: 54.0901447, 12.2516513\n")).node();
     14        final String level0l = "" +
     15                "node 298884272: 54.0901447, 12.2516513\n" +
     16                "  name = Neu Broderstorf\n" +
     17                "  traffic_sign = city_limit\n";
     18        final NodeData node = new Level0LParser(new StringReader(level0l)).node();
    1519        assertThat(node.getId(), is(298884272L));
    1620        assertThat(node.getCoor().lat(), is(54.0901447));
    1721        assertThat(node.getCoor().lon(), is(12.2516513));
    18 
     22        assertThat(node.getKeys().size(), is(2));
     23        assertThat(node.getKeys().get("name"), is("Neu Broderstorf"));
     24        assertThat(node.getKeys().get("traffic_sign"), is("city_limit"));
    1925    }
    2026}
Note: See TracChangeset for help on using the changeset viewer.