Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mappyfile.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Name>mappyfile</Name>
<RootNamespace>mappyfile</RootNamespace>
<InterpreterId>MSBuild|mappyfile|$(MSBuildProjectFullPath)</InterpreterId>
<StartupFile>tests\test_utils.py</StartupFile>
<StartupFile>tests\test_snippets.py</StartupFile>
<LaunchProvider>Standard Python launcher</LaunchProvider>
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
<Environment>PATH=C:\MapServer\bin;%PATH%
Expand Down Expand Up @@ -208,6 +208,7 @@ PROJ_LIB=C:\MapServer\bin\proj\SHARE
<Content Include="MANIFEST.in" />
<Content Include="mappyfile\mapfile.lark" />
<Content Include="mappyfile\py.typed" />
<Content Include="mappyfile\schemas\identify.json" />
<Content Include="mappyfile\schemas\plugins.json" />
<Content Include="mappyfile\schemas\maps.json" />
<Content Include="mappyfile\schemas\expression.json">
Expand Down
5 changes: 4 additions & 1 deletion mappyfile/mapfile.lark
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ composite: composite_type composite_body _END
| connectionoptions

composite_body: _composite_item*
_composite_item: (composite|attr|points|projection|pattern|values|config)
_composite_item: (composite|attr|points|projection|pattern|values|config|classauto)

!projection: "PROJECTION"i (string*|AUTO) _END
!config: "CONFIG"i (string | UNQUOTED_STRING) (string | UNQUOTED_STRING)
Expand Down Expand Up @@ -78,6 +78,7 @@ string_pair: (string|UNQUOTED_STRING) (string|UNQUOTED_STRING)

attr_bind_pair: attr_bind attr_bind
attr_mixed_pair: attr_bind (int|float) | (int|float) attr_bind
classauto: CLASSAUTO
float: SIGNED_FLOAT
float_pair: float float
path: PATH
Expand Down Expand Up @@ -124,6 +125,7 @@ func_params: atom ("," atom)*
| "COMPOSITE"i
| "FEATURE"i
| "GRID"i
| "IDENTIFY"i
| "JOIN"i
| "LABEL"i
| "LAYER"i
Expand All @@ -139,6 +141,7 @@ func_params: atom ("," atom)*
| "WEB"i
| "SYMBOL"i

CLASSAUTO: "CLASSAUTO"i
AUTO: "AUTO"i
PATH: /([a-z0-9_]*\.*\/|[a-z0-9_]+[.\/])[a-z0-9_\/\.-]+/i

Expand Down
12 changes: 11 additions & 1 deletion mappyfile/pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ def __format_line(
) -> str:
if (aligned_max_indent is None) or (aligned_max_indent == 0):
aligned_max_indent = len(key) + 1
indent = " " * (aligned_max_indent - len(key))
if value == "":
indent = "" # for keywords with no values, do not add a space
else:
indent = " " * (aligned_max_indent - len(key))

tmpl = "{spacer}{key}{indent}{value}"
d = {"spacer": spacer, "key": key, "value": value, "indent": indent}
return tmpl.format(**d)
Expand Down Expand Up @@ -399,6 +403,12 @@ def format_value(self, attr: str, attr_props, value: Any) -> Any:

return value

if "type" in attr_props and attr_props["type"] == "null":
# for keywords without a value return an empty string
# currently only CLASSAUTO is the only keyword without a value
assert attr.lower() == "classauto"
return ""

if (
"type" in attr_props and attr_props["type"] == "string"
): # and "enum" not in attr_props
Expand Down
23 changes: 23 additions & 0 deletions mappyfile/schemas/identify.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "object",
"additionalProperties": false,
"metadata": {
"minVersion": 8.6
},
"patternProperties": {
"^__[a-z]+__$": true
},
"properties": {
"__type__": {
"const": "identify"
},
"tolerance": {
"type": "number"
},
"toleranceunits": {
"enum": [ "feet", "inches", "kilometers", "meters", "miles", "nauticalmiles", "pixels", "dd" ]
},
"classauto": { "type": "null" }
},
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
6 changes: 6 additions & 0 deletions mappyfile/schemas/layer.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@
"header": {
"type": "string"
},
"identify": {
"$ref": "identify.json",
"metadata": {
"minVersion": 8.6
}
},
"joins": {
"type": "array",
"items": {
Expand Down
3 changes: 3 additions & 0 deletions mappyfile/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
composite
feature
grid
identify
join
label
leader
Expand Down Expand Up @@ -111,6 +112,7 @@
graticule
group
header
identify
image
imagecolor
imagetype
Expand Down Expand Up @@ -256,6 +258,7 @@
cluster
connectionoptions
grid
identify
leader
legend
metadata
Expand Down
9 changes: 9 additions & 0 deletions mappyfile/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,15 @@ def list(self, t):
v.value = "{%s}" % list_values
return v

def classauto(self, t):
key_token = t[0]
key_name = self.key_name(key_token)
pd = self.create_position_dict(key_token, None)
d: dict = OrderedDict()
d["__position__"] = pd
d[key_name] = None
return d


class CommentsTransformer(Transformer_InPlace):
"""
Expand Down
Loading