Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaped angles #87

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/Cro/WebApp/Template/ASTBuilder.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,25 @@ class Cro::WebApp::Template::ASTBuilder {
make Literal.new(text => ~$/);
}


method sigil-tag:sym<comment>($/) {
make Nothing.new;
make Nothing.new;
}

# cw: These are reversed for some reason... I don't know why!
method sigil-tag:sym<leLiteral>($/) {
make Literal.new( text => '<=' );
}

method sigil-tag:sym<geLiteral>($/) {
make Literal.new( text => '>=' );
}

method sigil-tag:sym<gtLiteral>($/) {
make Literal.new( text => '>' );
}

method sigil-tag:sym<ltLiteral>($/) {
make Literal.new( text => '<' );
}

method sigil-tag:sym<topic>($/) {
Expand Down
7 changes: 7 additions & 0 deletions lib/Cro/WebApp/Template/Parser.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ grammar Cro::WebApp::Template::Parser {
[ '>' || <.panic: "malformed closing tag"> ]
}



proto token tag-element { * }

token tag-element:sym<sigil-tag> {
Expand All @@ -66,6 +68,11 @@ grammar Cro::WebApp::Template::Parser {

proto token sigil-tag { * }

token sigil-tag:sym<geLiteral> { '<\ge>' }
token sigil-tag:sym<leLiteral> { '<\le>' }
token sigil-tag:sym<gtLiteral> { '<\gt>' }
token sigil-tag:sym<ltLiteral> { '<\lt>' }

token sigil-tag:sym<topic> {
'<.'
[ <deref> || <.malformed: 'topic tag'> ]
Expand Down
11 changes: 11 additions & 0 deletions t/template-use.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ is norm-ws(render-template('transitive-use.crotmp', {})),
</html>
EXPECTED

is norm-ws(render-template('ab-test-1.crotmp', {})),
norm-ws(q:to/EXPECTED/), 'Can call a sub from a used template';
<header>
Foo bar header<<=
</header>
Content
<footer>
Foo bar footer>>=
</footer>
EXPECTED

sub norm-ws($str) {
$str.subst(:g, /\s+/, '')
}
Expand Down
4 changes: 4 additions & 0 deletions t/test-data/ab-test-1.crotmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<:use 'angle-bracket-escape.crotmp'>
<&header>
Content
<&footer>
19 changes: 19 additions & 0 deletions t/test-data/angle-bracket-escape.crotmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<:sub footer>
<footer>
Foo bar footer<\gt><\ge>
</footer>
</:>

<:sub header>
<header>
Foo bar header<\lt><\le>
</header>
</:>

<:macro wrap>
<html>
<&header><\le><\ge>
<:body>
<&footer>
</html>
</:>