Compare commits

...

3 Commits

Author SHA1 Message Date
Sasha Koshka 82093865b0 wip 2022-10-19 13:27:48 -04:00
Sasha Koshka 8b4fee50ab Literals call themselves literals instead of arg 2022-10-18 23:39:07 -04:00
Sasha Koshka 6dfde851e5 Add cast phrase kind to parser 2022-10-18 23:32:15 -04:00
10 changed files with 84 additions and 31 deletions

View File

@ -6,15 +6,15 @@ func TestDataSection (test *testing.T) {
checkTree ("../tests/analyzer/dataSection", false,
`dataSection ro ../tests/analyzer/dataSection.aBasicInt
type 1 basic Int
arg uint 5
uintLiteral 5
dataSection ro ../tests/analyzer/dataSection.bRune
type 1 basic Int
arg string 'A'
stringLiteral 'A'
dataSection ro ../tests/analyzer/dataSection.cString
type 1 basic String
arg string 'A very large bird'
stringLiteral 'A very large bird'
dataSection ro ../tests/analyzer/dataSection.dCharBuffer
type 32 basic U8
arg string 'A very large bird` + "\000" + `'
stringLiteral 'A very large bird` + "\000" + `'
`, test)
}

View File

@ -5,40 +5,40 @@ import "testing"
func TestEnumSection (test *testing.T) {
checkTree ("../tests/analyzer/enumSection", false,
`enumSection ro ../tests/analyzer/enumSection.aWeekday
arg uint 1
uintLiteral 1
type 1 basic Int
member sunday
arg uint 1
uintLiteral 1
member monday
arg uint 2
uintLiteral 2
member tuesday
arg uint 3
uintLiteral 3
member wednesday
arg uint 4
uintLiteral 4
member thursday
arg uint 5
uintLiteral 5
member friday
arg uint 6
uintLiteral 6
member saturday
arg uint 7
uintLiteral 7
typeSection ro ../tests/analyzer/enumSection.bColor
type 1 basic U32
enumSection ro ../tests/analyzer/enumSection.cNamedColor
arg uint 16711680
uintLiteral 16711680
type 1 basic bColor
member red
arg uint 16711680
uintLiteral 16711680
member green
arg uint 65280
uintLiteral 65280
member blue
arg uint 255
uintLiteral 255
enumSection ro ../tests/analyzer/enumSection.dFromFarAway
arg uint 5
uintLiteral 5
type 1 basic dInheritFromOther
member bird
arg uint 5
uintLiteral 5
member bread
arg uint 4
uintLiteral 4
typeSection ro ../tests/analyzer/typeSection/required.aBasic
type 1 basic Int
typeSection ro ../tests/analyzer/typeSection.dInheritFromOther

View File

@ -1,3 +1,15 @@
package analyzer
// TODO
// FuncSection represents a type definition section.
type FuncSection struct {
sectionBase
}
func (analyzer *analysisOperation) analyzeFuncSection () (
section Section,
err error,
) {
return
}

View File

@ -6,12 +6,14 @@ func TestFuncSection (test *testing.T) {
checkTree ("../tests/analyzer/funcSection", false,
`
typeSection ro ../tests/analyzer/funcSection.aCString
type 1 pointer {Int}
type 1 pointer {
type 1 basic U8
}
funcSection ro ../tests/analyzer/funcSection.bArbitrary
block
arbitraryPhrase
command 'puts'
cast
castPhrase
type aCString
arg string 'hellorld` + "\000" + `'
`, test)

View File

@ -28,7 +28,7 @@ type StringLiteral struct {
// ToString outputs the data in the argument as a string.
func (literal IntLiteral) ToString (indent int) (output string) {
output += doIndent(indent, fmt.Sprint("arg int ", literal.value, "\n"))
output += doIndent(indent, fmt.Sprint("intLiteral ", literal.value, "\n"))
return
}
@ -71,7 +71,7 @@ func (literal IntLiteral) canBePassedAs (what Type) (allowed bool) {
// ToString outputs the data in the argument as a string.
func (literal UIntLiteral) ToString (indent int) (output string) {
output += doIndent(indent, fmt.Sprint("arg uint ", literal.value, "\n"))
output += doIndent(indent, fmt.Sprint("uintLiteral ", literal.value, "\n"))
return
}
@ -120,7 +120,7 @@ func (literal FloatLiteral) What () (what Type) {
// ToString outputs the data in the argument as a string.
func (literal FloatLiteral) ToString (indent int) (output string) {
output += doIndent(indent, fmt.Sprint("arg float ", literal.value, "\n"))
output += doIndent(indent, fmt.Sprint("floatLiteral ", literal.value, "\n"))
return
}
@ -170,7 +170,7 @@ func (literal StringLiteral) What () (what Type) {
// ToString outputs the data in the argument as a string.
func (literal StringLiteral) ToString (indent int) (output string) {
output += doIndent(indent, fmt.Sprint("arg string '", literal.value, "'\n"))
output += doIndent(indent, fmt.Sprint("stringLiteral '", literal.value, "'\n"))
return
}

View File

@ -70,3 +70,9 @@ func (section sectionBase) locator () (where locator) {
where = section.where
return
}
// phraseBase is a struct that all phrases must embed.
type phraseBase struct {
locatable
returnsTo []Argument
}

30
analyzer/phrase.go Normal file
View File

@ -0,0 +1,30 @@
package analyzer
import "git.tebibyte.media/arf/arf/parser"
type Phrase interface {
}
type ArbitraryPhrase struct {
phraseBase
command string
arguments []Argument
}
type CastPhrase struct {
phraseBase
command Argument
arguments []Argument
}
// TODO more phrases lol
func (analyzer *analysisOperation) analyzePhrase (
inputPhrase parser.Phrase,
) (
phrase Phrase,
err error,
) {
return
}

View File

@ -10,10 +10,10 @@ typeSection ro ../tests/analyzer/typeSection/required.bBird
type 1 basic Obj
member rw wing
type 1 basic Int
arg uint 2
uintLiteral 2
typeSection ro ../tests/analyzer/typeSection.aBasicInt
type 1 basic Int
arg uint 5
uintLiteral 5
typeSection ro ../tests/analyzer/typeSection.bOnBasicInt
type 1 basic aBasicInt
typeSection ro ../tests/analyzer/typeSection.cBasicObject
@ -28,15 +28,15 @@ typeSection ro ../tests/analyzer/typeSection.eInheritObject
type 1 basic cBasicObject
member ro that
type 1 basic UInt
arg uint 5
uintLiteral 5
typeSection ro ../tests/analyzer/typeSection.fInheritObjectFromOther
type 1 basic bBird
member ro wing
type 1 basic Int
arg uint 2
uintLiteral 2
member ro beak
type 1 basic Int
arg uint 238
uintLiteral 238
typeSection ro ../tests/analyzer/typeSection.gPointer
type 1 pointer {
type 1 basic Int

View File

@ -314,6 +314,8 @@ func (parser *parsingOperation) parsePhraseCommand () (
switch identifier.trail[0] {
case "loc":
kind = PhraseKindReference
case "cast":
kind = PhraseKindCast
case "defer":
kind = PhraseKindDefer
case "if":

View File

@ -236,6 +236,7 @@ const (
PhraseKindOperator
PhraseKindAssign
PhraseKindReference
PhraseKindCast
PhraseKindDefer
PhraseKindIf
PhraseKindElseIf