From f9d386c2510c229cc29f3f44879539cd27a0e4cc Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Fri, 10 Jun 2022 16:49:33 +0200 Subject: [PATCH] Add chapter on styling the AST --- lepiter/98eic2j16rr2u9v6h3elxhsll.bak | 224 ++++++++++++++++++++++ lepiter/98eic2j16rr2u9v6h3elxhsll.lepiter | 154 ++++++++++++++- 2 files changed, 375 insertions(+), 3 deletions(-) create mode 100644 lepiter/98eic2j16rr2u9v6h3elxhsll.bak diff --git a/lepiter/98eic2j16rr2u9v6h3elxhsll.bak b/lepiter/98eic2j16rr2u9v6h3elxhsll.bak new file mode 100644 index 0000000..b8249d5 --- /dev/null +++ b/lepiter/98eic2j16rr2u9v6h3elxhsll.bak @@ -0,0 +1,224 @@ +{ + "__schema" : "4.1", + "__type" : "page", + "children" : { + "__type" : "snippets", + "items" : [ + { + "__type" : "textSnippet", + "children" : { + "__type" : "snippets", + "items" : [ ] + }, + "createEmail" : { + "__type" : "email", + "emailString" : "" + }, + "createTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:26:00.598758+02:00" + } + }, + "editEmail" : { + "__type" : "email", + "emailString" : "" + }, + "editTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:27:38.908748+02:00" + } + }, + "uid" : { + "__type" : "uid", + "uidString" : "+EdxxTyZDQCZwZeADqn2mw==" + }, + "paragraphStyle" : { + "__type" : "textStyle" + }, + "string" : "Once we have an AST, we might want to add syntax highlighting. It’s actually quite simple to add syntax highlighting for an existing parser; all we need to do is add a method to the class {{gtClass:GtSmaCCParserStyler}}." + }, + { + "__type" : "textSnippet", + "children" : { + "__type" : "snippets", + "items" : [ ] + }, + "createEmail" : { + "__type" : "email", + "emailString" : "" + }, + "createTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:27:43.823213+02:00" + } + }, + "editEmail" : { + "__type" : "email", + "emailString" : "" + }, + "editTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:30:41.645617+02:00" + } + }, + "uid" : { + "__type" : "uid", + "uidString" : "rt9venqdDQCJG731AZ6iBQ==" + }, + "paragraphStyle" : { + "__type" : "textStyle" + }, + "string" : "In the case of Carp, the code resides in {{gtMethod:GtSmaCCParserStyler class>>#carpStyler:}} with some utilities in {{gtClass:CarpStylerUtilities}}. The code is straight-forward: we simply add a rule for all the different types of node we generated in [[Building a parser from scratch]] that we want to highlight with the style information such as color and text adornment." + }, + { + "__type" : "textSnippet", + "children" : { + "__type" : "snippets", + "items" : [ ] + }, + "createEmail" : { + "__type" : "email", + "emailString" : "" + }, + "createTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:30:43.246304+02:00" + } + }, + "editEmail" : { + "__type" : "email", + "emailString" : "" + }, + "editTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:31:44.742069+02:00" + } + }, + "uid" : { + "__type" : "uid", + "uidString" : "whgkhXqdDQCJpS0fAZ6iBQ==" + }, + "paragraphStyle" : { + "__type" : "textStyle" + }, + "string" : "If you need inspiration for your styler, here is a list of all the methods defined in {{gtClass:GtSmaCCParserStyler}}:" + }, + { + "__type" : "textSnippet", + "children" : { + "__type" : "snippets", + "items" : [ ] + }, + "createEmail" : { + "__type" : "email", + "emailString" : "" + }, + "createTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:32:13.252466+02:00" + } + }, + "editEmail" : { + "__type" : "email", + "emailString" : "" + }, + "editTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:44:28.640047+02:00" + } + }, + "uid" : { + "__type" : "uid", + "uidString" : "USl+inqdDQCJqBvxAZ6iBQ==" + }, + "paragraphStyle" : { + "__type" : "textStyle" + }, + "string" : "{{gtExample:GtSmaCCParserStyler class >> #itself | noCode=true | previewExpanded=true | previewShow=#gtParsersFor:}}" + }, + { + "__type" : "textSnippet", + "children" : { + "__type" : "snippets", + "items" : [ ] + }, + "createEmail" : { + "__type" : "email", + "emailString" : "" + }, + "createTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:44:52.275311+02:00" + } + }, + "editEmail" : { + "__type" : "email", + "emailString" : "" + }, + "editTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:47:01.610149+02:00" + } + }, + "uid" : { + "__type" : "uid", + "uidString" : "+ybFtnqdDQCJv51jAZ6iBQ==" + }, + "paragraphStyle" : { + "__type" : "textStyle" + }, + "string" : "In Carp, I also went down the extra mile of coloring parentheses according to their nesting level. The code for this is inside the rule for lists, maps and arrays, and it uses {{gtClass:CarpStylerUtilities}} to color the parentheses and register an event for when the cursor enters or leaves the region to highlight it. Should you want more complex highlighting and change it based on cursor position" + } + ] + }, + "createEmail" : { + "__type" : "email", + "emailString" : "" + }, + "createTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-04-17T17:09:46.810502+02:00" + } + }, + "editEmail" : { + "__type" : "email", + "emailString" : "" + }, + "editTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-04-17T17:09:46.810502+02:00" + } + }, + "pageType" : { + "__type" : "namedPage", + "title" : "Styling your AST" + }, + "uid" : { + "__type" : "uuid", + "uuid" : "098070c5-3c99-0d00-99c0-2cce0ea9f69b" + } +} \ No newline at end of file diff --git a/lepiter/98eic2j16rr2u9v6h3elxhsll.lepiter b/lepiter/98eic2j16rr2u9v6h3elxhsll.lepiter index 284f6fb..dd52d9d 100644 --- a/lepiter/98eic2j16rr2u9v6h3elxhsll.lepiter +++ b/lepiter/98eic2j16rr2u9v6h3elxhsll.lepiter @@ -18,7 +18,7 @@ "__type" : "time", "time" : { "__type" : "dateAndTime", - "dateAndTimeString" : "2022-04-17T17:09:48.939646+02:00" + "dateAndTimeString" : "2022-06-10T16:26:00.598758+02:00" } }, "editEmail" : { @@ -29,7 +29,7 @@ "__type" : "time", "time" : { "__type" : "dateAndTime", - "dateAndTimeString" : "2022-04-17T17:09:49.381266+02:00" + "dateAndTimeString" : "2022-06-10T16:27:38.908748+02:00" } }, "uid" : { @@ -39,7 +39,155 @@ "paragraphStyle" : { "__type" : "textStyle" }, - "string" : "TODO" + "string" : "Once we have an AST, we might want to add syntax highlighting. It’s actually quite simple to add syntax highlighting for an existing parser; all we need to do is add a method to the class {{gtClass:GtSmaCCParserStyler}}." + }, + { + "__type" : "textSnippet", + "children" : { + "__type" : "snippets", + "items" : [ ] + }, + "createEmail" : { + "__type" : "email", + "emailString" : "" + }, + "createTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:27:43.823213+02:00" + } + }, + "editEmail" : { + "__type" : "email", + "emailString" : "" + }, + "editTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:30:41.645617+02:00" + } + }, + "uid" : { + "__type" : "uid", + "uidString" : "rt9venqdDQCJG731AZ6iBQ==" + }, + "paragraphStyle" : { + "__type" : "textStyle" + }, + "string" : "In the case of Carp, the code resides in {{gtMethod:GtSmaCCParserStyler class>>#carpStyler:}} with some utilities in {{gtClass:CarpStylerUtilities}}. The code is straight-forward: we simply add a rule for all the different types of node we generated in [[Building a parser from scratch]] that we want to highlight with the style information such as color and text adornment." + }, + { + "__type" : "textSnippet", + "children" : { + "__type" : "snippets", + "items" : [ ] + }, + "createEmail" : { + "__type" : "email", + "emailString" : "" + }, + "createTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:30:43.246304+02:00" + } + }, + "editEmail" : { + "__type" : "email", + "emailString" : "" + }, + "editTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:31:44.742069+02:00" + } + }, + "uid" : { + "__type" : "uid", + "uidString" : "whgkhXqdDQCJpS0fAZ6iBQ==" + }, + "paragraphStyle" : { + "__type" : "textStyle" + }, + "string" : "If you need inspiration for your styler, here is a list of all the methods defined in {{gtClass:GtSmaCCParserStyler}}:" + }, + { + "__type" : "textSnippet", + "children" : { + "__type" : "snippets", + "items" : [ ] + }, + "createEmail" : { + "__type" : "email", + "emailString" : "" + }, + "createTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:32:13.252466+02:00" + } + }, + "editEmail" : { + "__type" : "email", + "emailString" : "" + }, + "editTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:44:28.640047+02:00" + } + }, + "uid" : { + "__type" : "uid", + "uidString" : "USl+inqdDQCJqBvxAZ6iBQ==" + }, + "paragraphStyle" : { + "__type" : "textStyle" + }, + "string" : "{{gtExample:GtSmaCCParserStyler class >> #itself | noCode=true | previewExpanded=true | previewShow=#gtParsersFor:}}" + }, + { + "__type" : "textSnippet", + "children" : { + "__type" : "snippets", + "items" : [ ] + }, + "createEmail" : { + "__type" : "email", + "emailString" : "" + }, + "createTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:44:52.275311+02:00" + } + }, + "editEmail" : { + "__type" : "email", + "emailString" : "" + }, + "editTime" : { + "__type" : "time", + "time" : { + "__type" : "dateAndTime", + "dateAndTimeString" : "2022-06-10T16:47:24.613405+02:00" + } + }, + "uid" : { + "__type" : "uid", + "uidString" : "+ybFtnqdDQCJv51jAZ6iBQ==" + }, + "paragraphStyle" : { + "__type" : "textStyle" + }, + "string" : "In Carp, I also went down the extra mile of coloring parentheses according to their nesting level. The code for this is inside the rule for lists, maps and arrays, and it uses {{gtClass:CarpStylerUtilities}} to color the parentheses and register an event for when the cursor enters or leaves the region to highlight it. Should you want more complex highlighting and change it based on cursor position and interactions, this might give you a taste of how to do it." } ] },