Skip to content

Commit

Permalink
A first implementation of preserving underscores when trying to find …
Browse files Browse the repository at this point in the history
…a method in an attribute to apply to a node.
  • Loading branch information
codeZeilen committed May 4, 2021
1 parent 3bf594e commit 425ea3e
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rules
Rule: aNode with: opt

^ self value: opt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rules
RuleOne: aNode with: worldString

^ {#RuleOne}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rules
Rule_one: aNode with: string

^ {#Rule_one}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rules
Rule_two: aNode with: string

^ {#Rule_two}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rules
Start: aNode with: a with: b

^ (self value: a) , (self value: b)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
as yet unclassified
wantsOriginalInlineRuleNames

^ true
Original file line number Diff line number Diff line change
@@ -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" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "Ohm-Core-Tests",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
],
"name" : "OhmAttributeGenerationTestUnderscoreAttribute",
"pools" : [
],
"super" : "OhmSemanticAction",
"type" : "normal" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
converting
originalRuleNameAsMessageName: ruleName

^ (ruleName , ':') asSymbol
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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" } }

0 comments on commit 425ea3e

Please sign in to comment.