diff --git a/src/dcparser.rs b/src/dcparser.rs index f8d4993..ac539f4 100644 --- a/src/dcparser.rs +++ b/src/dcparser.rs @@ -510,151 +510,73 @@ parser! { array_param[ap] => ast::Parameter::Array(ap), } - // ----- Char Parameter ----- // - - char_param: ast::CharParameter { - // FIXME: solve shift-reduce conflict - //CharType => ast::CharParameter { - // identifier: None, - // char_literal: None, - //}, - CharType Identifier(id) => ast::CharParameter { - identifier: Some(id), - char_literal: None, - }, - CharType Identifier(id) Equals CharacterLiteral(c) => ast::CharParameter { - identifier: Some(id), - char_literal: Some(c), - }, + size_constraint: Option { + => None, + OpenParenthesis DecimalLiteral(sc) CloseParenthesis => Some(sc) } - // ----- Integer Parameter ----- // - - int_param: ast::IntParameter { - //IntType(int_id) => ast::IntParameter { - // identifier: None, - // int_type: int_id, - // int_range: None, - // int_transform: None, - // int_constant: None, - //}, - named_transformed_ranged_int[(int_id, r, t, id)] => ast::IntParameter { - identifier: Some(id), - int_type: int_id, - int_range: r, - int_transform: t, - int_constant: None, - }, - named_transformed_ranged_int[(int_id, r, t, id)] - Equals DecimalLiteral(dl) => ast::IntParameter { - identifier: Some(id), - int_type: int_id, - int_range: r, - int_transform: t, - int_constant: Some(dl), - }, + int_range: Option> { + => None, + OpenParenthesis DecimalLiteral(a) Hyphen DecimalLiteral(b) CloseParenthesis => Some(a .. b) } - named_transformed_ranged_int: (String, Option>, Option, String) { - transformed_ranged_int[(int_id, r, t)] Identifier(id) => (int_id, Some(r), Some(t), id), - IntType(int_id) Identifier(id) => (int_id, None, None, id), + float_range: Option> { + => None, + OpenParenthesis FloatLiteral(a) Hyphen FloatLiteral(b) CloseParenthesis => Some(a .. b) } - - transformed_ranged_int: (String, Range, ast::IntTransform) { - ranged_int[(int_id, r)] int_transform[t] => (int_id, r, t) + + array_range: Option>> { + => None, + OpenBrackets array_range_opts[aros] CloseBrackets => Some(aros) } - ranged_int: (String, Range) { - IntType(int_id) int_range[r] => (int_id, r) + array_range_opts: Vec> { + => vec![], + array_range_opts[mut aros] Hyphen DecimalLiteral(aro) => { + aros.push(aro); + aros + }, + array_range_opts[mut aros] DecimalLiteral(aro) => { + aros.push(aro); + aros + } } - int_range: Range { - OpenParenthesis DecimalLiteral(a) Hyphen DecimalLiteral(b) CloseParenthesis => a .. b + // ----- Char Parameter ----- // + + char_param: ast::CharParameter { } - int_transform: ast::IntTransform { - Percent DecimalLiteral(n) => ast::IntTransform::OperatorIntLiteral { - operator: Percent, - int_literal: n, - } + // ----- Integer Parameter ----- // + + int_param: ast::IntParameter { } // ----- Float Parameter ----- // float_param: ast::FloatParameter { - FloatType => ast::FloatParameter { - identifier: None, - float_type: None, - float_range: None, - float_transform: None, - float_constant: None, - } - } - - float_range: (f64, f64) { - OpenParenthesis FloatLiteral(a) Hyphen FloatLiteral(b) CloseParenthesis => (a, b) } // ----- String Parameter ----- // string_param: ast::StringParameter { - //StringType => ast::StringParameter { - // identifier: None, - // string_literal: None, - // size_constraint: None, - //}, - named_sized_string[(id, sc)] => ast::StringParameter { - identifier: Some(id), - string_literal: None, - size_constraint: sc, - }, - named_sized_string[(id, sc)] Equals StringLiteral(sl) => ast::StringParameter { - identifier: Some(id), - string_literal: Some(sl), - size_constraint: sc, - }, - } - - named_sized_string: (String, Option) { - sized_string[sc] Identifier(id) => (id, Some(sc)), - StringType Identifier(id) => (id, None), // accept w/o size constraint - } - - sized_string: i64 { - StringType size_constraint[sc] => sc } // ----- Blob Parameter ----- // + // FIXME: plex needs to fix optional grammar. cannot move on with the parser. + // FIXME: https://github.com/goffrie/plex/issues/20 + //opt_id: Option { + // => None, + // Identifier(id) => Some(id) + //} + blob_param: ast::BlobParameter { - //BlobType => ast::BlobParameter { - // identifier: None, - // string_literal: None, - // size_constraint: None, - //}, - named_sized_blob[(id, sc)] => ast::BlobParameter { - identifier: Some(id), + BlobType size_constraint[sc] opt_id[id] => ast::BlobParameter { + identifier: id, string_literal: None, size_constraint: sc, }, - named_sized_blob[(id, sc)] Equals StringLiteral(sl) => ast::BlobParameter { - identifier: Some(id), - string_literal: Some(sl), - size_constraint: sc, - }, - } - - named_sized_blob: (String, Option) { - sized_blob[sc] Identifier(id) => (id, Some(sc)), - BlobType Identifier(id) => (id, None), // also accept w/o constraint - } - - sized_blob: i64 { - BlobType size_constraint[sc] => sc - } - - size_constraint: i64 { - OpenParenthesis DecimalLiteral(s) CloseParenthesis => s } // ----- Struct Parameter ----- //