scratch – Diff between revs 75 and 125
?pathlinks?
Rev 75 | Rev 125 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | |
1 | |
|
2 | Inline = require './Inline' |
2 | Inline = require './Inline' |
|
3 | Pattern = require './Pattern' |
3 | Pattern = require './Pattern' |
|
4 | Utils = require './Utils' |
4 | Utils = require './Utils' |
|
- | 5 | ParseException = require './Exception/ParseException' |
||
Line 5... | Line 6... | |||
5 | ParseException = require './Exception/ParseException' |
6 | ParseMore = require './Exception/ParseMore' |
|
6 | |
7 | |
|
7 | # Parser parses YAML strings to convert them to JavaScript objects. |
8 | # Parser parses YAML strings to convert them to JavaScript objects. |
|
Line 17... | Line 18... | |||
17 | PATTERN_COMPACT_NOTATION: new Pattern '^(?<key>'+Inline.REGEX_QUOTED_STRING+'|[^ \'"\\{\\[].*?) *\\:(\\s+(?<value>.+?))?\\s*$' |
18 | PATTERN_COMPACT_NOTATION: new Pattern '^(?<key>'+Inline.REGEX_QUOTED_STRING+'|[^ \'"\\{\\[].*?) *\\:(\\s+(?<value>.+?))?\\s*$' |
|
18 | PATTERN_MAPPING_ITEM: new Pattern '^(?<key>'+Inline.REGEX_QUOTED_STRING+'|[^ \'"\\[\\{].*?) *\\:(\\s+(?<value>.+?))?\\s*$' |
19 | PATTERN_MAPPING_ITEM: new Pattern '^(?<key>'+Inline.REGEX_QUOTED_STRING+'|[^ \'"\\[\\{].*?) *\\:(\\s+(?<value>.+?))?\\s*$' |
|
19 | PATTERN_DECIMAL: new Pattern '\\d+' |
20 | PATTERN_DECIMAL: new Pattern '\\d+' |
|
20 | PATTERN_INDENT_SPACES: new Pattern '^ +' |
21 | PATTERN_INDENT_SPACES: new Pattern '^ +' |
|
21 | PATTERN_TRAILING_LINES: new Pattern '(\n*)$' |
22 | PATTERN_TRAILING_LINES: new Pattern '(\n*)$' |
|
22 | PATTERN_YAML_HEADER: new Pattern '^\\%YAML[: ][\\d\\.]+.*\n' |
23 | PATTERN_YAML_HEADER: new Pattern '^\\%YAML[: ][\\d\\.]+.*\n', 'm' |
|
23 | PATTERN_LEADING_COMMENTS: new Pattern '^(\\#.*?\n)+' |
24 | PATTERN_LEADING_COMMENTS: new Pattern '^(\\#.*?\n)+', 'm' |
|
24 | PATTERN_DOCUMENT_MARKER_START: new Pattern '^\\-\\-\\-.*?\n' |
25 | PATTERN_DOCUMENT_MARKER_START: new Pattern '^\\-\\-\\-.*?\n', 'm' |
|
25 | PATTERN_DOCUMENT_MARKER_END: new Pattern '^\\.\\.\\.\\s*$' |
26 | PATTERN_DOCUMENT_MARKER_END: new Pattern '^\\.\\.\\.\\s*$', 'm' |
|
26 | PATTERN_FOLDED_SCALAR_BY_INDENTATION: {} |
27 | PATTERN_FOLDED_SCALAR_BY_INDENTATION: {} |
|
Line 27... | Line 28... | |||
27 | |
28 | |
|
28 | # Context types |
29 | # Context types |
|
29 | # |
30 | # |
|
Line 331... | Line 332... | |||
331 | indent = @getCurrentLineIndentation() |
332 | indent = @getCurrentLineIndentation() |
|
Line 332... | Line 333... | |||
332 | |
333 | |
|
333 | if indent is newIndent |
334 | if indent is newIndent |
|
Line 334... | Line -... | |||
334 | removeComments = not removeCommentsPattern.test @currentLine |
- | ||
335 | |
335 | removeComments = not removeCommentsPattern.test @currentLine |
|
336 | if isItUnindentedCollection and not @isStringUnIndentedCollectionItem(@currentLine) and indent is newIndent |
336 | |
|
Line 337... | Line 337... | |||
337 | @moveToPreviousLine() |
337 | if removeComments and @isCurrentLineComment() |
|
338 | break |
338 | continue |
|
339 | |
339 | |
|
Line 340... | Line 340... | |||
340 | if @isCurrentLineBlank() |
340 | if @isCurrentLineBlank() |
|
341 | data.push @currentLine[newIndent..] |
341 | data.push @currentLine[newIndent..] |
|
342 | continue |
342 | continue |
|
Line 343... | Line 343... | |||
343 | |
343 | |
|
344 | if removeComments and @isCurrentLineComment() |
344 | if isItUnindentedCollection and not @isStringUnIndentedCollectionItem(@currentLine) and indent is newIndent |
|
345 | if indent is newIndent |
345 | @moveToPreviousLine() |
|
346 | continue |
346 | break |
|
Line 414... | Line 414... | |||
414 | Inline.configure exceptionOnInvalidType, objectDecoder |
414 | Inline.configure exceptionOnInvalidType, objectDecoder |
|
415 | return Inline.parseScalar matches.type+' '+val |
415 | return Inline.parseScalar matches.type+' '+val |
|
416 | else |
416 | else |
|
417 | return val |
417 | return val |
|
Line 418... | Line -... | |||
418 | |
- | ||
419 | try |
- | ||
420 | return Inline.parse value, exceptionOnInvalidType, objectDecoder |
- | ||
421 | catch e |
418 | |
|
422 | # Try to parse multiline compact sequence or mapping |
419 | # Value can be multiline compact sequence or mapping or string |
|
423 | if value.charAt(0) in ['[', '{'] and e instanceof ParseException and @isNextLineIndented() |
420 | if value.charAt(0) in ['[', '{', '"', "'"] |
|
424 | value += "\n" + @getNextEmbedBlock() |
421 | while true |
|
425 | try |
422 | try |
|
426 | return Inline.parse value, exceptionOnInvalidType, objectDecoder |
423 | return Inline.parse value, exceptionOnInvalidType, objectDecoder |
|
- | 424 | catch e |
||
- | 425 | if e instanceof ParseMore and @moveToNextLine() |
||
- | 426 | value += "\n" + Utils.trim(@currentLine, ' ') |
||
427 | catch e |
427 | else |
|
428 | e.parsedLine = @getRealCurrentLineNb() + 1 |
428 | e.parsedLine = @getRealCurrentLineNb() + 1 |
|
429 | e.snippet = @currentLine |
- | ||
430 | |
429 | e.snippet = @currentLine |
|
431 | throw e |
- | ||
432 | |
430 | throw e |
|
433 | else |
431 | else |
|
434 | e.parsedLine = @getRealCurrentLineNb() + 1 |
432 | if @isNextLineIndented() |
|
435 | e.snippet = @currentLine |
- | ||
436 | |
433 | value += "\n" + @getNextEmbedBlock() |
|
Line 437... | Line 434... | |||
437 | throw e |
434 | return Inline.parse value, exceptionOnInvalidType, objectDecoder |
|
Line 438... | Line 435... | |||
438 | |
435 | |