diff --git a/frictionless/fields/string.py b/frictionless/fields/string.py index fefe92324b..3fb4eeec5e 100644 --- a/frictionless/fields/string.py +++ b/frictionless/fields/string.py @@ -73,13 +73,13 @@ def value_reader(cell: Any): # WKT elif self.format == "wkt": - parser = platform.wkt.WktParser() + parser = platform.wkt.Parser() def value_reader(cell: Any): if not isinstance(cell, str): return None try: - parser.parse(cell, rule_name="wkt_representation") + parser.parse(cell) except Exception: return None return cell diff --git a/frictionless/platform.py b/frictionless/platform.py index 24420809f6..f10302db40 100644 --- a/frictionless/platform.py +++ b/frictionless/platform.py @@ -13,9 +13,6 @@ def inner(*args: Any, **kwargs: Any): try: return func(*args, **kwargs) except Exception: - if name == "wkt" and sys.version_info >= (3, 10): - note = "WKT is not supported in Python3.10+ (grako is unmaintained)" - raise platform.frictionless.FrictionlessException(note) module = import_module("frictionless.exception") note = f'Please install "frictionless[{name}]"' raise module.FrictionlessException(note) diff --git a/frictionless/vendors/wkt/__init__.py b/frictionless/vendors/wkt/__init__.py index 2c3b819af2..2a3855a18a 100644 --- a/frictionless/vendors/wkt/__init__.py +++ b/frictionless/vendors/wkt/__init__.py @@ -1 +1 @@ -from .parser import WktParser +from .parser import Parser diff --git a/frictionless/vendors/wkt/parser.py b/frictionless/vendors/wkt/parser.py index 246e0d340e..29f30c578f 100644 --- a/frictionless/vendors/wkt/parser.py +++ b/frictionless/vendors/wkt/parser.py @@ -1,82 +1,63 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # CAVEAT UTILITOR # -# This file was automatically generated by Grako. +# This file was automatically generated by TatSu. # -# https://pypi.python.org/pypi/grako/ +# https://pypi.python.org/pypi/tatsu/ # # Any changes you make to it will be overwritten the next time # the file is generated. +from __future__ import annotations -from __future__ import absolute_import, division, print_function, unicode_literals - -from grako.buffering import Buffer -from grako.parsing import Parser, graken -from grako.util import RE_FLAGS, generic_main, re # noqa - -KEYWORDS = {} - - -class WktBuffer(Buffer): - def __init__( - self, - text, - whitespace=None, - nameguard=None, - comments_re=None, - eol_comments_re=None, - ignorecase=None, - namechars="", - **kwargs, - ): - super(WktBuffer, self).__init__( - text, - whitespace=whitespace, - nameguard=nameguard, - comments_re=comments_re, - eol_comments_re=eol_comments_re, - ignorecase=ignorecase, # type: ignore - namechars=namechars, - **kwargs, - ) +import sys + +from tatsu.buffering import Buffer +from tatsu.infos import ParserConfig +from tatsu.parsing import Parser, isname, leftrec, nomemo, tatsumasu # noqa +from tatsu.util import generic_main, re # noqa +KEYWORDS = {} # type: ignore -class WktParser(Parser): - def __init__( - self, - whitespace=None, - nameguard=None, - comments_re=None, - eol_comments_re=None, - ignorecase=None, - left_recursion=False, - parseinfo=True, - keywords=None, - namechars="", - buffer_class=WktBuffer, - **kwargs, - ): - if keywords is None: - keywords = KEYWORDS - super(WktParser, self).__init__( - whitespace=whitespace, - nameguard=nameguard, - comments_re=comments_re, - eol_comments_re=eol_comments_re, - ignorecase=ignorecase, # type: ignore - left_recursion=left_recursion, - parseinfo=parseinfo, - keywords=keywords, - namechars=namechars, - buffer_class=buffer_class, - **kwargs, + +class Buffer(Buffer): + def __init__(self, text, /, config: ParserConfig = None, **settings): + config = ParserConfig.new( + config, + owner=self, + whitespace=None, + nameguard=None, + comments_re=None, + eol_comments_re=None, + ignorecase=False, + namechars="", + parseinfo=False, + ) + config = config.replace(**settings) + super().__init__(text, config=config) + + +class Parser(Parser): + def __init__(self, /, config: ParserConfig = None, **settings): + config = ParserConfig.new( + config, + owner=self, + whitespace=None, + nameguard=None, + comments_re=None, + eol_comments_re=None, + ignorecase=False, + namechars="", + parseinfo=False, + keywords=KEYWORDS, + start="wkt_representation", ) + config = config.replace(**settings) + super().__init__(config=config) - @graken() - def _wkt_representation_(self): + @tatsumasu() + def _wkt_representation_(self): # noqa with self._choice(): with self._option(): self._point_text_representation_() @@ -86,17 +67,32 @@ def _wkt_representation_(self): self._surface_text_representation_() with self._option(): self._collection_text_representation_() - self._error("no available options") - - @graken() - def _point_text_representation_(self): + self._error( + "expecting one of: " + "'POINT'" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ) + + @tatsumasu() + def _point_text_representation_(self): # noqa self._token("POINT") with self._optional(): self._z_m_() self._point_text_() - @graken() - def _curve_text_representation_(self): + @tatsumasu() + def _curve_text_representation_(self): # noqa with self._choice(): with self._option(): self._linestring_text_representation_() @@ -104,35 +100,42 @@ def _curve_text_representation_(self): self._circularstring_text_representation_() with self._option(): self._compoundcurve_text_representation_() - self._error("no available options") - - @graken() - def _linestring_text_representation_(self): + self._error( + "expecting one of: " + "'CIRCULARSTRING' 'COMPOUNDCURVE'" + "'LINESTRING'" + "" + "" + "" + ) + + @tatsumasu() + def _linestring_text_representation_(self): # noqa self._token("LINESTRING") with self._optional(): self._z_m_() self._linestring_text_body_() - @graken() - def _circularstring_text_representation_(self): + @tatsumasu() + def _circularstring_text_representation_(self): # noqa self._token("CIRCULARSTRING") with self._optional(): self._z_m_() self._circularstring_text_() - @graken() - def _compoundcurve_text_representation_(self): + @tatsumasu() + def _compoundcurve_text_representation_(self): # noqa self._token("COMPOUNDCURVE") with self._optional(): self._z_m_() self._compoundcurve_text_() - @graken() - def _surface_text_representation_(self): + @tatsumasu() + def _surface_text_representation_(self): # noqa self._curvepolygon_text_representation_() - @graken() - def _curvepolygon_text_representation_(self): + @tatsumasu() + def _curvepolygon_text_representation_(self): # noqa with self._choice(): with self._option(): self._token("CURVEPOLYGON") @@ -143,24 +146,29 @@ def _curvepolygon_text_representation_(self): self._polygon_text_representation_() with self._option(): self._triangle_text_representation_() - self._error("no available options") - - @graken() - def _polygon_text_representation_(self): + self._error( + "expecting one of: " + "'CURVEPOLYGON' 'POLYGON' 'TRIANGLE'" + "" + "" + ) + + @tatsumasu() + def _polygon_text_representation_(self): # noqa self._token("POLYGON") with self._optional(): self._z_m_() self._polygon_text_body_() - @graken() - def _triangle_text_representation_(self): + @tatsumasu() + def _triangle_text_representation_(self): # noqa self._token("TRIANGLE") with self._optional(): self._z_m_() self._triangle_text_body_() - @graken() - def _collection_text_representation_(self): + @tatsumasu() + def _collection_text_representation_(self): # noqa with self._choice(): with self._option(): self._multipoint_text_representation_() @@ -170,17 +178,29 @@ def _collection_text_representation_(self): self._multisurface_text_representation_() with self._option(): self._geometrycollection_text_representation_() - self._error("no available options") - - @graken() - def _multipoint_text_representation_(self): + self._error( + "expecting one of: " + "'GEOMETRYCOLLECTION' 'MULTICURVE'" + "'MULTIPOINT' 'MULTISURFACE'" + "" + "" + "" + "" + "" + "" + "" + "" + ) + + @tatsumasu() + def _multipoint_text_representation_(self): # noqa self._token("MULTIPOINT") with self._optional(): self._z_m_() self._multipoint_text_() - @graken() - def _multicurve_text_representation_(self): + @tatsumasu() + def _multicurve_text_representation_(self): # noqa with self._choice(): with self._option(): self._token("MULTICURVE") @@ -189,17 +209,21 @@ def _multicurve_text_representation_(self): self._multicurve_text_() with self._option(): self._multilinestring_text_representation_() - self._error("no available options") - - @graken() - def _multilinestring_text_representation_(self): + self._error( + "expecting one of: " + "'MULTICURVE' 'MULTILINESTRING'" + "" + ) + + @tatsumasu() + def _multilinestring_text_representation_(self): # noqa self._token("MULTILINESTRING") with self._optional(): self._z_m_() self._multilinestring_text_() - @graken() - def _multisurface_text_representation_(self): + @tatsumasu() + def _multisurface_text_representation_(self): # noqa with self._choice(): with self._option(): self._token("MULTISURFACE") @@ -212,54 +236,61 @@ def _multisurface_text_representation_(self): self._polyhedralsurface_text_representation_() with self._option(): self._tin_text_representation_() - self._error("no available options") - - @graken() - def _multipolygon_text_representation_(self): + self._error( + "expecting one of: " + "'MULTIPOLYGON' 'MULTISURFACE'" + "'POLYHEDRALSURFACE' 'TIN'" + "" + "" + "" + ) + + @tatsumasu() + def _multipolygon_text_representation_(self): # noqa self._token("MULTIPOLYGON") with self._optional(): self._z_m_() self._multipolygon_text_() - @graken() - def _polyhedralsurface_text_representation_(self): + @tatsumasu() + def _polyhedralsurface_text_representation_(self): # noqa self._token("POLYHEDRALSURFACE") with self._optional(): self._z_m_() self._polyhedralsurface_text_() - @graken() - def _tin_text_representation_(self): + @tatsumasu() + def _tin_text_representation_(self): # noqa self._token("TIN") with self._optional(): self._z_m_() self._tin_text_() - @graken() - def _geometrycollection_text_representation_(self): + @tatsumasu() + def _geometrycollection_text_representation_(self): # noqa self._token("GEOMETRYCOLLECTION") with self._optional(): self._z_m_() self._geometrycollection_text_() - @graken() - def _linestring_text_body_(self): + @tatsumasu() + def _linestring_text_body_(self): # noqa self._linestring_text_() - @graken() - def _curvepolygon_text_body_(self): + @tatsumasu() + def _curvepolygon_text_body_(self): # noqa self._curvepolygon_text_() - @graken() - def _polygon_text_body_(self): + @tatsumasu() + def _polygon_text_body_(self): # noqa self._polygon_text_() - @graken() - def _triangle_text_body_(self): + @tatsumasu() + def _triangle_text_body_(self): # noqa self._triangle_text_() - @graken() - def _point_text_(self): + @tatsumasu() + def _point_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -267,10 +298,10 @@ def _point_text_(self): self._left_paren_() self._point_() self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _point_(self): + @tatsumasu() + def _point_(self): # noqa self._x_() self._y_() with self._optional(): @@ -278,24 +309,24 @@ def _point_(self): with self._optional(): self._m_() - @graken() - def _x_(self): + @tatsumasu() + def _x_(self): # noqa self._number_() - @graken() - def _y_(self): + @tatsumasu() + def _y_(self): # noqa self._number_() - @graken() - def _z_(self): + @tatsumasu() + def _z_(self): # noqa self._number_() - @graken() - def _m_(self): + @tatsumasu() + def _m_(self): # noqa self._number_() - @graken() - def _linestring_text_(self): + @tatsumasu() + def _linestring_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -303,16 +334,16 @@ def _linestring_text_(self): self._left_paren_() self._point_() - def block0(): + def block1(): self._comma_() self._point_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _circularstring_text_(self): + @tatsumasu() + def _circularstring_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -320,16 +351,16 @@ def _circularstring_text_(self): self._left_paren_() self._point_() - def block0(): + def block1(): self._comma_() self._point_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _compoundcurve_text_(self): + @tatsumasu() + def _compoundcurve_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -337,25 +368,31 @@ def _compoundcurve_text_(self): self._left_paren_() self._single_curve_text_() - def block0(): + def block1(): self._comma_() self._single_curve_text_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _single_curve_text_(self): + @tatsumasu() + def _single_curve_text_(self): # noqa with self._choice(): with self._option(): self._linestring_text_body_() with self._option(): self._circularstring_text_representation_() - self._error("no available options") - - @graken() - def _curve_text_(self): + self._error( + "expecting one of: " + "'CIRCULARSTRING'" + "" + " " + " " + ) + + @tatsumasu() + def _curve_text_(self): # noqa with self._choice(): with self._option(): self._linestring_text_body_() @@ -363,10 +400,17 @@ def _curve_text_(self): self._circularstring_text_representation_() with self._option(): self._compoundcurve_text_representation_() - self._error("no available options") - - @graken() - def _ring_text_(self): + self._error( + "expecting one of: " + "'CIRCULARSTRING' 'COMPOUNDCURVE'" + "" + "" + " " + " " + ) + + @tatsumasu() + def _ring_text_(self): # noqa with self._choice(): with self._option(): self._linestring_text_body_() @@ -374,20 +418,31 @@ def _ring_text_(self): self._circularstring_text_representation_() with self._option(): self._compoundcurve_text_representation_() - self._error("no available options") - - @graken() - def _surface_text_(self): + self._error( + "expecting one of: " + "'CIRCULARSTRING' 'COMPOUNDCURVE'" + "" + "" + " " + " " + ) + + @tatsumasu() + def _surface_text_(self): # noqa with self._choice(): with self._option(): self._token("CURVEPOLYGON") self._curvepolygon_text_body_() with self._option(): self._polygon_text_body_() - self._error("no available options") - - @graken() - def _curvepolygon_text_(self): + self._error( + "expecting one of: " + "'CURVEPOLYGON' " + " " + ) + + @tatsumasu() + def _curvepolygon_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -395,16 +450,16 @@ def _curvepolygon_text_(self): self._left_paren_() self._ring_text_() - def block0(): + def block1(): self._comma_() self._ring_text_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _polygon_text_(self): + @tatsumasu() + def _polygon_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -412,16 +467,16 @@ def _polygon_text_(self): self._left_paren_() self._linestring_text_() - def block0(): + def block1(): self._comma_() self._linestring_text_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _triangle_text_(self): + @tatsumasu() + def _triangle_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -429,10 +484,10 @@ def _triangle_text_(self): self._left_paren_() self._linestring_text_() self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _multipoint_text_(self): + @tatsumasu() + def _multipoint_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -440,16 +495,16 @@ def _multipoint_text_(self): self._left_paren_() self._point_text_() - def block0(): + def block1(): self._comma_() self._point_text_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _multicurve_text_(self): + @tatsumasu() + def _multicurve_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -457,16 +512,16 @@ def _multicurve_text_(self): self._left_paren_() self._curve_text_() - def block0(): + def block1(): self._comma_() self._curve_text_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _multilinestring_text_(self): + @tatsumasu() + def _multilinestring_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -474,16 +529,16 @@ def _multilinestring_text_(self): self._left_paren_() self._linestring_text_body_() - def block0(): + def block1(): self._comma_() self._linestring_text_body_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _multisurface_text_(self): + @tatsumasu() + def _multisurface_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -491,16 +546,16 @@ def _multisurface_text_(self): self._left_paren_() self._surface_text_() - def block0(): + def block1(): self._comma_() self._surface_text_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _multipolygon_text_(self): + @tatsumasu() + def _multipolygon_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -508,16 +563,16 @@ def _multipolygon_text_(self): self._left_paren_() self._polygon_text_body_() - def block0(): + def block1(): self._comma_() self._polygon_text_body_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _polyhedralsurface_text_(self): + @tatsumasu() + def _polyhedralsurface_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -525,16 +580,16 @@ def _polyhedralsurface_text_(self): self._left_paren_() self._polygon_text_body_() - def block0(): + def block1(): self._comma_() self._polygon_text_body_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _tin_text_(self): + @tatsumasu() + def _tin_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -542,16 +597,16 @@ def _tin_text_(self): self._left_paren_() self._triangle_text_body_() - def block0(): + def block1(): self._comma_() self._triangle_text_body_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _geometrycollection_text_(self): + @tatsumasu() + def _geometrycollection_text_(self): # noqa with self._choice(): with self._option(): self._empty_set_() @@ -559,20 +614,20 @@ def _geometrycollection_text_(self): self._left_paren_() self._wkt_representation_() - def block0(): + def block1(): self._comma_() self._wkt_representation_() - self._closure(block0) + self._closure(block1) self._right_paren_() - self._error("no available options") + self._error("expecting one of: " "'(' 'EMPTY' ") - @graken() - def _empty_set_(self): + @tatsumasu() + def _empty_set_(self): # noqa self._token("EMPTY") - @graken() - def _z_m_(self): + @tatsumasu() + def _z_m_(self): # noqa with self._choice(): with self._option(): self._token("ZM") @@ -580,202 +635,201 @@ def _z_m_(self): 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'") - @graken() - def _left_paren_(self): + @tatsumasu() + def _left_paren_(self): # noqa self._token("(") - @graken() - def _right_paren_(self): + @tatsumasu() + def _right_paren_(self): # noqa self._token(")") - @graken() - def _comma_(self): + @tatsumasu() + def _comma_(self): # noqa self._token(",") - @graken() - def _number_(self): - self._pattern(r"[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)([eE][+-]?[0-9]+)?") + @tatsumasu() + def _number_(self): # noqa + self._pattern("[+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][+-]?[0-9]+)?") -class WktSemantics(object): - def wkt_representation(self, ast): +class Semantics: + def wkt_representation(self, ast): # noqa return ast - def point_text_representation(self, ast): + def point_text_representation(self, ast): # noqa return ast - def curve_text_representation(self, ast): + def curve_text_representation(self, ast): # noqa return ast - def linestring_text_representation(self, ast): + def linestring_text_representation(self, ast): # noqa return ast - def circularstring_text_representation(self, ast): + def circularstring_text_representation(self, ast): # noqa return ast - def compoundcurve_text_representation(self, ast): + def compoundcurve_text_representation(self, ast): # noqa return ast - def surface_text_representation(self, ast): + def surface_text_representation(self, ast): # noqa return ast - def curvepolygon_text_representation(self, ast): + def curvepolygon_text_representation(self, ast): # noqa return ast - def polygon_text_representation(self, ast): + def polygon_text_representation(self, ast): # noqa return ast - def triangle_text_representation(self, ast): + def triangle_text_representation(self, ast): # noqa return ast - def collection_text_representation(self, ast): + def collection_text_representation(self, ast): # noqa return ast - def multipoint_text_representation(self, ast): + def multipoint_text_representation(self, ast): # noqa return ast - def multicurve_text_representation(self, ast): + def multicurve_text_representation(self, ast): # noqa return ast - def multilinestring_text_representation(self, ast): + def multilinestring_text_representation(self, ast): # noqa return ast - def multisurface_text_representation(self, ast): + def multisurface_text_representation(self, ast): # noqa return ast - def multipolygon_text_representation(self, ast): + def multipolygon_text_representation(self, ast): # noqa return ast - def polyhedralsurface_text_representation(self, ast): + def polyhedralsurface_text_representation(self, ast): # noqa return ast - def tin_text_representation(self, ast): + def tin_text_representation(self, ast): # noqa return ast - def geometrycollection_text_representation(self, ast): + def geometrycollection_text_representation(self, ast): # noqa return ast - def linestring_text_body(self, ast): + def linestring_text_body(self, ast): # noqa return ast - def curvepolygon_text_body(self, ast): + def curvepolygon_text_body(self, ast): # noqa return ast - def polygon_text_body(self, ast): + def polygon_text_body(self, ast): # noqa return ast - def triangle_text_body(self, ast): + def triangle_text_body(self, ast): # noqa return ast - def point_text(self, ast): + def point_text(self, ast): # noqa return ast - def point(self, ast): + def point(self, ast): # noqa return ast - def x(self, ast): + def x(self, ast): # noqa return ast - def y(self, ast): + def y(self, ast): # noqa return ast - def z(self, ast): + def z(self, ast): # noqa return ast - def m(self, ast): + def m(self, ast): # noqa return ast - def linestring_text(self, ast): + def linestring_text(self, ast): # noqa return ast - def circularstring_text(self, ast): + def circularstring_text(self, ast): # noqa return ast - def compoundcurve_text(self, ast): + def compoundcurve_text(self, ast): # noqa return ast - def single_curve_text(self, ast): + def single_curve_text(self, ast): # noqa return ast - def curve_text(self, ast): + def curve_text(self, ast): # noqa return ast - def ring_text(self, ast): + def ring_text(self, ast): # noqa return ast - def surface_text(self, ast): + def surface_text(self, ast): # noqa return ast - def curvepolygon_text(self, ast): + def curvepolygon_text(self, ast): # noqa return ast - def polygon_text(self, ast): + def polygon_text(self, ast): # noqa return ast - def triangle_text(self, ast): + def triangle_text(self, ast): # noqa return ast - def multipoint_text(self, ast): + def multipoint_text(self, ast): # noqa return ast - def multicurve_text(self, ast): + def multicurve_text(self, ast): # noqa return ast - def multilinestring_text(self, ast): + def multilinestring_text(self, ast): # noqa return ast - def multisurface_text(self, ast): + def multisurface_text(self, ast): # noqa return ast - def multipolygon_text(self, ast): + def multipolygon_text(self, ast): # noqa return ast - def polyhedralsurface_text(self, ast): + def polyhedralsurface_text(self, ast): # noqa return ast - def tin_text(self, ast): + def tin_text(self, ast): # noqa return ast - def geometrycollection_text(self, ast): + def geometrycollection_text(self, ast): # noqa return ast - def empty_set(self, ast): + def empty_set(self, ast): # noqa return ast - def z_m(self, ast): + def z_m(self, ast): # noqa return ast - def left_paren(self, ast): + def left_paren(self, ast): # noqa return ast - def right_paren(self, ast): + def right_paren(self, ast): # noqa return ast - def comma(self, ast): + def comma(self, ast): # noqa return ast - def number(self, ast): + def number(self, ast): # noqa return ast -def main(filename, startrule, **kwargs): - with open(filename) as f: - text = f.read() - parser = WktParser() - return parser.parse(text, startrule, filename=filename, **kwargs) +def main(filename, **kwargs): + if not filename or filename == "-": + text = sys.stdin.read() + else: + with open(filename) as f: + text = f.read() + parser = Parser() + return parser.parse(text, filename=filename, **kwargs) if __name__ == "__main__": import json - from grako.util import asjson + from tatsu.util import asjson - ast = generic_main(main, WktParser, name="Wkt") - print("AST:") - print(ast) - print() - print("JSON:") - print(json.dumps(asjson(ast), indent=2)) - print() + ast = generic_main(main, Parser, name="") + data = asjson(ast) + print(json.dumps(data, indent=2)) diff --git a/pyproject.toml b/pyproject.toml index b60b816850..1d0a510bf7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,7 +99,7 @@ postgresql = ["sqlalchemy>=1.4", "psycopg>=3.0", "psycopg2>=2.9"] spss = ["savReaderWriter>=3.0"] sql = ["sqlalchemy>=1.4"] visidata = ["visidata>=2.10"] -wkt = ["grako>=3.99"] +wkt = ["TatSu>=5.8.3"] zenodo = ["pyzenodo3>=1.0"] [project.scripts] diff --git a/tests/fields/test_string.py b/tests/fields/test_string.py index 2ebaadc0a4..24a83794f4 100644 --- a/tests/fields/test_string.py +++ b/tests/fields/test_string.py @@ -1,5 +1,3 @@ -import sys - import pytest from frictionless import Field @@ -35,7 +33,6 @@ def test_string_read_cell(format, source, target): assert cell == target -@pytest.mark.skipif(sys.version_info >= (3, 10), reason="Doesn't work in Python3.10+") @pytest.mark.parametrize( "format, source, target", [ @@ -46,6 +43,49 @@ def test_string_read_cell(format, source, target): "POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))", "POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))", ), + ( + "wkt", + "MULTIPOINT ((10 40), (40 30), (20 20), (30 10))", + "MULTIPOINT ((10 40), (40 30), (20 20), (30 10))", + ), + ( + "wkt", + "TRIANGLE((0 0, 1 0, 0.5 1, 0 0))", + "TRIANGLE((0 0, 1 0, 0.5 1, 0 0))", + ), + ( + "wkt", + "MULTILINESTRING ((0 0, 1 1, 2 2), (3 3, 4 4, 5 5))", + "MULTILINESTRING ((0 0, 1 1, 2 2), (3 3, 4 4, 5 5))", + ), + ( + "wkt", + "MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)), ((1 1, 1 2, 2 2, 2 1, 1 1)))", + "MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)), ((1 1, 1 2, 2 2, 2 1, 1 1)))", + ), + ( + "wkt", + "CIRCULARSTRING (-116.4 45.2, -118.0 47.0, -120.0 49.0)", + "CIRCULARSTRING (-116.4 45.2, -118.0 47.0, -120.0 49.0)", + ), + ( + "wkt", + "TIN (((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 1 0,0 0 0)))", + "TIN (((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 1 0,0 0 0)))", + ), + ( + "wkt", + "CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING (0 0,1 1,2 0),(2 0,0 0)))", + "CURVEPOLYGON(COMPOUNDCURVE(CIRCULARSTRING (0 0,1 1,2 0),(2 0,0 0)))", + ), + ( + "wkt", + "POLYHEDRALSURFACE (((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)))", + "POLYHEDRALSURFACE (((0 0 0,0 0 1,0 1 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,1 0 1,0 0 1,0 0 0)),((1 1 0,1 1 1,1 0 1,1 0 0,1 1 0)),((0 1 0,0 1 1,1 1 1,1 1 0,0 1 0)),((0 0 1,1 0 1,1 1 1,0 1 1,0 0 1)))", + ), + ("wkt", "CIRCULARSTRING EMPTY", "CIRCULARSTRING EMPTY"), + ("wkt", "GEOMETRYCOLLECTION EMPTY", "GEOMETRYCOLLECTION EMPTY"), + ("wkt", "POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10)", None), ("wkt", "string", None), ("wkt", "", None), ("wkt", 0, None),