Skip to content

Commit

Permalink
Output peg header comments to go file (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
pointlander authored Nov 30, 2024
1 parent bd929c4 commit 36333de
Show file tree
Hide file tree
Showing 9 changed files with 1,070 additions and 893 deletions.
3 changes: 3 additions & 0 deletions grammars/c/c.peg
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
# A.2.4 External definitions
#-------------------------------------------------------------------------

#go:build grammars
# +build grammars

package main

type C Peg {
Expand Down
3 changes: 3 additions & 0 deletions grammars/calculator/calculator.peg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

#go:build grammars
# +build grammars

package main

type Calculator Peg {
Expand Down
3 changes: 3 additions & 0 deletions grammars/calculator_ast/calculator.peg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

#go:build grammars
# +build grammars

package main

type Calculator Peg {
Expand Down
5 changes: 5 additions & 0 deletions grammars/fexl/fexl.peg
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# fexl

#go:build grammars
# +build grammars

package main

type Fexl Peg {
Expand Down
3 changes: 3 additions & 0 deletions grammars/java/java_1_7.peg
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
# Compilation Unit
#-------------------------------------------------------------------------

#go:build grammars
# +build grammars

package main

type Java Peg {
Expand Down
3 changes: 3 additions & 0 deletions grammars/long_test/long.peg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

#go:build grammars
# +build grammars

package main

type Long Peg {
Expand Down
5 changes: 4 additions & 1 deletion peg.peg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Peg Peg {
}

# Hierarchical syntax
Grammar <- Spacing 'package' MustSpacing Identifier { p.AddPackage(text) }
Grammar <- Header 'package' MustSpacing Identifier { p.AddPackage(text) }
Import*
'type' MustSpacing Identifier { p.AddPeg(text) }
'Peg' Spacing Action { p.AddState(text) }
Expand Down Expand Up @@ -118,6 +118,9 @@ Spacing <- SpaceComment*
MustSpacing <- SpaceComment+
Comment <- ('#' / '//') (!EndOfLine .)* EndOfLine
Space <- ' ' / '\t' / EndOfLine
Header <- HeaderSpaceComment*
HeaderSpaceComment <- (HeaderComment / <Space+> { p.AddSpace(text) } )
HeaderComment <- ('#' / '//') <(!EndOfLine .)*> { p.AddComment(text) } EndOfLine
EndOfLine <- '\r\n' / '\n' / '\r'
EndOfFile <- !.
Action <- '{' < ActionBody* > '}' Spacing
Expand Down
Loading

0 comments on commit 36333de

Please sign in to comment.