Typed G-code parsing, validation, rewriting, and offline toolpath review for MoonBit
moon add cjcjwe/gcode-toolkitimport {
"cjcjwe/gcode-toolkit" @gcode,
}
let program = @gcode.parse_gcode("G1 X10 Y5 F1200\nG0 Z2").unwrap()
let statistics = @gcode.analyze(program)
println(@gcode.render_summary(program))
println(statistics.cutting_distance())moon run cmd/main
moon run examples/document
moon run examples/validation
moon run examples/rewrite
moon run examples/batchmoon fmt --check
moon info
moon check --deny-warn
moon build
moon test
moon run cmd/main
moon run examples/document
moon run examples/validation
moon run examples/rewrite
moon run examples/batch
powershell -ExecutionPolicy Bypass -File scripts/source-audit.ps1pub struct BlockDifference {
kind_value : BlockDifferenceKind
line_value : Int
left_value : String?
right_value : String?
} derive(Eq, Debug)fn CoordinateTransform::new(offset_x : Double, offset_y : Double, offset_z : Double, scale : Double) -> Result[CoordinateTransform, GCodeError]pub struct Diagnostic {
severity_value : DiagnosticSeverity
code_value : String
message_value : String
line_value : Int
} derive(Eq, Debug)pub struct DocumentDifference {
differences_value : Array[BlockDifference]
equal_blocks_value : Int
left_lines_value : Int
right_lines_value : Int
} derive(Eq, Debug)pub struct DocumentRewritePlan {
comment_mode_value : CommentRewriteMode
blank_mode_value : BlankLineRewriteMode
sequence_mode_value : SequenceRewriteMode
checksum_mode_value : ChecksumRewriteMode
feed_multiplier_value : Double
spindle_multiplier_value : Double
tool_mappings_value : Array[ToolMapping]
include_final_newline_value : Bool
} derive(Eq, Debug)fn DocumentRewritePlan::with_blank_lines(self : DocumentRewritePlan, mode : BlankLineRewriteMode) -> DocumentRewritePlanfn DocumentRewritePlan::with_checksums(self : DocumentRewritePlan, mode : ChecksumRewriteMode) -> DocumentRewritePlanfn DocumentRewritePlan::with_comments(self : DocumentRewritePlan, mode : CommentRewriteMode) -> DocumentRewritePlanfn DocumentRewritePlan::with_feed_multiplier(self : DocumentRewritePlan, multiplier : Double) -> Result[DocumentRewritePlan, GCodeError]fn DocumentRewritePlan::with_final_newline(self : DocumentRewritePlan, enabled : Bool) -> DocumentRewritePlanfn DocumentRewritePlan::with_sequences(self : DocumentRewritePlan, mode : SequenceRewriteMode) -> DocumentRewritePlanfn DocumentRewritePlan::with_spindle_multiplier(self : DocumentRewritePlan, multiplier : Double) -> Result[DocumentRewritePlan, GCodeError]fn DocumentRewritePlan::with_tool_mapping(self : DocumentRewritePlan, from : Int, to : Int) -> Result[DocumentRewritePlan, GCodeError]pub struct DocumentRewriteResult {
text_value : String
records_value : Array[RewriteLineRecord]
changed_lines_value : Int
omitted_lines_value : Int
diagnostics_value : Array[Diagnostic]
} derive(Eq, Debug)pub struct DocumentValidation {
profile_value : ValidationProfile
diagnostics_value : Array[Diagnostic]
summary_value : ValidationSummary
state_trace_value : StateTraceReport
} derive(Eq, Debug)pub struct GCodeAudit {
program_value : GCodeProgram
statistics_value : MotionStatistics
diagnostics_value : Array[Diagnostic]
canonical_text_value : String
} derive(Eq, Debug)pub struct GCodeBatchItem {
label_value : String
program_value : GCodeProgram?
error_value : GCodeError?
} derive(Eq, Debug)pub struct GCodeDocument {
blocks_value : Array[GCodeBlock]
physical_lines_value : Int
} derive(Eq, Debug)pub struct GCodeError {
code_value : GCodeErrorCode
message_value : String
location_value : SourceLocation
} derive(Eq, Debug)pub struct MachineState {
unit_value : LengthUnit
coordinate_mode_value : CoordinateMode
extrusion_mode_value : ExtrusionMode
plane_value : WorkingPlane
motion_value : MotionKind?
position_value : Position
work_offset_value : Position
feed_value : Double?
spindle_mode_value : SpindleMode
spindle_speed_value : Double?
coolant_value : CoolantMode
tool_value : Int?
} derive(Eq, Debug)pub struct Motion {
kind_value : MotionKind
start_value : Position
end_value : Position
i_value : Double
j_value : Double
feed_value : Double?
source_line_value : Int
} derive(Eq, Debug)pub struct ProgramIndex {
commands_value : Array[CommandOccurrence]
usage_value : Array[LetterUsage]
executable_lines_value : Array[Int]
comment_lines_value : Array[Int]
sequence_gaps_value : Array[SequenceGap]
} derive(Eq, Debug)fn ProgramIndex::find_command(self : ProgramIndex, letter : Int, code : Double) -> Array[CommandOccurrence]pub struct ReviewBatch {
outcomes_value : Array[ReviewOutcome]
summary_value : ReviewBatchSummary
} derive(Eq, Debug)pub struct ReviewBatchSummary {
item_count_value : Int
parsed_count_value : Int
accepted_count_value : Int
rejected_count_value : Int
parse_error_count_value : Int
diagnostic_error_count_value : Int
warning_count_value : Int
changed_line_count_value : Int
command_count_value : Int
} derive(Eq, Debug)pub struct ReviewOutcome {
label_value : String
document_value : GCodeDocument?
index_value : ProgramIndex?
validation_value : DocumentValidation?
rewrite_value : DocumentRewriteResult?
parse_error_value : GCodeError?
} derive(Eq, Debug)pub struct ReviewRequest {
label_value : String
source_value : String
profile_value : ValidationProfile
rewrite_plan_value : DocumentRewritePlan
} derive(Eq, Debug)fn ReviewRequest::with_rewrite_plan(self : ReviewRequest, plan : DocumentRewritePlan) -> ReviewRequestfn SafetyPolicy::with_workspace(self : SafetyPolicy, x : Double, y : Double, z : Double) -> SafetyPolicypub struct StateSnapshot {
line_value : Int
before_value : MachineState
after_value : MachineState
labels_value : Array[String]
} derive(Eq, Debug)pub struct StateTraceReport {
snapshots_value : Array[StateSnapshot]
diagnostics_value : Array[Diagnostic]
final_state_value : MachineState
} derive(Eq, Debug)pub struct ToolSection {
ordinal_value : Int
tool_value : Int?
start_line_value : Int
end_line_value : Int
blocks_value : Array[GCodeBlock]
} derive(Eq, Debug)pub struct ToolpathTrace {
points_value : Array[TracePoint]
total_distance_value : Double
} derive(Eq, Debug)pub struct TracePoint {
index_value : Int
line_value : Int
position_value : Position
cumulative_distance_value : Double
feed_value : Double?
kind_value : MotionKind
} derive(Eq, Debug)pub struct ValidationProfile {
name_value : String
family_value : ControllerFamily
allowed_g_codes_value : Array[Double]
allowed_m_codes_value : Array[Int]
allowed_letters_value : Array[Int]
max_x_value : Double
max_y_value : Double
max_z_value : Double
max_feed_value : Double
max_spindle_value : Double
max_tool_value : Int
require_sequence_value : Bool
require_checksum_value : Bool
require_monotonic_sequence_value : Bool
allow_extrusion_value : Bool
allow_arcs_value : Bool
} derive(Eq, Debug)fn ValidationProfile::with_arcs_allowed(self : ValidationProfile, allowed : Bool) -> ValidationProfilefn ValidationProfile::with_checksum_required(self : ValidationProfile, required : Bool) -> ValidationProfilefn ValidationProfile::with_max_feed(self : ValidationProfile, max_feed : Double) -> ValidationProfilefn ValidationProfile::with_max_spindle(self : ValidationProfile, max_spindle : Double) -> ValidationProfilefn ValidationProfile::with_sequence_policy(self : ValidationProfile, required : Bool, monotonic : Bool) -> ValidationProfilefn ValidationProfile::with_workspace(self : ValidationProfile, max_x : Double, max_y : Double, max_z : Double) -> ValidationProfilefn compare_documents(left : GCodeDocument, right : GCodeDocument, ignore_comments? : Bool) -> DocumentDifferencefn review_batch(requests : Array[ReviewRequest], max_items? : Int, max_lines_per_item? : Int) -> Result[ReviewBatch, GCodeError]fn rewrite_document(document : GCodeDocument, plan? : DocumentRewritePlan) -> Result[DocumentRewriteResult, GCodeError]Install
Download zipTyped G-code parsing, validation, rewriting, and offline toolpath review for MoonBit