aboutsummaryrefslogtreecommitdiff
path: root/spec/parser.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-03-28 01:30:49 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-03-28 01:45:11 +0900
commit1746609e248151d575f6e3913ad5023fd421bfff (patch)
tree9312ac986191b3798125e2d3cc41518601d9b9e2 /spec/parser.go
parentFollow golangci-lint (diff)
downloadurubu-1746609e248151d575f6e3913ad5023fd421bfff.tar.gz
urubu-1746609e248151d575f6e3913ad5023fd421bfff.tar.xz
Simplify the syntax of #ast directive
This change allows using the simple syntax of the directive like `#ast $1 $3...` instead of `#ast #(foo $1 $3...)`.
Diffstat (limited to 'spec/parser.go')
-rw-r--r--spec/parser.go56
1 files changed, 13 insertions, 43 deletions
diff --git a/spec/parser.go b/spec/parser.go
index 7f3d8f7..a453538 100644
--- a/spec/parser.go
+++ b/spec/parser.go
@@ -49,19 +49,13 @@ type DirectiveNode struct {
}
type ParameterNode struct {
- ID string
- String string
- Tree *TreeStructNode
- Pos Position
+ ID string
+ String string
+ SymbolPosition *SymbolPositionNode
+ Pos Position
}
-type TreeStructNode struct {
- Name string
- Children []*TreeChildNode
- Pos Position
-}
-
-type TreeChildNode struct {
+type SymbolPositionNode struct {
Position int
Expansion bool
Pos Position
@@ -449,41 +443,17 @@ func (p *parser) parseParameter() *ParameterNode {
String: p.lastTok.text,
Pos: p.lastTok.pos,
}
- case p.consume(tokenKindTreeNodeOpen):
- if !p.consume(tokenKindID) {
- raiseSyntaxError(p.pos.Row, synErrTreeInvalidFirstElem)
- }
- name := p.lastTok.text
- namePos := p.lastTok.pos
-
- var children []*TreeChildNode
- for {
- if !p.consume(tokenKindPosition) {
- break
- }
-
- child := &TreeChildNode{
- Position: p.lastTok.num,
- Pos: p.lastTok.pos,
- }
- if p.consume(tokenKindExpantion) {
- child.Expansion = true
- }
-
- children = append(children, child)
+ case p.consume(tokenKindPosition):
+ symPos := &SymbolPositionNode{
+ Position: p.lastTok.num,
+ Pos: p.lastTok.pos,
}
-
- if !p.consume(tokenKindTreeNodeClose) {
- raiseSyntaxError(p.pos.Row, synErrTreeUnclosed)
+ if p.consume(tokenKindExpantion) {
+ symPos.Expansion = true
}
-
return &ParameterNode{
- Tree: &TreeStructNode{
- Name: name,
- Children: children,
- Pos: namePos,
- },
- Pos: namePos,
+ SymbolPosition: symPos,
+ Pos: symPos.Pos,
}
}