From 56a3ca509a7b81c74d6f512dd922536f0bd21714 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 11 Oct 2022 11:12:37 -0400 Subject: [PATCH 1/7] Rewrote func test case --- parser/func_test.go | 10 ++++++++++ tests/parser/func/main.arf | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/parser/func_test.go b/parser/func_test.go index 09c9e53..18faa49 100644 --- a/parser/func_test.go +++ b/parser/func_test.go @@ -105,5 +105,15 @@ func ro hDataInit [= y:{Int} [loc x]] [= z:Int:8 (398 9 2309 983 -2387 478 555 123)] [= bird:Bird ((99999) 324)] +func ro iDereference + > w:Face + > x:{Int} + > y:{Int ..} + > z:Int:4 + --- + = a:Int {w Int} + = b:Int {x} + = c:Int {y 4} + = d:Int {z 3} `, test) } diff --git a/tests/parser/func/main.arf b/tests/parser/func/main.arf index b8ed2d3..7e3d6de 100644 --- a/tests/parser/func/main.arf +++ b/tests/parser/func/main.arf @@ -132,3 +132,14 @@ func ro hDataInit = bird:Bird ( (99999) 324) + +func ro iDereference + > w:Face + > x:{Int} + > y:{Int ..} + > z:Int:4 + --- + = a:Int {w Int} + = b:Int {x} + = c:Int {y 4} + = d:Int {z 3} From 746fda68434cc2e6f2169d645dd32fa86196a67a Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 11 Oct 2022 11:15:16 -0400 Subject: [PATCH 2/7] No we don't want that --- parser/func_test.go | 2 -- tests/parser/func/main.arf | 2 -- 2 files changed, 4 deletions(-) diff --git a/parser/func_test.go b/parser/func_test.go index 18faa49..f34aed9 100644 --- a/parser/func_test.go +++ b/parser/func_test.go @@ -106,12 +106,10 @@ func ro hDataInit [= z:Int:8 (398 9 2309 983 -2387 478 555 123)] [= bird:Bird ((99999) 324)] func ro iDereference - > w:Face > x:{Int} > y:{Int ..} > z:Int:4 --- - = a:Int {w Int} = b:Int {x} = c:Int {y 4} = d:Int {z 3} diff --git a/tests/parser/func/main.arf b/tests/parser/func/main.arf index 7e3d6de..a800719 100644 --- a/tests/parser/func/main.arf +++ b/tests/parser/func/main.arf @@ -134,12 +134,10 @@ func ro hDataInit 324) func ro iDereference - > w:Face > x:{Int} > y:{Int ..} > z:Int:4 --- - = a:Int {w Int} = b:Int {x} = c:Int {y 4} = d:Int {z 3} From 1cd7511ced868f12d843ecae2516af37f1f54049 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 11 Oct 2022 11:23:50 -0400 Subject: [PATCH 3/7] Add dereference to tree --- parser/tree-tostring.go | 13 +++++++++++++ parser/tree.go | 13 ++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/parser/tree-tostring.go b/parser/tree-tostring.go index 157e3ca..2db8f60 100644 --- a/parser/tree-tostring.go +++ b/parser/tree-tostring.go @@ -133,6 +133,9 @@ func (argument Argument) ToString (indent int, breakLine bool) (output string) { case ArgumentKindList: output += argument.value.(List).ToString(indent, breakLine) + + case ArgumentKindDereference: + output += argument.value.(Dereference).ToString(indent) case ArgumentKindIdentifier: output += doIndent ( @@ -276,6 +279,16 @@ func (behavior FaceBehavior) ToString (indent int) (output string) { return } +func (dereference Dereference) ToString (indent int) (output string) { + output += "{" + output += dereference.argument.ToString(indent, false) + if dereference.offset != 0 { + output += fmt.Sprint(" ", dereference.offset) + } + output += "}" + return +} + func (phrase Phrase) ToString (indent int, ownLine bool) (output string) { if ownLine { output += doIndent(indent) diff --git a/parser/tree.go b/parser/tree.go index 0b3f09f..92bfb34 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -97,10 +97,8 @@ const ( ArgumentKindList // {name} - ArgumentKindDereference - // {name 23} - ArgumentKindSubscript + ArgumentKindDereference // name.name // name.name.name @@ -220,6 +218,15 @@ type FaceSection struct { FaceBehavior } +// Dereference represents a pointer dereference or array subscript. +type Dereference struct { + locatable + valuable + + // if a simple dereference was parsed, this should just be zero. + offset int +} + // PhraseKind determines what semantic role a phrase plays. type PhraseKind int From fae8bedfa9aca57204b40e46885a764e7637c2d8 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 11 Oct 2022 11:31:44 -0400 Subject: [PATCH 4/7] Dereference parsing stub --- parser/argument.go | 9 +++++++-- parser/dereference.go | 12 ++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 parser/dereference.go diff --git a/parser/argument.go b/parser/argument.go index 1185ec0..d07792e 100644 --- a/parser/argument.go +++ b/parser/argument.go @@ -3,7 +3,7 @@ package parser import "git.tebibyte.media/arf/arf/lexer" import "git.tebibyte.media/arf/arf/infoerr" -// TODO: add support for dereferences and subscripts +// TODO: add support for dereferences and subscripts (currently being worked on) var validArgumentStartTokens = []lexer.TokenKind { lexer.TokenKindName, @@ -14,6 +14,7 @@ var validArgumentStartTokens = []lexer.TokenKind { lexer.TokenKindString, lexer.TokenKindLBracket, + lexer.TokenKindLBrace, lexer.TokenKindLParen, } @@ -78,9 +79,13 @@ func (parser *ParsingOperation) parseArgument () (argument Argument, err error) parser.nextToken() case lexer.TokenKindLBracket: - argument.kind = ArgumentKindPhrase + argument.kind = ArgumentKindPhrase argument.value, err = parser.parseArgumentLevelPhrase() + case lexer.TokenKindLBrace: + argument.kind = ArgumentKindDereference + argument.value, err = parser.parseDereference() + case lexer.TokenKindLParen: argument.kind = ArgumentKindList argument.value, err = parser.parseList() diff --git a/parser/dereference.go b/parser/dereference.go new file mode 100644 index 0000000..ce132cf --- /dev/null +++ b/parser/dereference.go @@ -0,0 +1,12 @@ +package parser + +// import "git.tebibyte.media/arf/arf/lexer" +// import "git.tebibyte.media/arf/arf/infoerr" + +func (parser *ParsingOperation) parseDereference () ( + dereference Dereference, + err error, +) { + // TODO + return +} From a7588f7416c180ecd1d3c31fca715ef2de98ab29 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 11 Oct 2022 13:31:17 -0400 Subject: [PATCH 5/7] Added untested dereference parsing --- parser/dereference.go | 24 ++++++++++++++++++++++-- parser/tree.go | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/parser/dereference.go b/parser/dereference.go index ce132cf..55d55e5 100644 --- a/parser/dereference.go +++ b/parser/dereference.go @@ -1,12 +1,32 @@ package parser -// import "git.tebibyte.media/arf/arf/lexer" +import "git.tebibyte.media/arf/arf/lexer" // import "git.tebibyte.media/arf/arf/infoerr" func (parser *ParsingOperation) parseDereference () ( dereference Dereference, err error, ) { - // TODO + err = parser.expect(lexer.TokenKindLBrace) + if err != nil { return } + dereference.location = parser.token.Location() + + // parse the value we are dereferencing + err = parser.nextToken(validArgumentStartTokens...) + if err != nil { return } + dereference.argument, err = parser.parseArgument() + if err != nil { return } + + // if there is an offset, parse it + err = parser.expect(lexer.TokenKindUInt, lexer.TokenKindLBrace) + if err != nil { return } + if parser.token.Is(lexer.TokenKindUInt) { + dereference.offset = parser.token.Value().(uint64) + } + + err = parser.nextToken(lexer.TokenKindLBrace) + if err != nil { return } + err = parser.nextToken() + if err != nil { return } return } diff --git a/parser/tree.go b/parser/tree.go index 92bfb34..64c4f01 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -224,7 +224,7 @@ type Dereference struct { valuable // if a simple dereference was parsed, this should just be zero. - offset int + offset uint64 } // PhraseKind determines what semantic role a phrase plays. From 49e834860faf8554375e90d6aaa37c9d1cf687d9 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 11 Oct 2022 13:35:11 -0400 Subject: [PATCH 6/7] Fixed dereference parsing --- parser/dereference.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/parser/dereference.go b/parser/dereference.go index 55d55e5..3d8d550 100644 --- a/parser/dereference.go +++ b/parser/dereference.go @@ -1,7 +1,6 @@ package parser import "git.tebibyte.media/arf/arf/lexer" -// import "git.tebibyte.media/arf/arf/infoerr" func (parser *ParsingOperation) parseDereference () ( dereference Dereference, @@ -18,13 +17,13 @@ func (parser *ParsingOperation) parseDereference () ( if err != nil { return } // if there is an offset, parse it - err = parser.expect(lexer.TokenKindUInt, lexer.TokenKindLBrace) + err = parser.expect(lexer.TokenKindUInt, lexer.TokenKindRBrace) if err != nil { return } if parser.token.Is(lexer.TokenKindUInt) { dereference.offset = parser.token.Value().(uint64) } - err = parser.nextToken(lexer.TokenKindLBrace) + err = parser.nextToken(lexer.TokenKindRBrace) if err != nil { return } err = parser.nextToken() if err != nil { return } From cdebedb8399c49ebd148032c1921eb6ef06a6372 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 11 Oct 2022 13:36:11 -0400 Subject: [PATCH 7/7] Fixed test case --- parser/argument.go | 2 -- parser/func_test.go | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/parser/argument.go b/parser/argument.go index d07792e..2f83ecc 100644 --- a/parser/argument.go +++ b/parser/argument.go @@ -3,8 +3,6 @@ package parser import "git.tebibyte.media/arf/arf/lexer" import "git.tebibyte.media/arf/arf/infoerr" -// TODO: add support for dereferences and subscripts (currently being worked on) - var validArgumentStartTokens = []lexer.TokenKind { lexer.TokenKindName, diff --git a/parser/func_test.go b/parser/func_test.go index f34aed9..dabbf4e 100644 --- a/parser/func_test.go +++ b/parser/func_test.go @@ -110,8 +110,8 @@ func ro iDereference > y:{Int ..} > z:Int:4 --- - = b:Int {x} - = c:Int {y 4} - = d:Int {z 3} + [= b:Int {x}] + [= c:Int {y 4}] + [= d:Int {z 3}] `, test) }