Skip to content

Commit

Permalink
more WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
bd82 committed Aug 2, 2018
1 parent 6f635cb commit 263cc7c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 deletions.
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 82 additions & 9 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,27 +197,88 @@ class AstBuilderVisitor extends BaseVisitor {
if (ctx.Variable) {
return this.visit(ctx.Variable)
} else if (ctx.IntValue) {
return "TBD"
return visitToken(ctx.IntValue, "IntValue")
} else if (ctx.FloatValue) {
return "TBD"
return visitToken(ctx.IntValue, "FloatValue")
} else if (ctx.StringValue) {
return "TBD"
return visitToken(ctx.IntValue, "StringValue")
} else if (ctx.BooleanValue) {
return this.visit(ctx.BooleanValue)
} else if (ctx.NullValue) {
return this.visit(ctx.NullValue)
} else if (ctx.EnumValue) {
return this.visit(ctx.EnumValue)
} else if (ctx.ListValue) {
return this.visit(ctx.ListValue)
} else if (ctx.ObjectValue) {
return this.visit(ctx.ObjectValue)
} else {
throw "None Exhaustive Match"
}
}

BooleanValue(ctx) {}
BooleanValue(ctx) {
let boolValue
if (ctx.True) {
boolValue = true
} else if (ctx.False) {
boolValue = false
} else {
throw "None Exhaustive Match"
}

return {
kind: "BooleanValue",
value: boolValue,
loc: "TBD"
}
}

NullValue(ctx) {}
NullValue(ctx) {
return {
kind: "null",
loc: "TBD"
}
}

EnumValue(ctx) {}
EnumValue(ctx) {
return visitToken(ctx.NameButNotTrueOrFalseOrNull, "EnumValue")
}

ListValue(ctx) {}
ListValue(ctx) {
let items = []
if (ctx.Value) {
items = ctx.Value.map(this.visit, this)
}

ObjectValue(ctx) {}
return {
kind: "ListValue",
definitions: items,
loc: "TBD"
}
}

ObjectField(ctx) {}
ObjectValue(ctx) {
let entries = []
if (ctx.ObjectField) {
entries = ctx.ObjectField.map(this.visit, this)
}

return {
kind: "ObjectValue",
definitions: entries,
loc: "TBD"
}
}

ObjectField(ctx) {
return {
kind: "ObjectField",
name: visitName(ctx.Name),
value: this.visit(ctx.Value),
loc: "TBD"
}
}

VariableDefinitions(ctx) {}

Expand Down Expand Up @@ -325,3 +386,15 @@ function visitName(nameToken) {
loc: "TBD"
}
}

function visitToken(tokCst, kind) {
if (tokCst === undefined) {
return undefined
}

return {
kind: kind,
value: tokCst[0].image,
loc: "TBD"
}
}

0 comments on commit 263cc7c

Please sign in to comment.