Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix grammar merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsharp committed May 26, 2018
1 parent f4e5b14 commit ec9085b
Showing 1 changed file with 0 additions and 183 deletions.
183 changes: 0 additions & 183 deletions src/braid/ast/braid.peg
Original file line number Diff line number Diff line change
@@ -1,189 +1,6 @@
{
package ast

type ValueType int

const (
STRING = iota
INT
FLOAT
BOOL
CHAR
CONTAINER
NIL
)

type BasicAst struct {
Type string
StringValue string
CharValue rune
BoolValue bool
IntValue int
FloatValue float64
ValueType ValueType
Subvalues []Ast
}

type Func struct {
Arguments []Ast
ValueType ValueType
Subvalues []Ast
}

type Call struct {
Module Ast
Function Ast
Arguments []Ast
ValueType ValueType
}

type If struct {
Condition Ast
Then []Ast
Else []Ast
}

type Assignment struct {
Left []Ast
Right Ast
}

type Ast interface {
Print(indent int) string
}

func (a BasicAst) String() string {
switch (a.ValueType){
case STRING:
return fmt.Sprintf("\"%s\"", a.StringValue)
case CHAR:
return fmt.Sprintf("'%s'", string(a.CharValue))
case INT:
return fmt.Sprintf("%d", a.IntValue)
case FLOAT:
return fmt.Sprintf("%f", a.FloatValue)
}
return "()"
}

func (a BasicAst) Print(indent int) string {
str := ""

for i := 0; i < indent; i++ {
str += " "
}
str += fmt.Sprintf("%s %s:\n", a.Type, a)
for _, el := range(a.Subvalues){
str += el.Print(indent+1)
}
return str
}

func (a Func) String() string {
return "Func"
}

func (i If) String() string {
return "If"
}

func (a Func) Print(indent int) string {
str := ""

for i := 0; i < indent; i++ {
str += " "
}
str += "Func"
if len(a.Arguments) > 0 {
str += " (\n"
for _, el := range(a.Arguments){
str += el.Print(indent + 1)
}
for i := 0; i < indent; i++ {
str += " "
}
str += ")\n"
}
for _, el := range(a.Subvalues){
str += el.Print(indent+1)
}
return str
}

func (a Call) Print(indent int) string {
str := ""

for i := 0; i < indent; i++ {
str += " "
}
str += "Call:\n"
if a.Module.(BasicAst).Type != "" {
str += a.Module.Print(indent + 1)
}
str += a.Function.Print(indent + 1)

if len(a.Arguments) > 0 {
for i := 0; i < indent; i++ {
str += " "
}
str += "(\n"
for _, el := range(a.Arguments){
str += el.Print(indent + 1)
}
for i := 0; i < indent; i++ {
str += " "
}
str += ")\n"
}
return str
}

func (i If) Print(indent int) string {
str := ""

for i := 0; i < indent; i++ {
str += " "
}
str += "If"
if i.Condition != nil {
str += ":\n"
str += i.Condition.Print(indent + 1)

}
for _, el := range(i.Then){
for i := 0; i < indent; i++ {
str += " "
}
str += "Then:\n"
str += el.Print(indent+1)
}
for _, el := range(i.Else){
for i := 0; i < indent; i++ {
str += " "
}
str += "Else:\n"
str += el.Print(indent+1)

}
return str
}

func (a Assignment) Print(indent int) string {
str := ""

for i := 0; i < indent; i++ {
str += " "
}
str += "Assignment:\n"

for _, el := range(a.Left){
str += el.Print(indent+1)
}
str += a.Right.Print(indent+1)

return str
}

func toIfaceSlice(v interface{}) []interface{} {
if v == nil {
return nil
Expand Down

0 comments on commit ec9085b

Please sign in to comment.