From 425ea3e3d56d7b29723b6dadf6f052f9a9217324 Mon Sep 17 00:00:00 2001 From: Patrick R Date: Tue, 4 May 2021 17:44:18 +0200 Subject: [PATCH] A first implementation of preserving underscores when trying to find a method in an attribute to apply to a node. --- ...anPreserveTheUnderscoreInlineMessageNames.st | 17 +++++++++++++++++ .../methodProperties.json | 1 + .../README.md | 0 .../instance/Rule.with..st | 4 ++++ .../instance/RuleOne.with..st | 4 ++++ .../instance/Rule_one.with..st | 4 ++++ .../instance/Rule_two.with..st | 4 ++++ .../instance/Start.with.with..st | 4 ++++ .../instance/wantsOriginalInlineRuleNames.st | 4 ++++ .../methodProperties.json | 10 ++++++++++ .../properties.json | 14 ++++++++++++++ .../class/originalRuleNameAsMessageName..st | 4 ++++ .../class/ruleNameToMessageName..st | 8 +++----- .../OhmAttributes.class/instance/value..st | 7 +++++-- .../instance/wantsOriginalInlineRuleNames.st | 7 +++++++ .../OhmAttributes.class/methodProperties.json | 6 ++++-- 16 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 packages/Ohm-Core.package/OhmAttributeGenerationTest.class/instance/testAttributesCanPreserveTheUnderscoreInlineMessageNames.st create mode 100644 packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/README.md create mode 100644 packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule.with..st create mode 100644 packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/RuleOne.with..st create mode 100644 packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule_one.with..st create mode 100644 packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule_two.with..st create mode 100644 packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Start.with.with..st create mode 100644 packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/wantsOriginalInlineRuleNames.st create mode 100644 packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/methodProperties.json create mode 100644 packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/properties.json create mode 100644 packages/Ohm-Core.package/OhmAttributes.class/class/originalRuleNameAsMessageName..st create mode 100644 packages/Ohm-Core.package/OhmAttributes.class/instance/wantsOriginalInlineRuleNames.st diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTest.class/instance/testAttributesCanPreserveTheUnderscoreInlineMessageNames.st b/packages/Ohm-Core.package/OhmAttributeGenerationTest.class/instance/testAttributesCanPreserveTheUnderscoreInlineMessageNames.st new file mode 100644 index 0000000..3c9ec05 --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributeGenerationTest.class/instance/testAttributesCanPreserveTheUnderscoreInlineMessageNames.st @@ -0,0 +1,17 @@ +tests +testAttributesCanPreserveTheUnderscoreInlineMessageNames + + | g cst collector result | + g := OhmGrammar new: 'G { + Start = RuleOne Rule + RuleOne = "hello" + Rule = + "world" -- one + | "and others" -- two }'. + + collector := g synthesizedAttribute: OhmAttributeGenerationTestUnderscoreAttribute new. + + cst := g match: 'hello world' startingFrom: 'Start'. + result := collector value: cst. + + self assert: (result includes: #Rule_one). \ No newline at end of file diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTest.class/methodProperties.json b/packages/Ohm-Core.package/OhmAttributeGenerationTest.class/methodProperties.json index df8482e..227b887 100644 --- a/packages/Ohm-Core.package/OhmAttributeGenerationTest.class/methodProperties.json +++ b/packages/Ohm-Core.package/OhmAttributeGenerationTest.class/methodProperties.json @@ -10,6 +10,7 @@ "fixtureRuleFoo:" : "pre 1/13/2015 16:01", "setUp" : "pre 5/20/2017 16:55", "tearDown" : "pre 4/22/2015 14:13", + "testAttributesCanPreserveTheUnderscoreInlineMessageNames" : "pre 5/4/2021 17:37", "testBindingsAreEvaluatedLazily" : "pre 5/20/2017 16:55", "testBindingsAreEvaluatedLazilyAlsoWithSynthesizedAttributes" : "pre 11/17/2017 17:00", "testBindingsAreEvaluatedLazilyAlsoWithSynthesizedAttributesAndCached" : "pre 5/20/2017 16:56", diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/README.md b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/README.md new file mode 100644 index 0000000..e69de29 diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule.with..st b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule.with..st new file mode 100644 index 0000000..bde6df7 --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule.with..st @@ -0,0 +1,4 @@ +rules +Rule: aNode with: opt + + ^ self value: opt \ No newline at end of file diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/RuleOne.with..st b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/RuleOne.with..st new file mode 100644 index 0000000..ac0f9c8 --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/RuleOne.with..st @@ -0,0 +1,4 @@ +rules +RuleOne: aNode with: worldString + + ^ {#RuleOne} \ No newline at end of file diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule_one.with..st b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule_one.with..st new file mode 100644 index 0000000..b23e8c7 --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule_one.with..st @@ -0,0 +1,4 @@ +rules +Rule_one: aNode with: string + + ^ {#Rule_one} \ No newline at end of file diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule_two.with..st b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule_two.with..st new file mode 100644 index 0000000..d1b3172 --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Rule_two.with..st @@ -0,0 +1,4 @@ +rules +Rule_two: aNode with: string + + ^ {#Rule_two} \ No newline at end of file diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Start.with.with..st b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Start.with.with..st new file mode 100644 index 0000000..406e5f5 --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/Start.with.with..st @@ -0,0 +1,4 @@ +rules +Start: aNode with: a with: b + + ^ (self value: a) , (self value: b) \ No newline at end of file diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/wantsOriginalInlineRuleNames.st b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/wantsOriginalInlineRuleNames.st new file mode 100644 index 0000000..716ae0f --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/instance/wantsOriginalInlineRuleNames.st @@ -0,0 +1,4 @@ +as yet unclassified +wantsOriginalInlineRuleNames + + ^ true \ No newline at end of file diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/methodProperties.json b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/methodProperties.json new file mode 100644 index 0000000..d9a1fb7 --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/methodProperties.json @@ -0,0 +1,10 @@ +{ + "class" : { + }, + "instance" : { + "Rule:with:" : "pre 5/4/2021 17:35", + "RuleOne:with:" : "pre 5/4/2021 17:35", + "Rule_one:with:" : "pre 5/4/2021 17:35", + "Rule_two:with:" : "pre 5/4/2021 17:35", + "Start:with:with:" : "pre 5/4/2021 17:34", + "wantsOriginalInlineRuleNames" : "pre 5/4/2021 17:40" } } diff --git a/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/properties.json b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/properties.json new file mode 100644 index 0000000..519601c --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributeGenerationTestUnderscoreAttribute.class/properties.json @@ -0,0 +1,14 @@ +{ + "category" : "Ohm-Core-Tests", + "classinstvars" : [ + ], + "classvars" : [ + ], + "commentStamp" : "", + "instvars" : [ + ], + "name" : "OhmAttributeGenerationTestUnderscoreAttribute", + "pools" : [ + ], + "super" : "OhmSemanticAction", + "type" : "normal" } diff --git a/packages/Ohm-Core.package/OhmAttributes.class/class/originalRuleNameAsMessageName..st b/packages/Ohm-Core.package/OhmAttributes.class/class/originalRuleNameAsMessageName..st new file mode 100644 index 0000000..531e009 --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributes.class/class/originalRuleNameAsMessageName..st @@ -0,0 +1,4 @@ +converting +originalRuleNameAsMessageName: ruleName + + ^ (ruleName , ':') asSymbol \ No newline at end of file diff --git a/packages/Ohm-Core.package/OhmAttributes.class/class/ruleNameToMessageName..st b/packages/Ohm-Core.package/OhmAttributes.class/class/ruleNameToMessageName..st index ae3c16a..879fafe 100644 --- a/packages/Ohm-Core.package/OhmAttributes.class/class/ruleNameToMessageName..st +++ b/packages/Ohm-Core.package/OhmAttributes.class/class/ruleNameToMessageName..st @@ -1,13 +1,11 @@ converting ruleNameToMessageName: ruleName - + | name nameParts | nameParts := (ruleName subStrings: '_') asOrderedCollection. nameParts ifEmpty: [ ^ 'anything:' asSymbol ]. name := nameParts removeFirst. - nameParts - ifNotEmpty:[ name := name , - (nameParts inject: '' - into: [ :result :new | result , new capitalized ])]. + nameParts ifNotEmpty: [ + name := name , (nameParts inject: '' into: [:result :new | result , new capitalized])]. ^ (name , ':') asSymbol \ No newline at end of file diff --git a/packages/Ohm-Core.package/OhmAttributes.class/instance/value..st b/packages/Ohm-Core.package/OhmAttributes.class/instance/value..st index ffe5e71..fe0c70e 100644 --- a/packages/Ohm-Core.package/OhmAttributes.class/instance/value..st +++ b/packages/Ohm-Core.package/OhmAttributes.class/instance/value..st @@ -1,13 +1,16 @@ evaluation value: inputNode - + | selectors ruleName ruleMessageName aNode | inputNode isOhmMatchResult ifTrue: [aNode := inputNode cst] ifFalse: [aNode := inputNode ]. ruleName := aNode ruleName asSymbol. - ruleMessageName := self class ruleNameToMessageName: ruleName. + self wantsOriginalInlineRuleNames + ifTrue: [ruleMessageName := self class originalRuleNameAsMessageName: ruleName.] + ifFalse: [ruleMessageName := self class ruleNameToMessageName: ruleName.]. + selectors := self selectors select: [:msg | msg beginsWith: ruleMessageName]. self assert: selectors size <= 1. diff --git a/packages/Ohm-Core.package/OhmAttributes.class/instance/wantsOriginalInlineRuleNames.st b/packages/Ohm-Core.package/OhmAttributes.class/instance/wantsOriginalInlineRuleNames.st new file mode 100644 index 0000000..217bbeb --- /dev/null +++ b/packages/Ohm-Core.package/OhmAttributes.class/instance/wantsOriginalInlineRuleNames.st @@ -0,0 +1,7 @@ +configuration +wantsOriginalInlineRuleNames + + "If set to true, the attribute will use the original rule name as the prefix + to find the correct method to apply. This will preserve the underscore + used in inline rules." + ^ false \ No newline at end of file diff --git a/packages/Ohm-Core.package/OhmAttributes.class/methodProperties.json b/packages/Ohm-Core.package/OhmAttributes.class/methodProperties.json index 482be7d..60a304b 100644 --- a/packages/Ohm-Core.package/OhmAttributes.class/methodProperties.json +++ b/packages/Ohm-Core.package/OhmAttributes.class/methodProperties.json @@ -1,7 +1,8 @@ { "class" : { + "originalRuleNameAsMessageName:" : "pre 5/4/2021 17:43", "possibleActionsForRule:" : "pre 5/5/2015 20:32", - "ruleNameToMessageName:" : "^pre 4/30/2015 09:28" }, + "ruleNameToMessageName:" : "pre 5/4/2021 17:39" }, "instance" : { "applyListAttribute:on:" : "pre 5/5/2015 18:08", "defaultAttributeApplicable:on:" : "pre 5/4/2015 11:32", @@ -12,4 +13,5 @@ "selectors" : "pre 3/24/2020 09:27", "terminalExpression:" : "pre 1/7/2015 14:22", "tryToUseSpecialAttributesFor:asMessage:on:" : "pre 3/24/2020 09:29", - "value:" : "pre 7/7/2020 16:27" } } + "value:" : "pre 5/4/2021 17:42", + "wantsOriginalInlineRuleNames" : "pre 5/4/2021 17:42" } }