Skip to content

Commit

Permalink
unify name-y things in grammar
Browse files Browse the repository at this point in the history
This commit unifies the various types of named things in the PEG grammar
to a single pattern called ast.Name and gets rid of ast.String and
ast.QuotedString.  Now that the locators are all computed from the
underlying rule, we can easily have a single ast.Name that represents
different variations of names.  These changes will be used by a subequent PR
that will unify the get/file/pool operators into a single "from", which
is in turn needed by the upcoming SuperSQL additions.
  • Loading branch information
mccanne committed Oct 26, 2024
1 parent 7d8195e commit dafe1b4
Show file tree
Hide file tree
Showing 14 changed files with 2,644 additions and 2,695 deletions.
52 changes: 21 additions & 31 deletions compiler/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,14 @@ type Glob struct {
Loc `json:"loc"`
}

type QuotedString struct {
Kind string `json:"kind" unpack:""`
Text string `json:"text"`
Loc `json:"loc"`
}

type Regexp struct {
Kind string `json:"kind" unpack:""`
Pattern string `json:"pattern"`
PatternPos int `json:"pattern_pos"`
Loc `json:"loc"`
}

type String struct {
type Name struct {
Kind string `json:"kind" unpack:""`
Text string `json:"text"`
Loc `json:"loc"`
Expand All @@ -155,10 +149,9 @@ type Pattern interface {
PatternAST()
}

func (*Glob) PatternAST() {}
func (*QuotedString) PatternAST() {}
func (*Regexp) PatternAST() {}
func (*String) PatternAST() {}
func (*Glob) PatternAST() {}
func (*Regexp) PatternAST() {}
func (*Name) PatternAST() {}

type RecordExpr struct {
Kind string `json:"kind" unpack:""`
Expand All @@ -173,7 +166,7 @@ type RecordElem interface {

type FieldExpr struct {
Kind string `json:"kind" unpack:""`
Name string `json:"name"`
Name *Name `json:"name"`
Value Expr `json:"value"`
Loc `json:"loc"`
}
Expand Down Expand Up @@ -397,10 +390,9 @@ type (
Loc `json:"loc"`
}
Tail struct {
Kind string `json:"kind" unpack:""`
KeywordPos int `json:"keyword_pos"`
Count Expr `json:"count"`
Loc `json:"loc"`
Kind string `json:"kind" unpack:""`
Count Expr `json:"count"`
Loc `json:"loc"`
}
Pass struct {
Kind string `json:"kind" unpack:""`
Expand All @@ -412,9 +404,7 @@ type (
Loc `json:"loc"`
}
Summarize struct {
Kind string `json:"kind" unpack:""`
// StartPos is not called KeywordPos for Summarize since the "summarize"
// keyword is optional.
Kind string `json:"kind" unpack:""`
Limit int `json:"limit"`
Keys Assignments `json:"keys"`
Aggs Assignments `json:"aggs"`
Expand Down Expand Up @@ -509,17 +499,17 @@ type (
}
Load struct {
Kind string `json:"kind" unpack:""`
Pool string `json:"pool"` // ast.String etc
Branch string `json:"branch"`
Author string `json:"author"`
Message string `json:"message"`
Meta string `json:"meta"`
Pool *Name `json:"pool"`
Branch *Name `json:"branch"`
Author *Name `json:"author"`
Message *Name `json:"message"`
Meta *Name `json:"meta"`
Loc `json:"loc"`
}
Assert struct {
Kind string `json:"kind" unpack:""`
Expr Expr `json:"expr"`
Text string `json:"text"` //XXX text?
Text string `json:"text"`
Loc `json:"loc"`
}
Output struct {
Expand All @@ -540,18 +530,18 @@ type (
File struct {
Kind string `json:"kind" unpack:""`
Path Pattern `json:"path"`
Format string `json:"format"`
Format *Name `json:"format"`
SortKeys []SortExpr `json:"sort_keys"`
Loc `json:"loc"`
}
HTTP struct {
Kind string `json:"kind" unpack:""`
URL Pattern `json:"url"`
Format string `json:"format"`
Format *Name `json:"format"`
SortKeys []SortExpr `json:"sort_keys"`
Method string `json:"method"`
Method *Name `json:"method"`
Headers *RecordExpr `json:"headers"`
Body string `json:"body"`
Body *Name `json:"body"`
Loc `json:"loc"`
}
Pool struct {
Expand All @@ -567,8 +557,8 @@ type (

type PoolSpec struct {
Pool Pattern `json:"pool"`
Commit string `json:"commit"`
Meta string `json:"meta"`
Commit *Name `json:"commit"`
Meta *Name `json:"meta"`
Tap bool `json:"tap"`
Loc `json:"loc"`
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/ast/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ var unpacker = unpack.New(
Pool{},
Primitive{},
Put{},
QuotedString{},
Record{},
Agg{},
Regexp{},
Expand All @@ -70,7 +69,7 @@ var unpacker = unpack.New(
Spread{},
SliceExpr{},
Sort{},
String{},
Name{},
OpDecl{},
Switch{},
Tail{},
Expand Down
Loading

0 comments on commit dafe1b4

Please sign in to comment.