Index: trunk/extensions/VisualEditor/modules/parser/pegParser.pegjs.txt |
— | — | @@ -588,26 +588,29 @@ |
589 | 589 | / & { return syntaxFlags['extlink']; } "]" { return true; } |
590 | 590 | / & { return syntaxFlags['linkdesc']; } link_end { return true; } |
591 | 591 | / & { return syntaxFlags['h']; } '='+ space* newline { return true; } |
| 592 | + / & { return syntaxFlags['template']; } ('|' / '}}') { return true; } |
592 | 593 | |
593 | 594 | inline |
594 | | - = c:(urltext / inline_element / (!inline_breaks ch:. { return ch; }))+ { |
| 595 | + = c:(urltext / (! inline_breaks (inline_element / . )))+ { |
595 | 596 | var out = []; |
596 | 597 | var text = []; |
597 | 598 | c = flatten(c); |
598 | | - for (var i = 0; i < c.length; i++) { |
599 | | - if (typeof c[i] == 'string') { |
600 | | - text.push(c[i]); |
| 599 | + for (var i = 0, l = c.length; i < l; i++) { |
| 600 | + var ci = c[i]; |
| 601 | + if (typeof ci == 'string') { |
| 602 | + text.push(ci); |
601 | 603 | } else { |
602 | 604 | if (text.length) { |
603 | 605 | out.push({ type: "TEXT", value: text.join('') }); |
604 | 606 | text = []; |
605 | 607 | } |
606 | | - out.concat(c[i]); |
| 608 | + out.push(ci); |
607 | 609 | } |
608 | 610 | } |
609 | 611 | if (text.length) { |
610 | 612 | out.push({ type: 'TEXT', value: text.join('') }); |
611 | 613 | } |
| 614 | + //dp('inline out:' + pp(out)); |
612 | 615 | return out; |
613 | 616 | } |
614 | 617 | |
— | — | @@ -618,20 +621,21 @@ |
619 | 622 | var text = []; |
620 | 623 | c = flatten(c); |
621 | 624 | for (var i = 0; i < c.length; i++) { |
622 | | - if (typeof c[i] == 'string') { |
623 | | - text.push(c[i]); |
| 625 | + var ci = c[i] |
| 626 | + if (typeof ci == 'string') { |
| 627 | + text.push(ci); |
624 | 628 | } else { |
625 | 629 | if (text.length) { |
626 | 630 | out.push({type: 'TEXT', value: text.join('')}); |
627 | 631 | text = []; |
628 | 632 | } |
629 | | - out.push(c[i]); |
| 633 | + out.push(ci); |
630 | 634 | } |
631 | 635 | } |
632 | 636 | if (text.length) { |
633 | 637 | out.push({type: 'TEXT', value: text.join('')}); |
634 | 638 | } |
635 | | - dp('inlineline out:', pp(out)); |
| 639 | + //dp('inlineline out:' + pp(out)); |
636 | 640 | return out; |
637 | 641 | } |
638 | 642 | |
— | — | @@ -775,7 +779,9 @@ |
776 | 780 | //[^][<>"\\x00-\\x20\\x7F\p{Zs}] |
777 | 781 | |
778 | 782 | template |
779 | | - = "{{" target:template_target params:("|" p:template_param { return p })* "}}" { |
| 783 | + = "{{" target:template_target |
| 784 | + params:(newline? "|" newline? p:template_param { return p })* |
| 785 | + "}}" { |
780 | 786 | var obj = { type: 'TAG', name: 'template', |
781 | 787 | attribs: [['target', target]], |
782 | 788 | args: {}} |
— | — | @@ -798,29 +804,28 @@ |
799 | 805 | // parser only recognizes known self-closing tags for now, so use an |
800 | 806 | // explicit end tag for now. |
801 | 807 | //console.log(pp(obj)); |
802 | | - return [obj, {type: 'ENDTAG', name: 'template'}]; |
| 808 | + return obj; |
803 | 809 | } |
804 | 810 | |
805 | 811 | template_target |
806 | 812 | = h:( !"}}" x:([^|\n]) { return x } )* { return h.join(''); } |
807 | 813 | |
808 | | -/* XXX: pass these as convenient js structures to later stages, but serialize |
809 | | - * (to json) before passing remaining args to the tree builder */ |
810 | 814 | template_param |
811 | | - = name:template_param_name "=" c:template_param_text { |
| 815 | + = name:template_param_name space* "=" space* c:template_param_text { |
812 | 816 | return [name, c]; |
813 | 817 | } / c:template_param_text { |
814 | 818 | return [null, c]; |
815 | 819 | } |
816 | 820 | |
817 | 821 | tplarg |
818 | | - = "{{{" name:link_target params:("|" ! "}}}" p:template_param { return p })* "}}}" { |
| 822 | + = "{{{" name:link_target params:("|" p:template_param { return p })* "}}}" { |
819 | 823 | var obj = { |
820 | 824 | type: 'SELFCLOSINGTAG', |
821 | 825 | name: 'templatearg', |
822 | 826 | attribs: [['argname', name]] |
823 | 827 | }; |
824 | 828 | if (params && params.length) { |
| 829 | + // HACK, not final. |
825 | 830 | obj.attribs.push(['data-args', JSON.stringify(params)]); |
826 | 831 | } |
827 | 832 | return obj; |
— | — | @@ -829,23 +834,24 @@ |
830 | 835 | template_param_name |
831 | 836 | = h:( !"}}" x:([^=|\n]) { return x } )* { return h.join(''); } |
832 | 837 | |
| 838 | +// XXX: convert to inlineline with syntactic stop on "}}" |
833 | 839 | template_param_text |
834 | | - = tcs:template_param_text_chunk* { return JSON.stringify(tcs); } |
835 | | - //= h:( !"}}" x:([^|]) { return x } )* { return h.join(''); } |
| 840 | + = & { return setFlag('template') } |
| 841 | + il:inline+ { |
| 842 | + clearFlag('template'); |
| 843 | + return il; |
| 844 | + } |
| 845 | + / & { clearFlag('template'); return false; } |
| 846 | +// urltext |
| 847 | +// / xmlish_tag |
| 848 | +// / extlink |
| 849 | +// / template |
| 850 | +// / tplarg |
| 851 | +// / wikilink |
| 852 | +// / quote |
| 853 | +// / c:[^}|\n]+ {return {type: 'TEXT', value: c.join('')}} |
| 854 | +// / !"}}" x:([^|\n]) { return {type: 'TEXT', value: x} } |
836 | 855 | |
837 | | - |
838 | | -// XXX: convert to inlineline with syntactic stop on "}}" |
839 | | -template_param_text_chunk |
840 | | - = comment |
841 | | - / xmlish_tag |
842 | | - / extlink |
843 | | - / template |
844 | | - / tplarg |
845 | | - / wikilink |
846 | | - / quote |
847 | | - / c:[^}|\n]+ {return {type: 'TEXT', value: c.join('')}} |
848 | | - / !"}}" x:([^|\n]) { return {type: 'TEXT', value: x} } |
849 | | - |
850 | 856 | wikilink |
851 | 857 | = "[[" |
852 | 858 | ! url |