diff --git a/frictionless/fields/__spec__/test_string.py b/frictionless/fields/__spec__/test_string.py index 24a83794f4..009e2d3ec3 100644 --- a/frictionless/fields/__spec__/test_string.py +++ b/frictionless/fields/__spec__/test_string.py @@ -37,6 +37,16 @@ def test_string_read_cell(format, source, target): "format, source, target", [ ("wkt", "POINT (30 10)", "POINT (30 10)"), + ( + "wkt", + "POINT (574009.086492192 6028393.69530573)", + "POINT (574009.086492192 6028393.69530573)", + ), + ( + "wkt", + "SRID=25832;POINT (574009.086492192 6028393.69530573)", + "SRID=25832;POINT (574009.086492192 6028393.69530573)", + ), ("wkt", "LINESTRING (30 10, 10 30, 40 40)", "LINESTRING (30 10, 10 30, 40 40)"), ( "wkt", diff --git a/frictionless/vendors/wkt/grammar.txt b/frictionless/vendors/wkt/grammar.txt index f8bcfee667..0136fde1fb 100644 --- a/frictionless/vendors/wkt/grammar.txt +++ b/frictionless/vendors/wkt/grammar.txt @@ -1,9 +1,16 @@ wkt_representation = + srid_specification wkt_representation_body | + wkt_representation_body; + +wkt_representation_body = point_text_representation | curve_text_representation | surface_text_representation | collection_text_representation; +srid_specification = + "SRID=" number ";"; + point_text_representation = "POINT" [ z_m ] point_text; curve_text_representation = diff --git a/frictionless/vendors/wkt/parser.py b/frictionless/vendors/wkt/parser.py index 29f30c578f..7cd484e248 100644 --- a/frictionless/vendors/wkt/parser.py +++ b/frictionless/vendors/wkt/parser.py @@ -1,63 +1,89 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 -# CAVEAT UTILITOR +# WARNING: CAVEAT UTILITOR # -# This file was automatically generated by TatSu. +# This file was automatically generated by TatSu. # -# https://pypi.python.org/pypi/tatsu/ +# https://pypi.python.org/pypi/tatsu/ # -# Any changes you make to it will be overwritten the next time -# the file is generated. +# Any changes you make to it will be overwritten the next time +# the file is generated. -from __future__ import annotations +# ruff: noqa: C405, COM812, I001, F401, PLR1702, PLC2801, SIM117 import sys +from pathlib import Path from tatsu.buffering import Buffer +from tatsu.parsing import Parser +from tatsu.parsing import tatsumasu +from tatsu.parsing import leftrec, nomemo, isname from tatsu.infos import ParserConfig -from tatsu.parsing import Parser, isname, leftrec, nomemo, tatsumasu # noqa -from tatsu.util import generic_main, re # noqa +from tatsu.util import re, generic_main -KEYWORDS = {} # type: ignore + +KEYWORDS: set[str] = set() class Buffer(Buffer): - def __init__(self, text, /, config: ParserConfig = None, **settings): + def __init__(self, text, /, config: ParserConfig | None = None, **settings): config = ParserConfig.new( config, owner=self, whitespace=None, nameguard=None, - comments_re=None, - eol_comments_re=None, ignorecase=False, namechars="", parseinfo=False, + comments=None, + eol_comments=None, + keywords=KEYWORDS, + start="wkt_representation", ) config = config.replace(**settings) + super().__init__(text, config=config) class Parser(Parser): - def __init__(self, /, config: ParserConfig = None, **settings): + def __init__(self, /, config: ParserConfig | None = None, **settings): config = ParserConfig.new( config, owner=self, whitespace=None, nameguard=None, - comments_re=None, - eol_comments_re=None, ignorecase=False, namechars="", parseinfo=False, + comments=None, + eol_comments=None, keywords=KEYWORDS, start="wkt_representation", ) config = config.replace(**settings) + super().__init__(config=config) @tatsumasu() - def _wkt_representation_(self): # noqa + def _wkt_representation_(self): + with self._choice(): + with self._option(): + self._srid_specification_() + self._wkt_representation_body_() + with self._option(): + self._wkt_representation_body_() + self._error( + "expecting one of: " + "'SRID=' " + "" + "" + "" + "" + "" + ) + + @tatsumasu() + def _wkt_representation_body_(self): with self._choice(): with self._option(): self._point_text_representation_() @@ -85,14 +111,20 @@ def _wkt_representation_(self): # noqa ) @tatsumasu() - def _point_text_representation_(self): # noqa + def _srid_specification_(self): + self._token("SRID=") + self._number_() + self._token(";") + + @tatsumasu() + def _point_text_representation_(self): self._token("POINT") with self._optional(): self._z_m_() self._point_text_() @tatsumasu() - def _curve_text_representation_(self): # noqa + def _curve_text_representation_(self): with self._choice(): with self._option(): self._linestring_text_representation_() @@ -110,32 +142,32 @@ def _curve_text_representation_(self): # noqa ) @tatsumasu() - def _linestring_text_representation_(self): # noqa + def _linestring_text_representation_(self): self._token("LINESTRING") with self._optional(): self._z_m_() self._linestring_text_body_() @tatsumasu() - def _circularstring_text_representation_(self): # noqa + def _circularstring_text_representation_(self): self._token("CIRCULARSTRING") with self._optional(): self._z_m_() self._circularstring_text_() @tatsumasu() - def _compoundcurve_text_representation_(self): # noqa + def _compoundcurve_text_representation_(self): self._token("COMPOUNDCURVE") with self._optional(): self._z_m_() self._compoundcurve_text_() @tatsumasu() - def _surface_text_representation_(self): # noqa + def _surface_text_representation_(self): self._curvepolygon_text_representation_() @tatsumasu() - def _curvepolygon_text_representation_(self): # noqa + def _curvepolygon_text_representation_(self): with self._choice(): with self._option(): self._token("CURVEPOLYGON") @@ -154,21 +186,21 @@ def _curvepolygon_text_representation_(self): # noqa ) @tatsumasu() - def _polygon_text_representation_(self): # noqa + def _polygon_text_representation_(self): self._token("POLYGON") with self._optional(): self._z_m_() self._polygon_text_body_() @tatsumasu() - def _triangle_text_representation_(self): # noqa + def _triangle_text_representation_(self): self._token("TRIANGLE") with self._optional(): self._z_m_() self._triangle_text_body_() @tatsumasu() - def _collection_text_representation_(self): # noqa + def _collection_text_representation_(self): with self._choice(): with self._option(): self._multipoint_text_representation_() @@ -193,14 +225,14 @@ def _collection_text_representation_(self): # noqa ) @tatsumasu() - def _multipoint_text_representation_(self): # noqa + def _multipoint_text_representation_(self): self._token("MULTIPOINT") with self._optional(): self._z_m_() self._multipoint_text_() @tatsumasu() - def _multicurve_text_representation_(self): # noqa + def _multicurve_text_representation_(self): with self._choice(): with self._option(): self._token("MULTICURVE") @@ -216,14 +248,14 @@ def _multicurve_text_representation_(self): # noqa ) @tatsumasu() - def _multilinestring_text_representation_(self): # noqa + def _multilinestring_text_representation_(self): self._token("MULTILINESTRING") with self._optional(): self._z_m_() self._multilinestring_text_() @tatsumasu() - def _multisurface_text_representation_(self): # noqa + def _multisurface_text_representation_(self): with self._choice(): with self._option(): self._token("MULTISURFACE") @@ -246,51 +278,51 @@ def _multisurface_text_representation_(self): # noqa ) @tatsumasu() - def _multipolygon_text_representation_(self): # noqa + def _multipolygon_text_representation_(self): self._token("MULTIPOLYGON") with self._optional(): self._z_m_() self._multipolygon_text_() @tatsumasu() - def _polyhedralsurface_text_representation_(self): # noqa + def _polyhedralsurface_text_representation_(self): self._token("POLYHEDRALSURFACE") with self._optional(): self._z_m_() self._polyhedralsurface_text_() @tatsumasu() - def _tin_text_representation_(self): # noqa + def _tin_text_representation_(self): self._token("TIN") with self._optional(): self._z_m_() self._tin_text_() @tatsumasu() - def _geometrycollection_text_representation_(self): # noqa + def _geometrycollection_text_representation_(self): self._token("GEOMETRYCOLLECTION") with self._optional(): self._z_m_() self._geometrycollection_text_() @tatsumasu() - def _linestring_text_body_(self): # noqa + def _linestring_text_body_(self): self._linestring_text_() @tatsumasu() - def _curvepolygon_text_body_(self): # noqa + def _curvepolygon_text_body_(self): self._curvepolygon_text_() @tatsumasu() - def _polygon_text_body_(self): # noqa + def _polygon_text_body_(self): self._polygon_text_() @tatsumasu() - def _triangle_text_body_(self): # noqa + def _triangle_text_body_(self): self._triangle_text_() @tatsumasu() - def _point_text_(self): # noqa + def _point_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -298,10 +330,10 @@ def _point_text_(self): # noqa self._left_paren_() self._point_() self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _point_(self): # noqa + def _point_(self): self._x_() self._y_() with self._optional(): @@ -310,23 +342,23 @@ def _point_(self): # noqa self._m_() @tatsumasu() - def _x_(self): # noqa + def _x_(self): self._number_() @tatsumasu() - def _y_(self): # noqa + def _y_(self): self._number_() @tatsumasu() - def _z_(self): # noqa + def _z_(self): self._number_() @tatsumasu() - def _m_(self): # noqa + def _m_(self): self._number_() @tatsumasu() - def _linestring_text_(self): # noqa + def _linestring_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -334,16 +366,16 @@ def _linestring_text_(self): # noqa self._left_paren_() self._point_() - def block1(): + def block0(): self._comma_() self._point_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _circularstring_text_(self): # noqa + def _circularstring_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -351,16 +383,16 @@ def _circularstring_text_(self): # noqa self._left_paren_() self._point_() - def block1(): + def block0(): self._comma_() self._point_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _compoundcurve_text_(self): # noqa + def _compoundcurve_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -368,16 +400,16 @@ def _compoundcurve_text_(self): # noqa self._left_paren_() self._single_curve_text_() - def block1(): + def block0(): self._comma_() self._single_curve_text_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _single_curve_text_(self): # noqa + def _single_curve_text_(self): with self._choice(): with self._option(): self._linestring_text_body_() @@ -392,7 +424,7 @@ def _single_curve_text_(self): # noqa ) @tatsumasu() - def _curve_text_(self): # noqa + def _curve_text_(self): with self._choice(): with self._option(): self._linestring_text_body_() @@ -410,7 +442,7 @@ def _curve_text_(self): # noqa ) @tatsumasu() - def _ring_text_(self): # noqa + def _ring_text_(self): with self._choice(): with self._option(): self._linestring_text_body_() @@ -428,7 +460,7 @@ def _ring_text_(self): # noqa ) @tatsumasu() - def _surface_text_(self): # noqa + def _surface_text_(self): with self._choice(): with self._option(): self._token("CURVEPOLYGON") @@ -442,7 +474,7 @@ def _surface_text_(self): # noqa ) @tatsumasu() - def _curvepolygon_text_(self): # noqa + def _curvepolygon_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -450,16 +482,16 @@ def _curvepolygon_text_(self): # noqa self._left_paren_() self._ring_text_() - def block1(): + def block0(): self._comma_() self._ring_text_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _polygon_text_(self): # noqa + def _polygon_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -467,16 +499,16 @@ def _polygon_text_(self): # noqa self._left_paren_() self._linestring_text_() - def block1(): + def block0(): self._comma_() self._linestring_text_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _triangle_text_(self): # noqa + def _triangle_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -484,10 +516,10 @@ def _triangle_text_(self): # noqa self._left_paren_() self._linestring_text_() self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _multipoint_text_(self): # noqa + def _multipoint_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -495,16 +527,16 @@ def _multipoint_text_(self): # noqa self._left_paren_() self._point_text_() - def block1(): + def block0(): self._comma_() self._point_text_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _multicurve_text_(self): # noqa + def _multicurve_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -512,16 +544,16 @@ def _multicurve_text_(self): # noqa self._left_paren_() self._curve_text_() - def block1(): + def block0(): self._comma_() self._curve_text_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _multilinestring_text_(self): # noqa + def _multilinestring_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -529,16 +561,16 @@ def _multilinestring_text_(self): # noqa self._left_paren_() self._linestring_text_body_() - def block1(): + def block0(): self._comma_() self._linestring_text_body_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _multisurface_text_(self): # noqa + def _multisurface_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -546,16 +578,16 @@ def _multisurface_text_(self): # noqa self._left_paren_() self._surface_text_() - def block1(): + def block0(): self._comma_() self._surface_text_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _multipolygon_text_(self): # noqa + def _multipolygon_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -563,16 +595,16 @@ def _multipolygon_text_(self): # noqa self._left_paren_() self._polygon_text_body_() - def block1(): + def block0(): self._comma_() self._polygon_text_body_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _polyhedralsurface_text_(self): # noqa + def _polyhedralsurface_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -580,16 +612,16 @@ def _polyhedralsurface_text_(self): # noqa self._left_paren_() self._polygon_text_body_() - def block1(): + def block0(): self._comma_() self._polygon_text_body_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _tin_text_(self): # noqa + def _tin_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -597,16 +629,16 @@ def _tin_text_(self): # noqa self._left_paren_() self._triangle_text_body_() - def block1(): + def block0(): self._comma_() self._triangle_text_body_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _geometrycollection_text_(self): # noqa + def _geometrycollection_text_(self): with self._choice(): with self._option(): self._empty_set_() @@ -614,20 +646,20 @@ def _geometrycollection_text_(self): # noqa self._left_paren_() self._wkt_representation_() - def block1(): + def block0(): self._comma_() self._wkt_representation_() - self._closure(block1) + self._closure(block0) self._right_paren_() - self._error("expecting one of: " "'(' 'EMPTY' ") + self._error("expecting one of: '(' 'EMPTY' ") @tatsumasu() - def _empty_set_(self): # noqa + def _empty_set_(self): self._token("EMPTY") @tatsumasu() - def _z_m_(self): # noqa + def _z_m_(self): with self._choice(): with self._option(): self._token("ZM") @@ -635,199 +667,40 @@ def _z_m_(self): # noqa self._token("Z") with self._option(): self._token("M") - self._error("expecting one of: " "'M' 'Z' 'ZM'") + self._error("expecting one of: 'M' 'Z' 'ZM'") @tatsumasu() - def _left_paren_(self): # noqa + def _left_paren_(self): self._token("(") @tatsumasu() - def _right_paren_(self): # noqa + def _right_paren_(self): self._token(")") @tatsumasu() - def _comma_(self): # noqa + def _comma_(self): self._token(",") @tatsumasu() - def _number_(self): # noqa + def _number_(self): self._pattern("[+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][+-]?[0-9]+)?") -class Semantics: - def wkt_representation(self, ast): # noqa - return ast - - def point_text_representation(self, ast): # noqa - return ast - - def curve_text_representation(self, ast): # noqa - return ast - - def linestring_text_representation(self, ast): # noqa - return ast - - def circularstring_text_representation(self, ast): # noqa - return ast - - def compoundcurve_text_representation(self, ast): # noqa - return ast - - def surface_text_representation(self, ast): # noqa - return ast - - def curvepolygon_text_representation(self, ast): # noqa - return ast - - def polygon_text_representation(self, ast): # noqa - return ast - - def triangle_text_representation(self, ast): # noqa - return ast - - def collection_text_representation(self, ast): # noqa - return ast - - def multipoint_text_representation(self, ast): # noqa - return ast - - def multicurve_text_representation(self, ast): # noqa - return ast - - def multilinestring_text_representation(self, ast): # noqa - return ast - - def multisurface_text_representation(self, ast): # noqa - return ast - - def multipolygon_text_representation(self, ast): # noqa - return ast - - def polyhedralsurface_text_representation(self, ast): # noqa - return ast - - def tin_text_representation(self, ast): # noqa - return ast - - def geometrycollection_text_representation(self, ast): # noqa - return ast - - def linestring_text_body(self, ast): # noqa - return ast - - def curvepolygon_text_body(self, ast): # noqa - return ast - - def polygon_text_body(self, ast): # noqa - return ast - - def triangle_text_body(self, ast): # noqa - return ast - - def point_text(self, ast): # noqa - return ast - - def point(self, ast): # noqa - return ast - - def x(self, ast): # noqa - return ast - - def y(self, ast): # noqa - return ast - - def z(self, ast): # noqa - return ast - - def m(self, ast): # noqa - return ast - - def linestring_text(self, ast): # noqa - return ast - - def circularstring_text(self, ast): # noqa - return ast - - def compoundcurve_text(self, ast): # noqa - return ast - - def single_curve_text(self, ast): # noqa - return ast - - def curve_text(self, ast): # noqa - return ast - - def ring_text(self, ast): # noqa - return ast - - def surface_text(self, ast): # noqa - return ast - - def curvepolygon_text(self, ast): # noqa - return ast - - def polygon_text(self, ast): # noqa - return ast - - def triangle_text(self, ast): # noqa - return ast - - def multipoint_text(self, ast): # noqa - return ast - - def multicurve_text(self, ast): # noqa - return ast - - def multilinestring_text(self, ast): # noqa - return ast - - def multisurface_text(self, ast): # noqa - return ast - - def multipolygon_text(self, ast): # noqa - return ast - - def polyhedralsurface_text(self, ast): # noqa - return ast - - def tin_text(self, ast): # noqa - return ast - - def geometrycollection_text(self, ast): # noqa - return ast - - def empty_set(self, ast): # noqa - return ast - - def z_m(self, ast): # noqa - return ast - - def left_paren(self, ast): # noqa - return ast - - def right_paren(self, ast): # noqa - return ast - - def comma(self, ast): # noqa - return ast - - def number(self, ast): # noqa - return ast - - def main(filename, **kwargs): if not filename or filename == "-": text = sys.stdin.read() else: - with open(filename) as f: - text = f.read() + text = Path(filename).read_text() parser = Parser() - return parser.parse(text, filename=filename, **kwargs) + return parser.parse( + text, + filename=filename, + **kwargs, + ) if __name__ == "__main__": import json - from tatsu.util import asjson ast = generic_main(main, Parser, name="")