diff options
| -rw-r--r-- | internal/generated/nqc.raku | 24 | ||||
| -rw-r--r-- | internal/generated/types/types.go | 11 |
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 |
