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

Add methods to OhmNode and add case labels #57

Open
wants to merge 6 commits into
base: new-whitespace-handling
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
firstChild

^ self children first
6 changes: 6 additions & 0 deletions packages/Ohm-Core.package/OhmNode.class/instance/isEmpty.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
testing
isEmpty

^ (self interval length == 0
or: [ self interval end < 1 ]
or: [ self interval start > self interval stream contents size ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
isNotEmpty

^ self isEmpty not
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
numberOfChildren

^ self children size
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
unformattedSourceCode

^ self interval stream contents
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
"children" : "pre 1/5/2015 16:06",
"children:" : "pre 1/5/2015 16:06",
"enclosingRule" : "pre 7/31/2020 15:43",
"firstChild" : "PS 8/1/2020 09:25",
"grammar" : "pre 1/5/2015 15:38",
"grammar:" : "pre 1/5/2015 15:38",
"initialize" : "pre 11/21/2017 15:29",
"interval" : "pre 1/5/2015 15:38",
"interval:" : "pre 1/5/2015 15:38",
"isEmpty" : "fau 7/31/2020 16:31",
"isListNode" : "pre 3/2/2018 16:08",
"isNotEmpty" : "fau 7/31/2020 16:32",
"isRootNode" : "pre 7/13/2020 10:31",
"isTerminalNode" : "pre 3/2/2018 16:17",
"numberOfChildren" : "fau 8/4/2020 09:03",
"parent" : "pre 1/21/2015 15:03",
"parent:" : "pre 1/21/2015 15:03",
"printStringLimitedTo:" : "pre 6/9/2015 13:39",
Expand All @@ -23,4 +27,5 @@
"ruleName:" : "pre 1/6/2015 17:15",
"skippedSpacesNodes" : "pre 7/10/2020 11:17",
"skippedSpacesString" : "pre 7/31/2020 15:47",
"sourceMap" : "pre 7/13/2020 10:32" } }
"sourceMap" : "pre 7/13/2020 10:32",
"unformattedSourceCode" : "PS 8/4/2020 06:24" } }
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
standard attributes
defaultExpression: aNode

(aNode interval start to: (aNode interval end min: self sourceMap size))
do: [:index | (self sourceMap at: index) add: aNode].

aNode children do: [:c | self value: c].
aNode isNotEmpty ifTrue: [
aNode interval start
to: aNode interval end
do: [ :index | (self sourceMap at: index) add: aNode ].
aNode children do: [ :c | self value: c ] ]
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
standard attributes
terminalExpression: aNode

aNode interval start to: aNode interval end do: [:i |
(self sourceMap at: i) add: aNode]
aNode isNotEmpty ifTrue: [
aNode interval start
to: aNode interval end
do: [ :index | (self sourceMap at: index) add: aNode ] ]
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
},
"instance" : {
"createSourceMapFor:" : "pre 7/31/2020 15:20",
"defaultExpression:" : "pre 7/13/2020 11:02",
"defaultExpression:" : "fau 7/31/2020 17:35",
"sourceMap" : "pre 4/29/2020 10:20",
"sourceMap:" : "pre 4/29/2020 10:20",
"terminalExpression:" : "pre 7/13/2020 11:01" } }
"terminalExpression:" : "fau 7/31/2020 17:38" } }
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Expression =
Operand CascadedMessages -- operandCascade
| UnaryMessageReceiver CascadedMessages -- unaryCascade
| BinaryMessageReceiver CascadedMessages -- binaryCascade
| KeywordMessageSend
| KeywordMessageSend --base

BinaryMessageSend =
BinaryMessageReceiver BinaryMessage?
Expand Down Expand Up @@ -143,7 +143,8 @@ Pragma =
"<" PragmaValues ">"

PragmaValues =
KeywordPragma+ | unaryPragma
KeywordPragma+ --keyword
| unaryPragma --unary

Pragmas =
Pragma*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"class" : {
"serializedGrammar" : "pre 7/7/2020 16:08" },
"serializedGrammar" : "fau 7/29/2020 16:41" },
"instance" : {
} }
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ testGrammarParsesConstantReferencesInExpressions

startRule := #Expression.
self shouldParse: 'nil+3' to: #(Expression
(KeywordMessageSend
(KeywordMessageReceiver
(BinaryMessageSend
(BinaryMessageReceiver (UnaryMessageSend (UnaryMessageSend_base (Operand (Literal 'nil')))))
(BinaryMessage '+3')))
(_list)))
(Expression_base
(KeywordMessageSend
(KeywordMessageReceiver
(BinaryMessageSend
(BinaryMessageReceiver (UnaryMessageSend (UnaryMessageSend_base (Operand (Literal 'nil')))))
(BinaryMessage '+3')))
(_list))))
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ testGrammarParsesUnaryMessageSendsWithProblematicOperand
startRule := #Expression.
self
shouldParse: '2negated' to: #(Expression
#(KeywordMessageSend
#(KeywordMessageReceiver
#(BinaryMessageSend
#(BinaryMessageReceiver
#(UnaryMessageSend
#(UnaryMessageSend_message
#(UnaryMessageReceiver #(Operand '2'))
#(UnaryMessage 'negated'))))))
#(_list)));
#(Expression_base
#(KeywordMessageSend
#(KeywordMessageReceiver
#(BinaryMessageSend
#(BinaryMessageReceiver
#(UnaryMessageSend
#(UnaryMessageSend_message
#(UnaryMessageReceiver #(Operand '2'))
#(UnaryMessage 'negated'))))))
#(_list))));
shouldParse: 'falseNegated' to: #(Expression
#(KeywordMessageSend
#(KeywordMessageReceiver
#(BinaryMessageSend
#(BinaryMessageReceiver
#(UnaryMessageSend
#(UnaryMessageSend_base
#(Operand 'falseNegated'))))))
#(_list)))
#(Expression_base
#(KeywordMessageSend
#(KeywordMessageReceiver
#(BinaryMessageSend
#(BinaryMessageReceiver
#(UnaryMessageSend
#(UnaryMessageSend_base
#(Operand 'falseNegated'))))))
#(_list))))


Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"testGrammarDistinguishesOperandAndUnaryCascades" : "pre 7/28/2020 16:13",
"testGrammarParsesBinaryMessageChains" : "pre 7/6/2020 12:28",
"testGrammarParsesCascadedMessages" : "pre 7/10/2020 13:53",
"testGrammarParsesConstantReferencesInExpressions" : "pre 7/6/2020 15:23",
"testGrammarParsesConstantReferencesInExpressions" : "fau 7/30/2020 14:51",
"testGrammarParsesUnaryMessageChains" : "pre 7/6/2020 12:28",
"testGrammarParsesUnaryMessageSendsWithProblematicOperand" : "pre 6/10/2020 18:14" } }
"testGrammarParsesUnaryMessageSendsWithProblematicOperand" : "fau 7/30/2020 14:50" } }