Skip to content

Commit

Permalink
Run go fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
trhodeos committed Feb 24, 2018
1 parent 01583e7 commit c474ec2
Showing 1 changed file with 56 additions and 52 deletions.
108 changes: 56 additions & 52 deletions spicy.go
Original file line number Diff line number Diff line change
@@ -1,94 +1,98 @@
package main

import (
"encoding/json"
"encoding/json"

"os"
"os"

"github.com/alecthomas/participle"
"github.com/alecthomas/participle"
)

type Constant struct {
Symbol string ` @Ident`
Int int `| @Int`
Symbol string ` @Ident`
Int int `| @Int`
}

type Flag struct {
Boot bool ` @"BOOT"`
Object bool `| @"OBJECT"`
Raw bool `| @"RAW"`
Boot bool ` @"BOOT"`
Object bool `| @"OBJECT"`
Raw bool `| @"RAW"`
}

type Summand struct {
Lhs *Constant ` @@`
Op string `[ @("+" | "-")`
Rhs *Constant ` @@ ]`
}
Lhs *Constant ` @@`
Op string `[ @("+" | "-")`
Rhs *Constant ` @@ ]`
}

type MaxSegment struct {
First string `"max[" @String ","`
Second string `@String "]"`
First string `"max[" @String ","`
Second string `@String "]"`
}

type MinSegment struct {
First string `"min[" @String ","`
Second string `@String "]"`
First string `"min[" @String ","`
Second string `@String "]"`
}

// Only one of these values will be set.
type Value struct {
String string ` @String`
Flags []*Flag `| @@ { @@ }`
ConstantValue *Summand `| @@`
MaxSegment *MaxSegment `| @@`
MinSegment *MinSegment `| @@`
String string ` @String`
Flags []*Flag `| @@ { @@ }`
ConstantValue *Summand `| @@`
MaxSegment *MaxSegment `| @@`
MinSegment *MinSegment `| @@`
}

type Statement struct {
/*
:name <segmentName>
|address <constant>
|after <segmentName>
|after max[<segmentName>,<segmentName>]
|after min[<segmentName>,<segmentName>]
|include <filename>
|maxsize <constant>
|align <constant>
|flags <flagList>
|number <constant>
|entry <symbol>
|stack <stackValue>
*/
// I tried using @Ident here, but the parser was greedily taking 'endseg' as name.
// By explicitly listing all known names here, we limit the search space.
Name string `@("name" | "address" | "after" | "include" | "maxsize" | "align" | "flags" | "number" | "entry" | "stack")`
Value Value `@@`
/*
:name <segmentName>
|address <constant>
|after <segmentName>
|after max[<segmentName>,<segmentName>]
|after min[<segmentName>,<segmentName>]
|include <filename>
|maxsize <constant>
|align <constant>
|flags <flagList>
|number <constant>
|entry <symbol>
|stack <stackValue>
*/
// I tried using @Ident here, but the parser was greedily taking 'endseg' as name.
// By explicitly listing all known names here, we limit the search space.
Name string `@("name" | "address" | "after" | "include" | "maxsize" | "align" | "flags" | "number" | "entry" | "stack")`
Value Value `@@`
}

type Statements struct {
Statements []*Statement `{ @@ }`
Statements []*Statement `{ @@ }`
}

type Segment struct {
StatementList Statements `"beginseg" @@ "endseg"`
StatementList Statements `"beginseg" @@ "endseg"`
}

type Wave struct {
StatementList Statements `"beginwave" @@ "endwave"`
StatementList Statements `"beginwave" @@ "endwave"`
}

type Spec struct {
SegmentList []*Segment `{ @@ }`
WaveList []*Wave `{ @@ }`
SegmentList []*Segment `{ @@ }`
WaveList []*Wave `{ @@ }`
}

func main() {
parser, err := participle.Build(&Spec{}, nil)
if err != nil { panic(err) }

spec := &Spec{}
err = parser.Parse(os.Stdin, spec)
if err != nil { panic(err) }

json.NewEncoder(os.Stdout).Encode(spec)
parser, err := participle.Build(&Spec{}, nil)
if err != nil {
panic(err)
}

spec := &Spec{}
err = parser.Parse(os.Stdin, spec)
if err != nil {
panic(err)
}

json.NewEncoder(os.Stdout).Encode(spec)
}

0 comments on commit c474ec2

Please sign in to comment.