summaryrefslogtreecommitdiff
path: root/internal/generated
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-02-21 01:12:15 +0200
committerPaul Buetow <paul@buetow.org>2024-02-21 01:12:15 +0200
commit8e42437d2a0c32ccf2b3084533552cea7ca4ca05 (patch)
tree8f3c9d71731df510023c27d54892f9c05b311194 /internal/generated
parente1213c1c0e52348fffb47015237b88237a377081 (diff)
const types can have own type defs in Go
Diffstat (limited to 'internal/generated')
-rw-r--r--internal/generated/nqc.raku24
-rw-r--r--internal/generated/types/types.go11
2 files changed, 26 insertions, 9 deletions
diff --git a/internal/generated/nqc.raku b/internal/generated/nqc.raku
index a777ba1..ddbd086 100644
--- a/internal/generated/nqc.raku
+++ b/internal/generated/nqc.raku
@@ -24,14 +24,30 @@ grammar NQC {
}
class NQCToGoActions {
+ has Str @.const-types is required;
+
method TOP($/) {
- make "// This file was generated - don't change manually!\n" ~
- "package types\n\n" ~ $<construct>.map(*.made).join('')
+ make "// This file was generated - don't change manually!\n"
+ ~ "package types\n\n"
+ ~ @!const-types.map({ "type {self!const-camel-case($_)} int\n" })
+ ~ $<construct>.map(*.made).join('')
}
method construct($/) { make $<constant>.made // $<statement>.made // '' }
method statement($/) { make "\n" ~ $<struct>.made ~ "\n"; }
- method constant($/) { make 'const ' ~ $<identifier> ~ ' = ' ~ $<number> ~ "\n" }
+
+ method constant($/) {
+ make 'const ' ~ $<identifier> ~ "{self!const-type($/)} = " ~ $<number> ~ "\n"
+ }
+
+ method !const-type($/) returns Str {
+ my $suffix = @!const-types.grep({ $<identifier>.ends-with($_) }).first;
+ $suffix ?? ' ' ~ self!const-camel-case($suffix) !! ''
+ }
+
+ method !const-camel-case(Str $const-name) returns Str {
+ $const-name.lc.split('_').map(*.tc).join('')
+ }
method struct($/) {
make 'type ' ~ $<identifier>.made ~ " struct \{\n\t"
@@ -72,4 +88,4 @@ class NQCToGoActions {
method identifier($/) { make $/.Str.split('_').map(*.tc).join('') }
}
-say NQC.parse($*IN.slurp, :actions(NQCToGoActions)).made;
+say NQC.parse($*IN.slurp, actions => NQCToGoActions.new(const-types => <OP_ID>)).made;
diff --git a/internal/generated/types/types.go b/internal/generated/types/types.go
index 505b1ca..3460cb3 100644
--- a/internal/generated/types/types.go
+++ b/internal/generated/types/types.go
@@ -1,12 +1,13 @@
// This file was generated - don't change manually!
package types
+type OpId int
const MAX_FILENAME_LENGTH = 256
-const OPENAT_ENTER_OP_ID = 1
-const OPEN_ENTER_OP_ID = 3
-const CLOSE_ENTER_OP_ID = 5
-const WRITE_ENTER_OP_ID = 7
-const WRITEV_ENTER_OP_ID = 9
+const OPENAT_ENTER_OP_ID OpId = 1
+const OPEN_ENTER_OP_ID OpId = 3
+const CLOSE_ENTER_OP_ID OpId = 5
+const WRITE_ENTER_OP_ID OpId = 7
+const WRITEV_ENTER_OP_ID OpId = 9
type NullEvent struct {
OpId uint32