Permalink
Browse files

Boolean tokens shut down the parsers

If a boolean token is found, the parse doesn't advance and returns.

Also, if an id starts with a yaml boolean (i.e. nomore, yesman,
enabledFeature) the parser also stops advancing and returns the
parsed tokens until that point in time.

see examples/boolean.yaml

badly need unit tests...

Signed-off-by: Tj Holowaychuk <tj@vision-media.ca>
  • Loading branch information...
1 parent 795ae8c commit 378d055b47e924fc3c86d7cf7845d5cc54f8d1ca @adiospace adiospace committed with May 22, 2011
Showing with 12 additions and 5 deletions.
  1. +7 −0 examples/boolean.yaml
  2. +5 −5 lib/yaml.js
View
@@ -0,0 +1,7 @@
+---
+ title: Some Title
+ falseme: I can see this
+ what: no
+ say: yes
+ trueme: found
+ hope: to see this
View
@@ -37,8 +37,8 @@ var tokens = [
['comment', /^#[^\n]*/],
['indent', /^\n( *)/],
['space', /^ +/],
- ['true', /^(enabled|true|yes|on)/],
- ['false', /^(disabled|false|no|off)/],
+ ['true', /^\b(enabled|true|yes|on)\b/],
+ ['false', /^\b(disabled|false|no|off)\b/],
['string', /^"(.*?)"/],
['string', /^'(.*?)'/],
['timestamp', /^((\d{4})-(\d\d?)-(\d\d?)(?:(?:[ \t]+)(\d\d?):(\d\d)(?::(\d\d))?)?)/],
@@ -53,7 +53,7 @@ var tokens = [
['-', /^\-/],
[':', /^[:]/],
['string', /^(?![^:\n\s]*:[^\/]{2})(([^:,\]\}\n\s]|(?!\n)\s(?!\s*?\n)|:\/\/|,(?=[^\n]*\s*[^\]\}\s\n]\s*\n)|[\]\}](?=[^\n]*\s*[^\]\}\s\n]\s*\n))*)(?=[,:\]\}\s\n]|$)/],
- ['id', /^([\w ]+)/],
+ ['id', /^([\w ]+)/]
]
/**
@@ -241,9 +241,9 @@ Parser.prototype.parse = function() {
case 'int':
return parseInt(this.advanceValue())
case 'true':
- return true
+ this.advanceValue(); return true
case 'false':
- return false
+ this.advanceValue(); return false
}
}

0 comments on commit 378d055

Please sign in to comment.