Skip to content

Bug 388663: update ECMAUrlParser to support nullable (?) #565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions monodoc/Monodoc.Ecma/EcmaDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public Mod DescModifier {
set;
}

public bool ArrayIsNullable {
get;
set;
}

public bool DescIsNullable
{
get;
set;
}

public string Namespace {
get;
set;
Expand Down Expand Up @@ -245,13 +256,21 @@ void ConstructCRef (StringBuilder sb, bool skipLeadingDot = false)
sb.Append ('+');
NestedType.ConstructCRef (sb, skipLeadingDot: true);
}
if (DescIsNullable)
{
sb.Append('?');
}
if (ArrayDimensions != null && ArrayDimensions.Count > 0) {
for (int i = 0; i < ArrayDimensions.Count; i++) {
sb.Append ('[');
sb.Append (new string (',', ArrayDimensions[i] - 1));
sb.Append (']');
}
}
if (ArrayIsNullable)
{
sb.Append('?');
}
if (DescKind == Kind.Type)
return;

Expand Down Expand Up @@ -396,17 +415,18 @@ string FormatGenericArgsFull (IEnumerable<EcmaDesc> genericArgs)
return genericArgs != null ? "<" + string.Join (",", genericArgs.Select (t => t.ToString ())) + ">" : string.Empty;
}

string ModToString (EcmaDesc desc)
string ModToString(EcmaDesc desc)
{
switch (desc.DescModifier) {
case Mod.Pointer:
return "*";
case Mod.Ref:
return "&";
case Mod.Out:
return "@";
default:
return string.Empty;
switch (desc.DescModifier)
{
case Mod.Pointer:
return "*";
case Mod.Ref:
return "&";
case Mod.Out:
return "@";
default:
return string.Empty;
}
}

Expand Down
21 changes: 17 additions & 4 deletions monodoc/Monodoc.Ecma/EcmaUrlParser.jay
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
%{

// To Generate this file:
// 1. Download and install mono-jay via https://packages.ubuntu.com/bionic/mono-jay
// 2. Run command:
// jay -ct Monodoc.Ecma/EcmaUrlParser.jay < Monodoc.Ecma/jay/skeleton.cs > Monodoc.Ecma/prebuilt/EcmaUrlParser.cs

using System.Text;
using System.IO;
using System;
Expand Down Expand Up @@ -69,6 +75,7 @@ namespace Monodoc.Ecma
%token REF_ARG
%token OUT_ARG
%token EXPLICIT_IMPL_SEP
%token QUESTION_MARK

%start expression

Expand Down Expand Up @@ -113,15 +120,17 @@ reduced_type_expression
}

type_expression_suffix
: opt_generic_type_suffix opt_inner_type_description opt_array_definition opt_etc {
: opt_generic_type_suffix opt_inner_type_description opt_nullable opt_array_definition opt_nullable opt_etc {
bool nestedDescHasEtc = $2 != null && ((EcmaDesc)$2).IsEtc;
EcmaDesc nestedType = (EcmaDesc)$2;
$$ = new EcmaDesc {
GenericTypeArguments = $1 as List<EcmaDesc>,
NestedType = nestedType,
ArrayDimensions = SafeReverse ($3 as List<int>),
Etc = $4 != null ? ((Tuple<char, string>)$4).Item1 : nestedDescHasEtc ? nestedType.Etc : (char)0,
EtcFilter = $4 != null ? ((Tuple<char, string>)$4).Item2 : nestedDescHasEtc ? nestedType.EtcFilter : null
DescIsNullable = $3 != null,
ArrayDimensions = SafeReverse ($4 as List<int>),
ArrayIsNullable = $5 != null,
Etc = $6 != null ? ((Tuple<char, string>)$6).Item1 : nestedDescHasEtc ? nestedType.Etc : (char)0,
EtcFilter = $6 != null ? ((Tuple<char, string>)$6).Item2 : nestedDescHasEtc ? nestedType.EtcFilter : null
};
if (nestedDescHasEtc) {
nestedType.Etc = (char)0;
Expand All @@ -142,6 +151,10 @@ generic_type_arg_list
: type_expression { $$ = new List<EcmaDesc> () { (EcmaDesc)$1 }; }
| generic_type_arg_list COMMA type_expression { ((List<EcmaDesc>)$1).Add ((EcmaDesc)$3); $$ = $1; }

opt_nullable
: /* empty */ { $$ = null; }
| QUESTION_MARK { $$ = "?"; }

opt_array_definition
: /* empty */ { $$ = null; }
| OP_ARRAY_OPEN opt_array_definition_list OP_ARRAY_CLOSE opt_array_definition {
Expand Down
10 changes: 6 additions & 4 deletions monodoc/Monodoc.Ecma/EcmaUrlTokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ int xtoken ()
return Token.OUT_ARG;
case '$':
return Token.EXPLICIT_IMPL_SEP;
case '?':
return Token.QUESTION_MARK;
default:
return TokenizeIdentifierOrNumber (next);
}
Expand Down Expand Up @@ -154,8 +156,8 @@ char Read ()
{
try {
if (input == null || real_current_pos >= input.Length)
return EndOfStream;
return EndOfStream;
return input[real_current_pos++];
} catch {
return EndOfStream;
Expand All @@ -166,8 +168,8 @@ char Peek ()
{
try {
if (input == null || real_current_pos >= input.Length)
return EndOfStream;
return EndOfStream;
return input[real_current_pos];
} catch {
return EndOfStream;
Expand Down
File renamed without changes.
Loading