Skip to content
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

Support all RFC3986 § 2.2 reserved characters #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
137 changes: 98 additions & 39 deletions odata-parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ OData =
{ return model }
/ '/$metadata'
{ return { resource: '$metadata' } }
/ '/'
/ Slash
{ return { resource: '$serviceroot' } }

QueryOptions =
Expand All @@ -134,7 +134,7 @@ Dollar '$ query options' =
/ '%24'

ParameterAliasOption =
'@' name:Text '='
AtSign name:Text Equals
value:(
n:Number
{ return [ 'Real', n ] }
Expand All @@ -154,12 +154,12 @@ ParameterAliasOption =
}

OperationParam =
name:Text '=' value:Text
name:Text Equals value:Text
{ return { name, value } }

SortOption =
'orderby='
properties:SortProperty|1..,','|
properties:SortProperty|1..,Comma|
{ return { name: '$orderby', value: { properties } } }

SortProperty =
Expand Down Expand Up @@ -209,7 +209,7 @@ ExpandOption =
SelectOption =
'select='
value:(
'*'
Asterisk
/ properties:PropertyPathList
{ return { properties } }
)
Expand All @@ -235,9 +235,9 @@ FormatOption =
'format='
type:ContentType
@(
';'
Semicolon
'odata.'?
'metadata='
'metadata' Equals
metadata:(
'none'
/ 'minimal'
Expand Down Expand Up @@ -299,7 +299,7 @@ FilterByValue =
/ Primitive

Primitive =
'(' spaces @Primitive spaces ')'
ParenOpen spaces @Primitive spaces ParenClose
/ QuotedTextBind
/ NumberBind
/ BooleanBind
Expand All @@ -310,7 +310,7 @@ Primitive =
/ PropertyPath

GroupedPrecedenceExpression =
'(' spaces @FilterByExpression spaces ')'
ParenOpen spaces @FilterByExpression spaces ParenClose

FilterByOperand =
spaces
Expand All @@ -337,13 +337,13 @@ FilterNegateExpression =
boundary
@(
FilterByValue
/ '(' spaces @FilterByExpression spaces ')'
/ ParenOpen spaces @FilterByExpression spaces ParenClose
)

GroupedPrimitive =
'(' spaces
@Primitive|1..,',' spaces|
')'
ParenOpen spaces
@Primitive|1..,Comma spaces|
ParenClose

FilterMethodCallExpression =
methodName:(
Expand Down Expand Up @@ -379,89 +379,89 @@ FilterMethodCallExpression =
/ 'trim'
/ 'year'
)
'('
ParenOpen
spaces
args:(
@FilterByExpression|1..,spaces ',' spaces|
@FilterByExpression|1..,spaces Comma spaces|
spaces
/ '' { return [] }
)
&{ return args.length === methods[methodName] || (Array.isArray(methods[methodName]) && methods[methodName].includes(args.length)) }
')'
ParenClose
{ return [ 'call', { args, method: methodName } ] }

LambdaMethodCall =
name:(
'any'
/ 'all'
)
'('
ParenOpen
spaces
identifier:ResourceName
':'
Colon
expression:FilterByExpression
spaces
')'
ParenClose
{ return { expression, identifier, method: name } }

ResourceMethodCall =
methodName:ResourceName
'('
ParenOpen
spaces
args:(
@FilterByExpression|1..,spaces ',' spaces|
@FilterByExpression|1..,spaces Comma spaces|
spaces
/ '' { return [] }
)
')'
ParenClose
{ return [ 'call', { args, method: methodName } ] }

PropertyPathList =
PropertyPath|1..,','|
PropertyPath|1..,Comma|
PropertyPath =
resource:ResourceName
property:(
'/'
Slash
@PropertyPath
)?
countOptions:(
'/$count'
optionsObj:(
'('
ParenOpen
@( Dollar
option:FilterByOption
{ return CollapseObjectArray([option]) }
)
')'
ParenClose
)?
{ return { count: true, options: optionsObj } }
)?
{ return { name: resource, property, ...countOptions } }
ExpandPropertyPathList =
ExpandPropertyPath|1..,','|
ExpandPropertyPath|1..,Comma|
ExpandPropertyPath =
resource:ResourceName
count:(
'/$count'
{ return true }
)?
optionsObj:(
'('
ParenOpen
@( options:QueryOption|1..,[&;]|
{ return CollapseObjectArray(options) }
/ '' { return {} }
)
')'
ParenClose
)?
next:(
'/'
Slash
@PropertyPath
)?
{ return { name: resource, property: next, count, options: optionsObj} }

LambdaPropertyPath =
resource:ResourceName
'/'
Slash
@( next:LambdaPropertyPath
{ return { name: resource, property: next } }
/ lambda:LambdaMethodCall
Expand All @@ -470,14 +470,14 @@ LambdaPropertyPath =
{ return { name: resource, method } }
)
Key =
'('
ParenOpen
@( KeyBind
/ keyBinds:NamedKeyBind|1..,','|
/ keyBinds:NamedKeyBind|1..,Comma|
{ return CollapseObjectArray(keyBinds) }
)
')'
ParenClose
NamedKeyBind =
name:ResourceName '=' value:KeyBind
name:ResourceName Equals value:KeyBind
{ return { name, value }}
KeyBind =
NumberBind
Expand All @@ -490,7 +490,7 @@ Links =

PathSegment =
result:(
'/'
Slash
result:(
resource:ResourceName
{ return { resource } }
Expand Down Expand Up @@ -523,7 +523,7 @@ PathSegment =
)?
{ return result }
SubPathSegment =
'/'
Slash
result:(
resource: ResourceName
{ return { resource } }
Expand Down Expand Up @@ -645,11 +645,70 @@ Text =

Sign =
'+'
/ '%2b'
{ return '+' }
/ '%2B'
{ return '+' }
/ '-'
/ ''

Slash =
'/'
/ '%2f'
{ return '/' }
/ '%2F'
{ return '/' }

Asterisk =
'*'
/ '%2a'
{ return '*' }
/ '%2A'
{ return '*' }

Equals =
'='
/ '%3d'
{ return '=' }
/ '%3D'
{ return '=' }

Comma =
','
/ '%2c'
{ return ',' }
/ '%2C'
{ return ',' }

Semicolon =
';'
/ '%3b'
{ return ';' }
/ '%3B'
{ return ';' }

AtSign =
'@'
/ '%40'
{ return '@' }

Colon =
':'
/ '%3a'
{ return ':' }
/ '%3A'
{ return ':' }

ParenOpen =
'('
/ '%28'
{ return '(' }

ParenClose =
')'
/ '%29'
{ return ')' }

// TODO: This should really be done treating everything the same, but for now this hack should allow FF to work passably.
Apostrophe =
'\''
Expand All @@ -667,7 +726,7 @@ QuotedText =
{ return decodeURIComponent(text.join('')) }

ParameterAlias =
'@' param:ResourceName
AtSign param:ResourceName
{ return { bind: '@' + param } }

NumberBind =
Expand Down Expand Up @@ -709,7 +768,7 @@ QuotedTextBind =
{ return Bind('Text', t) }

boundary =
( &'('
( &ParenOpen
/ space+
)

Expand Down
Loading