finalize TypeParser grammar

This commit is contained in:
Jan Tvrdik 2018-03-20 09:13:18 +01:00
parent 3dc77d7af4
commit aaa6ac83d1
3 changed files with 95 additions and 64 deletions

95
doc/grammars/type.abnf Normal file
View File

@ -0,0 +1,95 @@
; ---------------------------------------------------------------------------- ;
; Type ;
; ---------------------------------------------------------------------------- ;
Type
= Atomic [Union / Intersection]
/ Nullable
Union
= 1*(TokenUnion Atomic)
Intersection
= 1*(TokenIntersection Atomic)
Nullable
= TokenNullable TokenIdentifier [Generic]
Atomic
= TokenIdentifier [Generic / Array]
/ TokenThisVariable
/ TokenParenthesesOpen Type TokenParenthesesClose [Array]
Generic
= TokenAngleBracketOpen Type *(TokenComma Type) TokenAngleBracketClose
Array
= 1*(TokenSquareBracketOpen TokenSquareBracketClose)
; ---------------------------------------------------------------------------- ;
; Tokens ;
; ---------------------------------------------------------------------------- ;
TokenUnion
= "|" *ByteHorizontalWs
TokenIntersection
= "&" *ByteHorizontalWs
TokenNullable
= "?" *ByteHorizontalWs
TokenParenthesesOpen
= "(" *ByteHorizontalWs
TokenParenthesesClose
= ")" *ByteHorizontalWs
TokenAngleBracketOpen
= "<" *ByteHorizontalWs
TokenAngleBracketClose
= ">" *ByteHorizontalWs
TokenSquareBracketOpen
= "[" *ByteHorizontalWs
TokenSquareBracketClose
= "]" *ByteHorizontalWs
TokenComma
= "," *ByteHorizontalWs
TokenThisVariable
= %x24.74.68.69.73 *ByteHorizontalWs
TokenIdentifier
= [ByteBackslash] ByteIdentifierFirst *ByteIdentifierSecond *(ByteBackslash ByteIdentifierFirst *ByteIdentifierSecond) *ByteHorizontalWs
; ---------------------------------------------------------------------------- ;
; Bytes ;
; ---------------------------------------------------------------------------- ;
ByteHorizontalWs
= %x09 ; horizontal tab
/ %x20 ; space
ByteIdentifierFirst
= %x41-5A ; A-Z
/ %x5F ; _
/ %x61-7A ; a-z
/ %x80-FF
ByteIdentifierSecond
= %x30-39 ; 0-9
/ %x41-5A ; A-Z
/ %x5F ; _
/ %x61-7A ; a-z
/ %x80-FF
ByteBackslash
= %x5C ; \

View File

@ -1,32 +0,0 @@
Type
::= Atomic (Union | Intersection)?
| Nullable
Union
::= ('|' Atomic)+
Intersection
::= ('&' Atomic)+
Nullable
::= '?' Identifier Generic?
Atomic
::= Identifier (Generic | Array)?
| ThisType
| '(' Type ')' Array?
Generic
::= '<' Type (',' Type)* '>'
Array
::= ('[' ']')+
ThisType
::= '$this'
Identifier
::= ('\\'? Word)+
Word
::= [a-zA-Z_#x7F-#x10FFFF][0-9a-zA-Z_#x7F-#x10FFFF]*

View File

@ -1,32 +0,0 @@
Type
= Atomic (Union / Intersection)?
/ Nullable
Union
= ('|' Atomic)+
Intersection
= ('&' Atomic)+
Nullable
= '?' Identifier Generic?
Atomic
= Identifier (Generic / Array)?
/ ThisType
/ '(' Type ')' Array?
Generic
= '<' Type (',' Type)* '>'
Array
= ('[' ']')+
ThisType
= '$this'
Identifier
= ('\\'? Word)+
Word
= [a-zA-Z_\\127-\\255][a-zA-Z0-9_\\127-\\255]*