File: //usr/share/re2c/stdlib/rust
// supported feature lists -----------------------------------------------------
supported_apis = ["simple", "generic", "record"];
supported_api_styles = ["free-form"];
supported_code_models = ["loop-switch", "recursive-functions"];
supported_targets = ["code", "dot"];
supported_features = ["nested-ifs", "bitmaps", "case-ranges", "unsafe",
"tags", "captures", "captvars"];
// language-specific options ---------------------------------------------------
semicolons = 1;
backtick_quoted_strings = 0;
single_quoted_strings = 0;
indentation_sensitive = 0;
wrap_blocks_in_braces = 1;
special_escapes = "\n\r\t\\'\"";
// immutable configurations (command-line only options) ------------------------
re2c:target = code;
re2c:code-model = loop-switch;
re2c:input-encoding = ascii;
re2c:date = 1;
re2c:version = 1;
re2c:conditions = 0;
re2c:storable-state = 0;
re2c:flex-syntax = 0;
re2c:verbose = 0;
re2c:line-dirs = 0;
// mutable configurations ------------------------------------------------------
re2c:api = generic;
re2c:api:style = free-form;
re2c:api:sigil = "@@";
re2c:YYGETCOND:naked = 0;
re2c:YYSETCOND:naked = 0;
re2c:YYSETCOND@cond = "@@";
re2c:YYGETSTATE:naked = 0;
re2c:YYSETSTATE:naked = 0;
re2c:YYSETSTATE@state = "@@";
re2c:YYFILL@len = "@@";
re2c:YYFILL:naked = 0;
re2c:YYFN = ["<undefined-function-name>;<undefined-function-type>"];
re2c:yyfn:sep = ";";
re2c:yycond = "yycond";
re2c:yyctable = "yyctable";
re2c:yyaccept = "yyaccept";
re2c:yytarget = "yytarget";
re2c:yystate = "yystate";
re2c:yynmatch = "yynmatch";
re2c:yypmatch = "yypmatch";
re2c:yyrecord = "yyrecord";
re2c:yych = "yych";
re2c:yych:conversion = 0;
re2c:yych:literals = hex;
re2c:yych:emit = (.code_model.recursive_functions ? 0 : 1);
re2c:yybm = "yybm";
re2c:yybm:hex = 0;
re2c:yyfill = "";
re2c:yystable = ""; // deprecated
re2c:header = "";
re2c:eof = -1;
re2c:sentinel = -1;
re2c:yyfill:enable = 1;
re2c:yyfill:parameter = 1;
re2c:yyfill:check = 1;
re2c:tags = 0;
re2c:tags:prefix = "yyt";
re2c:captures = 0;
re2c:captvars = 0;
re2c:posix-captures = 0;
re2c:posix-captvars = 0;
re2c:invert-captures = 0;
re2c:cond:abort = 1;
re2c:cond:prefix = "yyc_";
re2c:cond:enumprefix = "YYC_";
re2c:cond:divider@cond = "@@";
re2c:cond:goto@cond = "@@";
re2c:state:abort = 1;
re2c:state:nextlabel = 0;
re2c:bit-vectors = 0;
re2c:debug-output = 0;
re2c:computed-gotos = 0;
re2c:computed-gotos:threshold = 9;
re2c:nested-ifs = 0;
re2c:case-insensitive = 0;
re2c:case-inverted = 0;
re2c:case-ranges = 1;
re2c:unsafe = 1;
re2c:monadic = 0;
re2c:encoding:ebcdic = 0;
re2c:encoding:utf32 = 0;
re2c:encoding:ucs2 = 0;
re2c:encoding:utf16 = 0;
re2c:encoding:utf8 = 0;
re2c:encoding-policy = ignore;
re2c:empty-class = match-empty;
re2c:indent:string = " ";
re2c:indent:top = 0;
re2c:label:prefix = "yy"; // used to generate function names
re2c:label:yyfill = "";
re2c:label:yyloop = "'yyl";
re2c:label:yyNext = "";
re2c:label:start = 0;
// mutable code configuration --------------------------------------------------
re2c:YYBACKUP = "YYBACKUP";
re2c:YYBACKUPCTX = "YYBACKUPCTX";
re2c:YYCONDTYPE = (.storable_state ? "isize" : "usize");
re2c:YYCOPYMTAG = sigil "{lhs} = " sigil "{rhs};";
re2c:YYCOPYSTAG = sigil "{lhs} = " sigil "{rhs};";
re2c:YYCTYPE = "YYCTYPE";
re2c:YYCTXMARKER = (.api.generic ? "YYCTXMARKER" : (.api.record ? yyrecord ".") "yyctxmarker");
re2c:YYCURSOR = (.api.generic ? "YYCURSOR" : (.api.record ? yyrecord ".") "yycursor");
re2c:YYDEBUG = "YYDEBUG";
re2c:YYFILL = "YYFILL";
re2c:YYGETACCEPT = sigil "{var}";
re2c:YYGETCOND = "YYGETCONDITION"; // historic default
re2c:YYGETSTATE = "YYGETSTATE";
re2c:YYINPUT = (.api.generic ? "YYINPUT" : (.api.record ? yyrecord ".") "yyinput");
re2c:YYLESSTHAN = "YYLESSTHAN";
re2c:YYLIMIT = (.api.generic ? "YYLIMIT" : (.api.record ? yyrecord ".") "yylimit");
re2c:YYMARKER = (.api.generic ? "YYMARKER" : (.api.record ? yyrecord ".") "yymarker");
re2c:YYMAXFILL = "YYMAXFILL";
re2c:YYMAXNMATCH = "YYMAXNMATCH";
re2c:YYMTAGN = "YYMTAGN";
re2c:YYMTAGP = "YYMTAGP";
re2c:YYPEEK = (.api.generic ? "YYPEEK" : "get_unchecked");
re2c:YYRESTORE = "YYRESTORE";
re2c:YYRESTORECTX = "YYRESTORECTX";
re2c:YYRESTORETAG = "YYRESTORETAG";
re2c:YYSETACCEPT = sigil "{var} = " sigil "{val};";
re2c:YYSETCOND = "YYSETCONDITION"; // historic default
re2c:YYSETSTATE = "YYSETSTATE";
re2c:YYSHIFT = "YYSHIFT";
re2c:YYSHIFTSTAG = "YYSHIFTSTAG";
re2c:YYSHIFTMTAG = "YYSHIFTMTAG";
re2c:YYSKIP = "YYSKIP";
re2c:YYSTAGN = "YYSTAGN";
re2c:YYSTAGP = "YYSTAGP";
re2c:tags:expression = (.api.record ? yyrecord ".") sigil;
re2c:tags:negative = (.api.generic ? "@@" : "usize::MAX");
re2c:cond:divider = "";
re2c:cond:goto = "";
// code templates --------------------------------------------------------------
code:var_local =
// In Rust uninitialized variable is an error, but if the compiler is able to see
// that all paths overwrite the initial value, it warns about unused assignments.
(!.init ? topindent "#[allow(unused_assignments)]" nl)
topindent "let mut " name " : " type " = " init ";" nl;
code:var_global = topindent "static mut " name " : " type " = " init ";" nl;
code:const_local = topindent "const " name ": " type " = " init ";" nl;
code:const_global = code:const_local;
code:array_local =
topindent "let " name ": [" type "; " size "] = [" nl indent
[row: topindent [elem{0:-2}: elem ", "] [elem{-1}: elem ","] nl]
dedent topindent "];" nl;
code:array_global = <undefined>;
code:array_elem = array "[" index "]";
code:enum = [elem: topindent "const " elem ": " type " = " init ";" nl];
code:enum_elem = name;
code:assign = topindent lhs " = " rhs ";" nl;
code:type_int = "isize";
code:type_uint = "usize";
code:type_yybm = "u8";
code:type_yytarget = <undefined>;
code:cmp_eq = "==";
code:cmp_ne = "!=";
code:cmp_lt = "<";
code:cmp_gt = ">";
code:cmp_le = "<=";
code:cmp_ge = ">=";
code:if_then_else =
[branch{0}: topindent "if " cond " {" nl
indent [stmt: stmt] dedent]
[branch{1:-1}: topindent "} else " (.cond ? "if " cond " ") "{" nl
indent [stmt: stmt] dedent]
topindent "}" nl;
code:if_then_else_oneline = <undefined>;
code:switch =
topindent "match " expr " {" nl
indent [case: case] dedent
topindent "}" nl;
code:switch_cases =
[case{0:-2}: topindent case " |" nl]
[case{-1}: topindent case " => {" nl
indent [stmt: stmt] dedent
topindent "}" nl];
code:switch_cases_oneline =
[case{0:-2}: topindent case " |" nl]
[case{-1}: topindent case " => " [stmt: stmt] "," nl];
code:switch_case_range = [val{0}: val] (.many ? " ..= " [val{-1}: val]);
code:switch_case_default = "_";
code:loop =
topindent (.loop_label ? label ": ") "loop {" nl
indent [stmt: stmt] dedent
topindent "}" nl;
code:continue = topindent "continue" (.loop_label ? " " label) ";" nl;
code:goto = <undefined>;
code:fndecl = <undefined>;
code:fndef =
topindent "fn " name "("
[arg{0:-2}: argname ": " argtype ", "]
[arg{-1}: argname ": " argtype]
")" (.type ? " -> " type) " {" nl
indent [stmt: stmt] dedent
"}" nl;
code:fncall = topindent name "(" [arg{0:-2}: arg ", "] [arg{-1}: arg] ")" nl;
code:tailcall = code:fncall;
code:recursive_functions = [fn: fndef nl];
code:fingerprint =
"/* Generated by re2rust" (.version ? " " version) (.date ? " on " date) " */" nl;
// No line directives in Rust: https://github.com/rust-lang/rfcs/issues/1862.
code:line_info = <undefined>;
code:abort = topindent "panic!(\"internal lexer error\")" nl;
code:yydebug =
topindent (.api.generic
? YYDEBUG
: (.api.record
? YYDEBUG "(" yyrecord ");"
: YYDEBUG "(" state ", " yych ");"
)) nl;
code:yypeek =
topindent (.code_model.recursive_functions ? "let ") yych " = " (.api.generic
? (.unsafe
? "unsafe {" YYPEEK "}"
: YYPEEK)
: (.unsafe
? "unsafe {*" YYINPUT "." YYPEEK "(" YYCURSOR ")}"
: YYINPUT "[" YYCURSOR "]") (.cast ? " as " YYCTYPE)
) ";" nl;
code:yyskip =
topindent (.api.generic
? YYSKIP
: YYCURSOR " += 1;"
) nl;
code:yybackup =
topindent (.api.generic
? YYBACKUP
: YYMARKER " = " YYCURSOR ";"
) nl;
code:yybackupctx =
topindent (.api.generic
? YYBACKUPCTX
: YYCTXMARKER " = " YYCURSOR ";"
) nl;
code:yyskip_yypeek = <undefined>;
code:yypeek_yyskip = <undefined>;
code:yyskip_yybackup = <undefined>;
code:yybackup_yyskip = <undefined>;
code:yybackup_yypeek = <undefined>;
code:yyskip_yybackup_yypeek = <undefined>;
code:yybackup_yypeek_yyskip = <undefined>;
code:yyrestore =
topindent (.api.generic
? YYRESTORE
: YYCURSOR " = " YYMARKER ";"
) nl;
code:yyrestorectx =
topindent (.api.generic
? YYRESTORECTX
: YYCURSOR " = " YYCTXMARKER ";"
) nl;
code:yyrestoretag =
topindent (.api.generic
? YYRESTORETAG
: YYCURSOR " = " tag ";"
) nl;
code:yyshift =
topindent (.api.generic
? YYSHIFT
: YYCURSOR " -= " offset ";"
) nl;
code:yyshiftstag =
(.nested ? topindent "if " tag " != " neg " {" nl indent)
topindent (.api.generic
? YYSHIFTSTAG
: tag " -= " offset ";"
) nl
(.nested ? dedent topindent "}" nl);
code:yyshiftmtag =
topindent YYSHIFTMTAG nl;
code:yystagp =
topindent (.api.generic
? YYSTAGP
: tag " = " YYCURSOR ";"
) nl;
code:yymtagp =
topindent YYMTAGP nl;
code:yystagn =
topindent (.api.generic
? YYSTAGN
: tag " = " neg ";"
) nl;
code:yymtagn =
topindent YYMTAGN nl;
code:yycopystag =
topindent (.api.generic
? YYCOPYSTAG
: lhs " = " rhs ";"
) nl;
code:yycopymtag =
topindent (.api.generic
? YYCOPYMTAG
: lhs " = " rhs ";"
) nl;
code:yygetaccept =
(.api.generic
? YYGETACCEPT
: (.api.record & (.storable_state | .code_model.recursive_functions) ? yyrecord ".") var);
code:yysetaccept =
topindent (.api.generic
? YYSETACCEPT
: (.api.record & (.storable_state | .code_model.recursive_functions) ? yyrecord ".")
var " = " val ";"
) nl;
code:yygetcond =
(.api.generic
? YYGETCOND
: (.api.record ? yyrecord ".") var);
code:yysetcond =
topindent (.api.generic
? YYSETCOND
: (.api.record ? yyrecord ".") var " = " val ";"
) nl;
code:yygetstate =
(.api.generic
? YYGETSTATE
: (.api.record ? yyrecord ".") var);
code:yysetstate =
topindent (.api.generic
? YYSETSTATE
: (.api.record ? yyrecord "." var) " = " val ";"
) nl;
code:yylessthan =
(.api.generic
? YYLESSTHAN
: (.many
? "(" YYLIMIT " - " YYCURSOR ") < " need
: YYLIMIT " <= " YYCURSOR));
code:yybm_filter = yych " & ~0xFF";
code:yybm_match = "(" yybm "[" offset "+" yych " as usize] & " mask ") != 0";