S: code_line;

code_line: c=code? com=comment?;

code: magic_string | header_line | instruction;

magic_string: ";!" "knitout" "-" v=int_exp;
header_line: ";;" h_op=header_op {10};
header_op: machine_op
			| gauge_op
			| yarn_op
			| carriers_op
			| position_op
			| width_op;

machine_op: "Machine" ":" m=identifier;
gauge_op: "Gauge" ":" g=int_exp;
yarn_op: "Yarn" "-" cid=int_exp ":" plies=int_exp "-" weight=int_exp color=identifier;
carriers_op: "Carriers" ":" CS=carrier_set;
position_op: "Position" ":" p=identifier;
width_op: "Width" ":" w=int_exp;

instruction: in_op
				| inhook_op
				| releasehook_op
				| out_op
				| outhook_op
				| rack_op
				| knit_op
				| tuck_op
				| split_op
				| drop_op
				| xfer_op
				| miss_op
				| pause_op;

in_op: "in" c=int_exp;
inhook_op: "inhook" c=int_exp;
releasehook_op: "releasehook" c=int_exp;
out_op: "out" c=int_exp;
outhook_op: "outhook" c=int_exp;
rack_op: "rack" R=float_exp ;
knit_op: "knit" D=direction N=needle_id CS=carrier_set;
tuck_op: "tuck" D=direction N=needle_id CS=carrier_set;
split_op: "split" D=direction N=needle_id N2=needle_id CS=carrier_set ;
drop_op: "drop" N=needle_id ;
xfer_op: "xfer" N=needle_id N2=needle_id ;
miss_op: "miss" D=direction N=needle_id CS=carrier_set;
kick_op: "kick" D=direction N=needle_id CS=carrier_set;
pause_op: "pause";


direction: "+" | "-";

carrier_set: carriers=int_exp+;

comment: ";" content = comment_content? {1};

terminals

identifier: /[a-zA-Z_]+[0-9a-zA-Z_]*/{9};
float_exp: /-?[0-9]*(\.?[0-9]+)?/;
int_exp: /-?[0-9]+/ {prefer};
needle_id: /[fb]s?[0-9]+/{10};
KEYWORD: /\w+/;

comment_content: /.*/;
