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

Templating engine #28

Draft
wants to merge 91 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
868bec1
Implement basic tests runner
lofcz Apr 14, 2022
f6890d6
Progress on implicit expr
lofcz Apr 15, 2022
961985c
Merge branch 'main' into feat-templating-lofcz
lofcz Apr 17, 2022
1d6facf
If-else nested passing
lofcz Apr 18, 2022
1c2f5e6
Begin work on explicit expressions
lofcz Apr 19, 2022
782cec8
Add support for comments in expressions, @* *@ comments
lofcz Apr 19, 2022
4fd0590
Add support for "else if"
lofcz Apr 19, 2022
f595a22
Add support for "elseif"
lofcz Apr 19, 2022
8303d67
Add support for "for"
lofcz Apr 19, 2022
bbff544
Add support for implicitly self closed tags
lofcz Apr 19, 2022
3496d47
Fix handling of server side comment when parsing inner content of a tag
lofcz Apr 19, 2022
f6aee34
Implement folding of tokens
lofcz Apr 19, 2022
d541828
Don't return from ParseCodeBlock until we've matched brks
lofcz Apr 19, 2022
79a992f
Support escape sequences in detected strings
lofcz Apr 19, 2022
72c4976
Add support for line transitions via @:
lofcz Apr 19, 2022
0bff8bd
Add support for <text> transition
lofcz Apr 19, 2022
a057052
Added support for while
lofcz Apr 19, 2022
0d06916
Added support for do..while
lofcz Apr 19, 2022
b447812
Added support for function
lofcz Apr 19, 2022
424ae52
Keep track of current sides to check for correct possible transitions
lofcz Apr 19, 2022
fa400d0
Add support for custom directives
lofcz Apr 19, 2022
907bafd
Cleanup, added public method debug
lofcz Apr 19, 2022
07e63e7
Merge branch 'main' into feat-templating-lofcz
lofcz Apr 19, 2022
686a7fe
Implemented missing @: in transition
lofcz Apr 19, 2022
25506d1
Avoid allocating in EncodeJsString
lofcz Apr 19, 2022
9f3ae29
Added support for @!
lofcz Apr 19, 2022
66caf7a
Merge branch 'main' into feat-templating-lofcz
lofcz Apr 20, 2022
6e7ae68
Added support for @switch implicit transition
lofcz Apr 20, 2022
deeb5db
Render transpiled code in error messages
lofcz Apr 20, 2022
ed16e20
Test cd on win
lofcz Apr 20, 2022
528ec60
Fix newline handling
lofcz Apr 21, 2022
0825469
Update dotnet.yml
lofcz Apr 21, 2022
72167ac
Shape public api
lofcz Apr 21, 2022
72a0016
Refactor
lofcz Apr 24, 2022
d1483a7
Add support for mathml/svg cdata
lofcz Apr 24, 2022
109dd56
Don't emit no-op CLEAN ops
CallumDev Apr 25, 2022
38f6f65
Merge branch 'main' into feat-templating-lofcz
lofcz Apr 26, 2022
02b26c7
Improve handling of <text> transition
lofcz Apr 26, 2022
1bec0ac
Fix - closing tags don't have to have a whitespace at the end
lofcz Apr 26, 2022
1b3e082
Update FunctionBuilder.cs
lofcz Apr 26, 2022
1ed1f11
Merge branch 'main' into feat-templating-lofcz
lofcz Apr 26, 2022
c2a3ec6
Split errors in recoverable and fatal
lofcz Apr 26, 2022
b84e76f
Relax unicode
lofcz Apr 26, 2022
10e1434
Merge branch 'main' into feat-templating-lofcz
lofcz Apr 27, 2022
5c6f30a
Improve recovery
lofcz Apr 27, 2022
3b17e58
Add yt tests
lofcz Apr 27, 2022
f227bd8
Merge remote-tracking branch 'origin/main' into feat-templating-lofcz
lofcz Apr 29, 2022
94b19de
Start work on tag helpers
lofcz Apr 29, 2022
5873e0c
Support basic tag helpers
lofcz Apr 29, 2022
fa98815
Add support for basic tag helpers with content
lofcz Apr 29, 2022
f311863
Add support for block exprs in tag helpers
lofcz Apr 30, 2022
a06cad9
Fix handling of empty strings in server side code
lofcz Apr 30, 2022
041d483
Add support for accessing attributes in tag helpers
lofcz Apr 30, 2022
2a46b00
Support shared context between tag helpers
lofcz May 1, 2022
f177d95
Improve crashes on banned keywords @else, @elseif
lofcz May 3, 2022
61fb784
Add support for self-closing tag helpers
lofcz May 3, 2022
51153a5
Merge branch 'main' into feat-templating-lofcz
lofcz May 17, 2022
f3ec2d4
Merge branch 'feat-public-fn-proto' into feat-templating-lofcz
lofcz May 18, 2022
006535f
Added support for preprocessor explicit transition @#
lofcz May 18, 2022
0d6d4d0
Added support for Html.Encode, Raw
lofcz May 18, 2022
9734ee2
Merge branch 'main' into feat-templating-lofcz
lofcz May 18, 2022
73af684
Support ! syntax to force native html elements
lofcz May 18, 2022
dc2fe1f
Fix adding double tokens
lofcz May 18, 2022
4f71011
Added tests for banned keywords
lofcz May 18, 2022
2ccc5f9
Support transitioning to server side from html comments
lofcz May 18, 2022
fc03979
Clean parser
lofcz May 18, 2022
7970748
Emit #line in debug mode
lofcz May 18, 2022
6a7622c
Discard empty blocks
lofcz May 18, 2022
3ce5ebf
Add inifinite loop test
lofcz May 18, 2022
1d4a72c
Merge branch 'feat-instruction-limit' into feat-templating-lofcz
lofcz May 18, 2022
23e4d49
Fix typo in "exceeded"
lofcz May 19, 2022
6f2d8c9
Reduce testing instruction limit to 100M
lofcz May 19, 2022
f6b872b
Merge branch 'main' into feat-templating-lofcz
lofcz May 19, 2022
9dced1a
Reflect updated syntax enum in templating engine
lofcz May 19, 2022
a065bfe
Avoid allocating in optimiseTokens routine
lofcz May 19, 2022
20787fa
Merge branch 'main' into feat-templating-lofcz
lofcz May 21, 2022
459de22
Add support for @enum, improve crash reporting
lofcz May 21, 2022
ee6d10e
Add support for @require
lofcz May 21, 2022
ac147d4
Add more tests for invalid inputs
lofcz May 21, 2022
99d4387
Fix handling of whitespace chars in ParseClient
lofcz May 22, 2022
8e32fd4
Handle server side single line comments
lofcz May 22, 2022
231b688
Improve test CodeBlock\5-mix to cover more cases
lofcz May 22, 2022
e3b0c9f
Merge branch 'main' into feat-templating-lofcz
lofcz Jun 1, 2022
b970589
Merge remote-tracking branch 'origin/feat-classes' into feat-templati…
lofcz Jun 1, 2022
697fe25
Add support for @class, @mixin
lofcz Jun 1, 2022
eada129
Merge branch 'main' into feat-templating-lofcz
lofcz Jun 2, 2022
b92aa8e
Support multiple tag helpers declared per file
lofcz Jun 5, 2022
6374fa8
Add support for self-contained bytecode export
lofcz Jun 15, 2022
94821d4
Move shared logic to Script
lofcz Jun 16, 2022
962373a
Merge branch 'main' into feat-templating-lofcz
lofcz Oct 10, 2022
48052cc
Finish merge
lofcz Oct 10, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,4 @@ public int Emit_JLclInit(SymbolRef sym, int target)
return AppendInstruction(new Instruction(OpCode.JLclInit, target, sym.Index));
}
}
}
}
2 changes: 1 addition & 1 deletion src/WattleScript.Interpreter/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ public static string GetSourceFragment(this SourceRef[] refs, string fullSourceC
return fullSourceCode.Substring(firstNotNull?.FromCharIndex ?? 0, lastNotNull?.ToCharIndex - firstNotNull?.FromCharIndex ?? 0);
}
}
}
}
Empty file.
Empty file modified src/WattleScript.Interpreter/Tree/Lexer/Lexer.cs
100755 → 100644
Empty file.
70 changes: 70 additions & 0 deletions src/WattleScript.Templating/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.ComponentModel;
using System;

namespace WattleScript.Templating;

internal static class Extensions
{
public static string ToDescriptionString(this Enum val)
{
DescriptionAttribute[] attributes = (DescriptionAttribute[])val.GetType().GetField(val.ToString())?.GetCustomAttributes(typeof(DescriptionAttribute), false)!;
return attributes.Length > 0 ? attributes[0].Description : "";
}

public static T? Peek<T>(this List<T?> list)
{
return list.Count > 0 ? list[^1] : default;
}

public static T? Pop<T>(this List<T?> list)
{
if (list.Count > 0)
{
T? itm = list[^1];
list.RemoveAt(list.Count - 1);
return itm;
}

return default;
}

public static void Push<T>(this List<T?> list, T? itm)
{
list.Add(itm);
}

public static string ReplaceFirst(this string text, string search, string replace)
{
int pos = text.IndexOf(search, StringComparison.Ordinal);
return pos < 0 ? text : string.Concat(text[..pos], replace, text.AsSpan(pos + search.Length));
}

public static Tuple<string, bool> Snippet(this string str, int pivot, int n)
{
bool clamped = false;

int expectedStart = pivot - n;
int realStart = Math.Max(0, str.Length > expectedStart ? expectedStart : str.Length);
int expectedLen = 2 * n;
int realLen = Math.Max(str.Length - realStart > expectedLen ? expectedLen : str.Length - realStart, 0);

if (str.Length - realStart < expectedLen)
{
clamped = true;
}

string snippet = str.Substring(realStart, realLen);

/*if (realStart > 0) // text continues before snippet
{
snippet = $"««{snippet}";
}

if (str.Length > realStart + realLen) // text continues after snippet
{
snippet = $"{snippet}»»";
}*/

return new Tuple<string, bool>(snippet, clamped);
}
}
97 changes: 97 additions & 0 deletions src/WattleScript.Templating/Parser/Node.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
namespace WattleScript.Templating;

internal class Document
{
public List<NodeBase> Nodes { get; set; }
public INodeWithChildren CurrentNode { get; set; }
DocumentNode DocNode = new DocumentNode();

public Document()
{
Nodes = new List<NodeBase>();
Nodes.Add(DocNode);
CurrentNode = DocNode;
}

public void AddChild(NodeBase node)
{
DocNode.AddChild(node);
}
}

internal interface INodeWithChildren
{
public List<NodeBase> Children { get; set; }
public void AddChild(NodeBase child);
}

internal class NodeBase
{
public int CharFrom { get; set; }
public bool Recovery { get; set; }
public int Line { get; set; }
public int Col { get; set; }
public int ContentFrom { get; set; }
public int ContentTo { get; set; }
}

internal class ServerNode : NodeBase
{

}

internal class TextNode : NodeBase
{
public string Text { get; set; }

public TextNode(string text)
{
Text = text;
}
}

internal class DocumentNode : NodeBase, INodeWithChildren
{
public List<NodeBase> Children { get; set; } = new List<NodeBase>();
public void AddChild(NodeBase child)
{
Children.Add(child);
}
}

internal class HtmlElement : NodeBase, INodeWithChildren
{
internal enum ClosingType
{
Unknown,
SelfClosing,
ImplicitSelfClosing,
EndTag
}

public HtmlElement Parent { get; set; }
public List<HtmlAttribute> Attributes { get; set; } = new List<HtmlAttribute>();
public string Name { get; set; }
public ClosingType Closing { get; set; }
public bool ForceNativeTag { get; set; }
public List<NodeBase> Children { get; set; } = new List<NodeBase>();

public void AddChild(NodeBase child)
{
Children.Add(child);
}
}

internal class HtmlAttribute
{
public string Name { get; set; }
public string Value { get; set; }
public Parser.HtmlAttrEnclosingModes QuoteType { get; set; }

internal HtmlAttribute(string name, string value, Parser.HtmlAttrEnclosingModes quoteType)
{
Name = name;
Value = value;
QuoteType = quoteType;
}
}
Loading