Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
Added bools
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Feb 25, 2010
1 parent 4698d2b commit 0e99409
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Readme.md
Expand Up @@ -11,11 +11,12 @@ fork the project and submit a patch :)

# Currently Supports

* Sequences
* Maps
* Comments
* Sequences (arrays)
* Maps (hashes)
* Nesting
* Primitive scalars (integers, floats, booleans, etc)
* Extended bools (enabled, disabled, yes, no, on, off, true, false)
* Inline sequences ([foo, bar])
* Inline maps ({ foo: bar })

Expand Down
8 changes: 8 additions & 0 deletions lib/yaml.js
Expand Up @@ -15,6 +15,8 @@ var tokens = [
['comment', /^#[^\n]*/],
['indent', /^\n( *)/],
['space', /^ +/],
['true', /^(enabled|true|yes|on)/],
['false', /^(disabled|false|no|off)/],
['string', /^"(.*?)"/],
['float', /^(\d+\.\d+)/],
['int', /^(\d+)/],
Expand Down Expand Up @@ -167,6 +169,8 @@ Parser.prototype.ignoreSpace = function() {
* | string
* | float
* | int
* | true
* | false
*/

Parser.prototype.parse = function() {
Expand All @@ -181,6 +185,10 @@ Parser.prototype.parse = function() {
return parseFloat(this.advanceValue())
case 'int':
return parseInt(this.advanceValue())
case 'true':
return true
case 'false':
return false
}
}

Expand Down
38 changes: 38 additions & 0 deletions spec/spec.core.js
Expand Up @@ -50,6 +50,44 @@ describe 'yaml'
end
end

describe 'bools'
describe 'true'
it 'true'
yaml.eval('true').should.equal true
end

it 'yes'
yaml.eval('yes').should.equal true
end

it 'on'
yaml.eval('on').should.equal true
end

it 'enabled'
yaml.eval('enabled').should.equal true
end
end

describe 'false'
it 'false'
yaml.eval('false').should.equal false
end

it 'no'
yaml.eval('no').should.equal false
end

it 'off'
yaml.eval('off').should.equal false
end

it 'disabled'
yaml.eval('disabled').should.equal false
end
end
end

describe 'indentation'
describe 'when invalid'
it 'should throw an error'
Expand Down

0 comments on commit 0e99409

Please sign in to comment.