travis-ci / travis-yaml

parses, normalizes, validates and serializes your .travis.yml
http://yaml.travis-ci.org/
MIT License
170 stars 66 forks source link

colon syntax error fase detected? #81

Closed davidak closed 8 years ago

davidak commented 8 years ago
before_install:
  - printf "CPU:"
  - grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:
  - printf "CPU Cores: "
  - grep -c processor /proc/cpuinfo

syntax error: (): found unexpected end of stream while scanning a quoted scalar at line 4 column 25

I think this is not an error since it is quoted.

BanzaiMan commented 8 years ago

You have an unquoted dangling : in grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:.

BanzaiMan commented 8 years ago

Actually, the error is on line 4… There is a trailing space after : that's fooling the parser. Try quoting the entire string:

before_install:
  - printf "CPU:"
  - grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:
  - "printf CPU Cores: "
  - grep -c processor /proc/cpuinfo
BanzaiMan commented 8 years ago

Or drop the space. (This makes the parser pass, but the data structure would be different.

{
  "before_install": [
    "printf \"CPU:\"", 
    {
      "grep model\\ name /proc/cpuinfo | head -1 | cut -f2 -d": null
    }, 
    {
      "printf CPU Cores": null
    }, 
    "grep -c processor /proc/cpuinfo"
  ]
}
BanzaiMan commented 8 years ago

I should note that the second command does not do what you think it does. (See the comment above.)

davidak commented 8 years ago

i noted that myself as there was not the output i wanted. i quoted it.

what you call "fooling the parser" should get fixed since i used the correct syntax.

thanks for the fast answers!

BanzaiMan commented 8 years ago

Not sure how you came to the conclusion that this is valid YAML syntax.

$ pry
[1] pry(main)> require 'yaml'
=> true
[2] pry(main)> yaml = <<-EOF
[2] pry(main)* before_install:
  - printf "CPU:"
  - grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:
  - printf "CPU Cores: "
[2] pry(main)*   - printf "CPU:"nfo[2] pry(main)*   - printf "CPU:"
  - grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:
  - printf "CPU Cores: "
[2] pry(main)*   - grep model\ name /proc/cpuinfo | head -1 | cut -f2 -d:roc/cpuinfo | head -1 | cut -f2 -d:
  - printf "CPU Cores: "
[2] pry(main)*   - printf "CPU Cores: "pry(main)*   - printf "CPU Cores: "
[2] pry(main)*   - grep -c processor /proc/cpuinfo  - grep -c processor /proc/cpuinfo
[2] pry(main)* EOF
=> "before_install:\n  - printf \"CPU:\"\n  - grep model name /proc/cpuinfo | head -1 | cut -f2 -d:\n  - printf \"CPU Cores: \"\n  - grep -c processor /proc/cpuinfo\n"
[3] pry(main)> YAML.load(yaml)
Psych::SyntaxError: (<unknown>): found unexpected end of stream while scanning a quoted scalar at line 4 column 24
from /Users/asari/.rvm/gems/ruby-2.1.5/gems/psych-2.0.8/lib/psych.rb:370:in `parse'

You may also try http://yaml-online-parser.appspot.com/ for validation.

davidak commented 8 years ago

as i understand i can use colons if i quote the string. is it official part of the syntax, that this is only true if there is not a whitespace after it?