Skip to content

Commit e09a476

Browse files
authored
Merge pull request #565: update ECMAUrlParser to support nullable (?)
Bug 388663: update ECMAUrlParser to support nullable (?)
2 parents 8090c24 + d22bb30 commit e09a476

File tree

8 files changed

+727
-214
lines changed

8 files changed

+727
-214
lines changed

monodoc/Monodoc.Ecma/EcmaDesc.cs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ public Mod DescModifier {
4646
set;
4747
}
4848

49+
public bool ArrayIsNullable {
50+
get;
51+
set;
52+
}
53+
54+
public bool DescIsNullable
55+
{
56+
get;
57+
set;
58+
}
59+
4960
public string Namespace {
5061
get;
5162
set;
@@ -245,13 +256,21 @@ void ConstructCRef (StringBuilder sb, bool skipLeadingDot = false)
245256
sb.Append ('+');
246257
NestedType.ConstructCRef (sb, skipLeadingDot: true);
247258
}
259+
if (DescIsNullable)
260+
{
261+
sb.Append('?');
262+
}
248263
if (ArrayDimensions != null && ArrayDimensions.Count > 0) {
249264
for (int i = 0; i < ArrayDimensions.Count; i++) {
250265
sb.Append ('[');
251266
sb.Append (new string (',', ArrayDimensions[i] - 1));
252267
sb.Append (']');
253268
}
254269
}
270+
if (ArrayIsNullable)
271+
{
272+
sb.Append('?');
273+
}
255274
if (DescKind == Kind.Type)
256275
return;
257276

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

399-
string ModToString (EcmaDesc desc)
418+
string ModToString(EcmaDesc desc)
400419
{
401-
switch (desc.DescModifier) {
402-
case Mod.Pointer:
403-
return "*";
404-
case Mod.Ref:
405-
return "&";
406-
case Mod.Out:
407-
return "@";
408-
default:
409-
return string.Empty;
420+
switch (desc.DescModifier)
421+
{
422+
case Mod.Pointer:
423+
return "*";
424+
case Mod.Ref:
425+
return "&";
426+
case Mod.Out:
427+
return "@";
428+
default:
429+
return string.Empty;
410430
}
411431
}
412432

monodoc/Monodoc.Ecma/EcmaUrlParser.jay

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
%{
2+
3+
// To Generate this file:
4+
// 1. Download and install mono-jay via https://packages.ubuntu.com/bionic/mono-jay
5+
// 2. Run command:
6+
// jay -ct Monodoc.Ecma/EcmaUrlParser.jay < Monodoc.Ecma/jay/skeleton.cs > Monodoc.Ecma/prebuilt/EcmaUrlParser.cs
7+
28
using System.Text;
39
using System.IO;
410
using System;
@@ -69,6 +75,7 @@ namespace Monodoc.Ecma
6975
%token REF_ARG
7076
%token OUT_ARG
7177
%token EXPLICIT_IMPL_SEP
78+
%token QUESTION_MARK
7279

7380
%start expression
7481

@@ -113,15 +120,17 @@ reduced_type_expression
113120
}
114121

115122
type_expression_suffix
116-
: opt_generic_type_suffix opt_inner_type_description opt_array_definition opt_etc {
123+
: opt_generic_type_suffix opt_inner_type_description opt_nullable opt_array_definition opt_nullable opt_etc {
117124
bool nestedDescHasEtc = $2 != null && ((EcmaDesc)$2).IsEtc;
118125
EcmaDesc nestedType = (EcmaDesc)$2;
119126
$$ = new EcmaDesc {
120127
GenericTypeArguments = $1 as List<EcmaDesc>,
121128
NestedType = nestedType,
122-
ArrayDimensions = SafeReverse ($3 as List<int>),
123-
Etc = $4 != null ? ((Tuple<char, string>)$4).Item1 : nestedDescHasEtc ? nestedType.Etc : (char)0,
124-
EtcFilter = $4 != null ? ((Tuple<char, string>)$4).Item2 : nestedDescHasEtc ? nestedType.EtcFilter : null
129+
DescIsNullable = $3 != null,
130+
ArrayDimensions = SafeReverse ($4 as List<int>),
131+
ArrayIsNullable = $5 != null,
132+
Etc = $6 != null ? ((Tuple<char, string>)$6).Item1 : nestedDescHasEtc ? nestedType.Etc : (char)0,
133+
EtcFilter = $6 != null ? ((Tuple<char, string>)$6).Item2 : nestedDescHasEtc ? nestedType.EtcFilter : null
125134
};
126135
if (nestedDescHasEtc) {
127136
nestedType.Etc = (char)0;
@@ -142,6 +151,10 @@ generic_type_arg_list
142151
: type_expression { $$ = new List<EcmaDesc> () { (EcmaDesc)$1 }; }
143152
| generic_type_arg_list COMMA type_expression { ((List<EcmaDesc>)$1).Add ((EcmaDesc)$3); $$ = $1; }
144153

154+
opt_nullable
155+
: /* empty */ { $$ = null; }
156+
| QUESTION_MARK { $$ = "?"; }
157+
145158
opt_array_definition
146159
: /* empty */ { $$ = null; }
147160
| OP_ARRAY_OPEN opt_array_definition_list OP_ARRAY_CLOSE opt_array_definition {

monodoc/Monodoc.Ecma/EcmaUrlTokenizer.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ int xtoken ()
111111
return Token.OUT_ARG;
112112
case '$':
113113
return Token.EXPLICIT_IMPL_SEP;
114+
case '?':
115+
return Token.QUESTION_MARK;
114116
default:
115117
return TokenizeIdentifierOrNumber (next);
116118
}
@@ -154,8 +156,8 @@ char Read ()
154156
{
155157
try {
156158
if (input == null || real_current_pos >= input.Length)
157-
return EndOfStream;
158-
159+
return EndOfStream;
160+
159161
return input[real_current_pos++];
160162
} catch {
161163
return EndOfStream;
@@ -166,8 +168,8 @@ char Peek ()
166168
{
167169
try {
168170
if (input == null || real_current_pos >= input.Length)
169-
return EndOfStream;
170-
171+
return EndOfStream;
172+
171173
return input[real_current_pos];
172174
} catch {
173175
return EndOfStream;
File renamed without changes.

0 commit comments

Comments
 (0)