Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Need better yaml parser #113

Open
klahnakoski opened this issue Feb 4, 2019 · 2 comments
Open

Need better yaml parser #113

klahnakoski opened this issue Feb 4, 2019 · 2 comments

Comments

@klahnakoski
Copy link
Contributor

YAML is complicated, and space specific, so is prone to typos. The current query parser does not do a good job of portraying what's expected, forcing to me to use other tools to format the file correctly.

eg

from: perf,
select:
    - {value: result.stats.median, aggregate: average}
edges:
    - result.test
    - {value: repo.changeset.id12, allowNulls: false}
where: and:
    -   or:
       - {prefix: {repo.changeset.id: {$eval: rev1}}}
       - {prefix: {repo.changeset.id: {$eval: rev2}}}
    - {in: {repo.branch.name: {$eval: branch}}}
    - {suffix: {result.test: {$eval: subtest}}}
    - {prefix: {result.suite: "raptor-tp6-"}}
format: cube,
limit: 1000

result in

Traceback (most recent call last):
  File "C:\Users\kyle\.IntelliJIdea2018.2\config\plugins\python\helpers\pydev\pydevd.py", line 1664, in <module>
    main()
  File "C:\Users\kyle\.IntelliJIdea2018.2\config\plugins\python\helpers\pydev\pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Users\kyle\.IntelliJIdea2018.2\config\plugins\python\helpers\pydev\pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Users\kyle\.IntelliJIdea2018.2\config\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/kyle/code/active-data-recipes/adr/cli.py", line 225, in <module>
    sys.exit(main())
  File "C:/Users/kyle/code/active-data-recipes/adr/cli.py", line 221, in main
    parsed_args.func(parsed_args, remainder, config, parser, request_type)
  File "C:/Users/kyle/code/active-data-recipes/adr/cli.py", line 67, in request_handler
    data, url = format_request(request, config, remainder, request_type)
  File "C:/Users/kyle/code/active-data-recipes/adr/cli.py", line 27, in format_request
    data = run_recipe(request, remainder, config)
  File "C:\Users\kyle\code\active-data-recipes\adr\recipe.py", line 81, in run_recipe
    recipe_context_def = get_recipe_contexts(recipe, mod)
  File "C:\Users\kyle\code\active-data-recipes\adr\recipe.py", line 43, in get_recipe_contexts
    query_context_def = load_query_context(query_name)
  File "C:\Users\kyle\code\active-data-recipes\adr\query.py", line 108, in load_query_context
    query = yaml.load(fh)
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\__init__.py", line 72, in load
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\constructor.py", line 35, in get_single_data
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\composer.py", line 36, in get_single_node
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\composer.py", line 55, in compose_document
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\composer.py", line 84, in compose_node
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\composer.py", line 127, in compose_mapping_node
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\parser.py", line 98, in check_event
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\parser.py", line 428, in parse_block_mapping_key
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\scanner.py", line 116, in check_token
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\scanner.py", line 223, in fetch_more_tokens
  File "C:\python36\lib\site-packages\pyyaml-4.2b4-py3.6-win-amd64.egg\yaml\scanner.py", line 579, in fetch_value
yaml.scanner.ScannerError: mapping values are not allowed here
  in "C:\Users\kyle\code\active-data-recipes\adr\queries\perf_tp6_compare.query", line 7, column 11
@klahnakoski
Copy link
Contributor Author

This is the good version, I think it was the commas

from: perf
select:
- {value: result.stats.median, aggregate: average}
edges:
- result.test
- {value: repo.changeset.id12, allowNulls: false}
where:
    and:
    -   or:
        - {prefix: {repo.changeset.id: {$eval: rev1}}}
        - {prefix: {repo.changeset.id: {$eval: rev2}}}
    - {in: {repo.branch.name: {$eval: branch}}}
    - {suffix: {result.test: {$eval: subtest}}}
    - {prefix: {result.suite: "raptor-tp6-"}}
format: cube
limit: 1000

@ahal
Copy link
Member

ahal commented Mar 21, 2019

Yeah, there's only really two options, pyyaml and ruamel.yaml. People had previously recommended ruamel because pyyaml looked dead, but it recently got a new owner and seems active again.

Not sure which is better these days.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants