diff --git a/topics/grammars/dart/ready.lst b/topics/grammars/dart/ready.lst index cb429113..4563e541 100644 --- a/topics/grammars/dart/ready.lst +++ b/topics/grammars/dart/ready.lst @@ -1 +1,2 @@ google +spec diff --git a/topics/grammars/dart/spec/Makefile b/topics/grammars/dart/spec/Makefile new file mode 100644 index 00000000..9c474d0c --- /dev/null +++ b/topics/grammars/dart/spec/Makefile @@ -0,0 +1,37 @@ +extract: + make fixes + ${hunter} grammar.lexically.fixed.prepared.src ebnf.edd raw.bgf + ${tooldir}/xbgf post-extract.xbgf raw.bgf ext.1.bgf + ${tooldir}/xbgf fix-spaces.xbgf ext.1.bgf ext.2.bgf + ${tooldir}/xbgf drop-empty-alternatives.xbgf ext.2.bgf ext.3.bgf + ${tooldir}/xbgf unite-misspellings.xbgf ext.3.bgf ext.4.bgf + ${tooldir}/xbgf emulate-negation.xbgf ext.4.bgf ext.5.bgf + ${tooldir}/xbgf emulate-omission.xbgf ext.5.bgf ext.6.bgf + ${tooldir}/xbgf correct.xbgf ext.6.bgf ext.7.bgf + ${tooldir}/xbgf complete.xbgf ext.7.bgf grammar.bgf + +fixes: + cp grammar.manually.fixed.src grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/HEX NUMBER/HEX_NUMBER/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/HEX DIGIT SEQUENCE/HEX_DIGIT_SEQUENCE/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/HEX DIGIT/HEX_DIGIT/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/SINGLE LINE STRING/SINGLE_LINE_STRING/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/MULTI LINE STRING/MULTI_LINE_STRING/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/ESCAPE SEQUENCE/ESCAPE_SEQUENCE/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/HEX DIGIT SEQUENCE/HEX_DIGIT_SEQUENCE/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/STRING CONTENT DQ/STRING_CONTENT_DQ/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/STRING CONTENT SQ/STRING_CONTENT_SQ/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/STRING INTERPOLATION/STRING_INTERPOLATION/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/IDENTIFIER NO DOLLAR/IDENTIFIER_NO_DOLLAR/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/BUILT IN IDENTIFIER/BUILT_IN_IDENTIFIER/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/IDENTIFIER START NO DOLLAR/IDENTIFIER_START_NO_DOLLAR/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/IDENTIFIER PART NO DOLLAR/IDENTIFIER_PART_NO_DOLLAR/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/IDENTIFIER START/IDENTIFIER_START/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/IDENTIFIER PART/IDENTIFIER_PART/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/SINGLE LINE COMMENT/SINGLE_LINE_COMMENT/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/MULTI LINE COMMENT/MULTI_LINE_COMMENT/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/‘/’/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/̃/~/g;' grammar.lexically.fixed.prepared.src + perl -pi -w -e 's/ˆ/^/g;' grammar.lexically.fixed.prepared.src + +include ../../Makefile.grammar diff --git a/topics/grammars/dart/spec/README.txt b/topics/grammars/dart/spec/README.txt new file mode 100644 index 00000000..f1b65593 --- /dev/null +++ b/topics/grammars/dart/spec/README.txt @@ -0,0 +1,37 @@ +http://www.dartlang.org/docs/spec/index.html +http://www.dartlang.org/docs/spec/dartLangSpec.pdf + +Dart Programming Language Specification +Draft Version 0.01 +The Dart Team +October 10th, 2011 + +List of errors not included in or not apparent from the XBGF files: +- lacking terminator symbol by NUMBER, assertStatement, scriptTag, libraryName +- constOb jectExpression => constObjectExpression +- things like ’;’ instead of ‘;’ in many terminals +- ‘, instead of ‘,’ (or ’,’) in formalParameterList +- ’) instead of ’(’ (or ‘(’) in libraryImport +- getterSignature and setterSignature contain "static" not in bold +- interfaceDefinition contains "interface" not in bold +- hyphenation in nonterminal names in + factoryConstructorSignature + mapLiteral + relationalExpression + additiveExpression + interfaceDefinition + functionExpression + topLevelDefinition + scriptDefinition + libraryDefinition +- The last two alternatives are just wrong, incorrectly understood from ANTLR spec: + SINGLE LINE STRING: + ‘”’ STRING CONTENT DQ* ‘”’ + | ‘’’ STRING CONTENT SQ* ‘\’’ + | ‘@’ ‘’’ ( ( ‘’’ | NEWLINE ))* ‘’’ + | ‘@’ ‘”’ ( ( ‘”’ | NEWLINE ))* ‘”’ + ; +- compoundAssignmentOperator contains both ("<<=") and ("<" "<" "="?) alternatives (left unfixed) +- switchCase contains "case" not in bold +- defaultCase contains "case" and "default" not in bold +- assertStatement contains "assert" not in bold \ No newline at end of file diff --git a/topics/grammars/dart/spec/complete.xbgf b/topics/grammars/dart/spec/complete.xbgf new file mode 100644 index 00000000..36fb9371 --- /dev/null +++ b/topics/grammars/dart/spec/complete.xbgf @@ -0,0 +1,19 @@ + + + + + + returnType + + + + void + + + type + + + + + + diff --git a/topics/grammars/dart/spec/correct.xbgf b/topics/grammars/dart/spec/correct.xbgf new file mode 100644 index 00000000..fccdfed0 --- /dev/null +++ b/topics/grammars/dart/spec/correct.xbgf @@ -0,0 +1,109 @@ + + + + + + staticFinalDeclarationList + + + + + + : + + + + + staticFinalDeclaration + + + + + + + , + + + staticFinalDeclaration + + + + + + + + + + + + + + + negate + + + , + + + + + negate + + + + + ESCAPE_SEQUENCE + + + + ESCAPE_SEQUENCE + + + + \ + + + u + + + + + + + { + + + HexDigitSequence + + + } + + + + + + + + + + + ESCAPE_SEQUENCE + + + + + + + + -- + + + incrementOperator + + + diff --git a/topics/grammars/dart/spec/drop-empty-alternatives.xbgf b/topics/grammars/dart/spec/drop-empty-alternatives.xbgf new file mode 100644 index 00000000..577cad21 --- /dev/null +++ b/topics/grammars/dart/spec/drop-empty-alternatives.xbgf @@ -0,0 +1,111 @@ + + + + + + binaryOperator + + + + + binaryOperator + + + + + + + + binaryOperator + + + + primary + + + + + primary + + + + + + + + primary + + + + NUMBER + + + + + NUMBER + + + + + + + + NUMBER + + + + expressionStatement + + + + + expressionStatement + + + + + + + + + assertStatement + + + + + assertStatement + + + + + + + + + scriptTag + + + + + scriptTag + + + + + + + + + libraryName + + + + + libraryName + + + + + + + diff --git a/topics/grammars/dart/spec/ebnf.edd b/topics/grammars/dart/spec/ebnf.edd new file mode 100644 index 00000000..81343cf3 --- /dev/null +++ b/topics/grammars/dart/spec/ebnf.edd @@ -0,0 +1,55 @@ + + + + : + ; + | + ( + ) + + + ? + * + + + + + _ + + + EOF + + + + + + + + + ’”’ + " + + + ’’’ + ' + + + ’\’’ + ' + + + + ’"""’ + """ + + + ’’’’’ + ''' + + diff --git a/topics/grammars/dart/spec/emulate-negation.xbgf b/topics/grammars/dart/spec/emulate-negation.xbgf new file mode 100644 index 00000000..cff0332d --- /dev/null +++ b/topics/grammars/dart/spec/emulate-negation.xbgf @@ -0,0 +1,167 @@ + + + + + + . + + + + + + MULTI_LINE_STRING + + + + + + . + + + + + + MULTI_LINE_COMMENT + + + + + + + + ' + + + NEWLINE + + + + + + + + SINGLE_LINE_STRING + + + + + + + " + + + NEWLINE + + + + + + + + SINGLE_LINE_STRING + + + + + + + + ~ + + + + + \ + + + " + + + $ + + + NEWLINE + + + + + + + + + + STRING_CONTENT_DQ + + + + + + + ~ + + + + + \ + + + ' + + + $ + + + NEWLINE + + + + + + + + + + STRING_CONTENT_SQ + + + + + + + + ~ + + + NEWLINE + + + + + + + + + + + + + ~ + + + + + NEWLINE + + + + + + + + + + + + + + diff --git a/topics/grammars/dart/spec/emulate-omission.xbgf b/topics/grammars/dart/spec/emulate-omission.xbgf new file mode 100644 index 00000000..25b61a42 --- /dev/null +++ b/topics/grammars/dart/spec/emulate-omission.xbgf @@ -0,0 +1,341 @@ + + + + + + + + + a + + + . + + + . + + + f + + + + + + + a + + + b + + + c + + + d + + + e + + + f + + + + + + + + + + A + + + . + + + . + + + F + + + + + + + A + + + B + + + C + + + D + + + E + + + F + + + + + + + + + + a + + + . + + + . + + + z + + + + + + + a + + + b + + + c + + + d + + + e + + + f + + + g + + + h + + + i + + + j + + + k + + + l + + + m + + + n + + + o + + + p + + + q + + + r + + + s + + + t + + + u + + + v + + + w + + + x + + + y + + + z + + + + + + + + + + A + + + . + + + . + + + Z + + + + + + + A + + + B + + + C + + + D + + + E + + + F + + + G + + + H + + + I + + + J + + + K + + + L + + + M + + + N + + + O + + + P + + + Q + + + R + + + S + + + T + + + U + + + V + + + W + + + X + + + Y + + + Z + + + + + + + + + + 0 + + + . + + + . + + + 9 + + + + + + + 0 + + + 1 + + + 2 + + + 3 + + + 4 + + + 5 + + + 6 + + + 7 + + + 8 + + + 9 + + + + + diff --git a/topics/grammars/dart/spec/fix-spaces.xbgf b/topics/grammars/dart/spec/fix-spaces.xbgf new file mode 100644 index 00000000..c9eb0d77 --- /dev/null +++ b/topics/grammars/dart/spec/fix-spaces.xbgf @@ -0,0 +1,57 @@ + + + + + + + + , + + + , + + + + + + ~ + + + ~ + + + + + + \ n + \n + + + + + \ r + \r + + + + + + ~/= + ~/= + + + + + + ~/ + ~/ + + + + + + ’’ + _ + + + diff --git a/topics/grammars/dart/spec/grammar.manually.fixed.src b/topics/grammars/dart/spec/grammar.manually.fixed.src new file mode 100644 index 00000000..10d1e880 --- /dev/null +++ b/topics/grammars/dart/spec/grammar.manually.fixed.src @@ -0,0 +1,456 @@ +variableDeclaration: +declaredIdentifier (‘, ’ identifier)* +; +initializedVariableDeclaration: +declaredIdentifier (‘=’ expression)? (‘, ’ initializedIdentifier)* +; +initializedIdentifierList: +initializedIdentifier (‘, ’ initializedIdentifier)* +; +initializedIdentifier: +identifier (‘=’ expression)? +; +declaredIdentifier: +finalVarOrType identifier +; +finalVarOrType:final type? | +var |type +; +functionSignature: +returnType? identifier formalParameterList +; +functionPrefix: +returnType? identifier +; +functionBody: +‘=>’ expression ‘;’ |block +; +block: +‘{’ statements ‘}’ +; +formalParameterList: +‘(’ ‘)’ |‘(’ normalFormalParameters (‘,’ namedFormalParameters)? ‘)’ |(namedFormalParameters) +; +normalFormalParameters: +normalFormalParameter (‘, ’ normalFormalParameter)* +; +namedFormalParameters: +‘[’ defaultFormalParameter (‘, ’ defaultFormalParameter)* ‘]’ +; +normalFormalParameter: +functionSignature |fieldFormalParameter |simpleFormalParameter +; +simpleFormalParameter: +declaredIdentifier | +identifier +; +fieldFormalParameter:finalVarOrType? this ‘.’ identifier +; +defaultFormalParameter: +normalFormalParameter (’=’ expression)? +; +classDefinition:class identifier typeParameters? superclass? interfaces? +‘{’ classMemberDefinition* ‘}’; +classMemberDefinition: +declaration ‘;’ |methodSignature functionBody +; +methodSignature: +factoryConstructorSignature |static functionSignature |getterSignature |setterSignature |operatorSignature |functionSignature initializers? |namedConstructorSignature initializers? +; +declaration: +constantConstructorSignature (redirection | initializers)? |constructorSignature (redirection | initializers)? |functionSignature redirection |namedConstructorSignature redirection | +abstract getterSignature |abstract setterSignature |abstract operatorSignature |abstract functionSignature |static final type? staticFinalDeclarationList |static? initializedVariableDeclaration +; +staticFinalDeclarationList: +:staticFinalDeclaration (’, ’ staticFinalDeclaration)* +; +staticFinalDeclaration: +identifier ’=’ expression +; +operatorSignature: +returnType? operator operator formalParameterList +; +operator: +unaryOperator |binaryOperator |’[]’ |’[]=’ | +negate, +; +unaryOperator: +negateOperator +; +binaryOperator: +multiplicativeOperator |additiveOperator |shiftOperator |relationalOperator |equalityOperator |bitwiseOperator | +; +prefixOperator: +additiveOperator |negateOperator +; +negateOperator: +’!’ |’ ̃’ +; +getterSignature:static? returnType? get identifier formalParameterList +; +setterSignature:static? returnType? set identifier formalParameterList +; +constructorSignature: +identifier formalParameterList |namedConstructorSignature +; +namedConstructorSignature: +identifier ‘.’ identifier formalParameterList +; +redirection:‘:’ this (‘.’ identifier)? arguments +; +initializers: +‘:’ superCallOrFieldInitializer (‘, ’ superCallOrFieldInitializer)* +; +superCallOrFieldInitializer:super arguments | +super ‘.’ identifier arguments |fieldInitializer +; +fieldInitializer:(this ‘.’)? identifier ‘=’ conditionalExpression +; +factoryConstructorSignature:factory qualified typeVariables? (‘.’ identifier)? formalParameterList +; +constantConstructorSignature:const qualified formalParameterList +; +superclass:extends type +; +interfaces: +implements typeList +; +interfaceDefinition: +interface identifier typeParameters? superinterfaces? factorySpecification? ‘{’ (interfaceMemberDefinition)* ‘}’ +; +interfaceMemberDefinition:static final type? initializedIdentifierList ‘;’ | +functionSignature ‘;’ | +constantConstructorSignature ‘;’ |namedConstructorSignature ‘;’ |getterSignature ‘;’ |setterSignature ‘;’ |operatorSignature ‘;’ |variableDeclaration ‘;’ +; +factorySpecification:factory identifier typeParameters? +; +superinterfaces:extends typeList +; +typeParameter:identifier (extends type)? +; +typeParameters: +‘<’ typeParameter (‘,’ typeParameter)* ‘>’ +; +expression: +assignableExpression assignmentOperator expression |conditionalExpression +; +expressionList: +expression (‘, ’ expression)* +; +primary: +thisExpression |super assignableSelector |functionExpression |literal |identifier |newExpression constantObjectExpression |‘(’ expression ‘)’ | +; +literal: +nullLiteral |booleanLiteral |numericLiteral |stringLiteral |mapLiteral |listLiteral +; +nullLiteral: +null +; +numericLiteral: +NUMBER |HEX NUMBER +; +NUMBER: +DIGIT+ (‘.’ DIGIT*)? EXPONENT? |‘.’ DIGIT+ EXPONENT? | +EXPONENT: +(‘e’ | ‘E’) (’+’ | ‘-‘)? DIGIT+ +; +HEX NUMBER: +‘0x’ HEX DIGIT+ |‘0X’ HEX DIGIT+ +; +HEX DIGIT: +‘a’..’f’ |‘A’..’F’ |DIGIT +; +booleanLiteral:true | +false +; +stringLiteral: +‘@’? MULTI LINE STRING |SINGLE LINE STRING +; +SINGLE LINE STRING: +‘”’ STRING CONTENT DQ* ‘”’ |‘’’ STRING CONTENT SQ* ‘\’’ |‘@’ ‘’’ ( ( ‘’’ | NEWLINE ))* ‘’’ |‘@’ ‘”’ ( ( ‘”’ | NEWLINE ))* ‘”’ +; +MULTI LINE STRING: +‘"""’ .* ‘"""’ |‘’’’’ .* ‘’’’’ +; +ESCAPE SEQUENCE: +\n|\r|\f|\b|\t|\v|\ x HEX DIGIT HEX DIGIT |\ u HEX DIGIT HEX DIGIT HEX DIGIT HEX DIGIT |\ u{ HexDigitSequence } +; +HEX DIGIT SEQUENCE: +HEX DIGIT HEX DIGIT? HEX DIGIT? HEX DIGIT? HEX DIGIT?HEX DIGIT? HEX DIGIT? +; +STRING CONTENT DQ: + ̃( ‘\’ | ‘"’ | ‘$’ | NEWLINE ) |‘\’ ̃( NEWLINE ) |STRING INTERPOLATION +; +STRING CONTENT SQ: + ̃( ‘\’ | ‘’’ | ‘$’ | NEWLINE ) |‘\’ ̃( NEWLINE ) |STRING INTERPOLATION +; +NEWLINE: +‘\ n’ |‘\ r’ +; +STRING INTERPOLATION: +‘$’ IDENTIFIER NO DOLLAR |‘$’ ‘{’ Expression ‘}’ +; +listLiteral: +const? typeArguments? ‘[’ (expressionList ‘, ’?)? ‘]’ +; +mapLiteral:const? typeArguments? ‘{’ (mapLiteralEntry (‘, ’ mapLiteralEntry)* ‘, ’?)? ‘}’; +mapLiteralEntry: +identifier ‘:’ expression |stringLiteral ‘:’ expression +; +functionExpression: +(returnType? identifier)? formalParameterList functionExpressionBody +; +functionExpressionBody: +‘=>’ expression |block +; +thisExpression:this +; +newExpression: +new type (‘.’ identifier)? arguments +; +constObjectExpression: +const type (’.’ identifier)? arguments +; +arguments: +‘(’ argumentList? ‘)’ +; +argumentList: +namedArgument (‘, ’ namedArgument)* |expressionList (‘, ’ namedArgument)* +; +namedArgument: +label expression +; +assignmentOperator: +‘=’ |compoundAssignmentOperator +; +compoundAssignmentOperator: +‘*=’ |‘/=’ |‘ ̃/=’ |‘%=’ |‘+=’ |‘-=’ |‘<<=’ |‘>’ ’>’ ’>’ ’=’ ? |‘<’ ’<’ ’=’ ? |‘&=’ | +‘ˆ=’ | +‘|=’ +; +conditionalExpression: +logicalOrExpression (‘?’ expression ‘:’ expression)? +; +logicalOrExpression: +logicalAndExpression (‘||’ logicalAndExpression)* +; +logicalAndExpression: +bitwiseOrExpression (‘&&’ bitwiseOrExpression)* +; +bitwiseOrExpression: +bitwiseXorExpression (‘|’ bitwiseXorExpression)* |super (‘|’ bitwiseXorExpression)+ +; +bitwiseXorExpression: +bitwiseAndExpression (‘ˆ’ bitwiseAndExpression)* |super (‘ˆ’ bitwiseAndExpression)+ +; +bitwiseAndExpression: +equalityExpression (‘&’ equalityExpression)* |super (‘&’ equalityExpression)+ +; +bitwiseOperator: +‘&’ |‘ˆ’ | +‘|’ +; +equalityExpression: +relationalExpression (equalityOperator relationalExpression)? | +super equalityOperator relationalExpression +; +equalityOperator: +‘==’ |‘!=’ |‘===’ |‘!==’ +; +relationalExpression: +shiftExpression (isOperator type | relationalOperator shiftExpression)? | +super relationalOperator shiftExpression +; +relationalOperator: +‘>=’ |‘>’ |‘<=’ |‘<’ +; +shiftExpression: +additiveExpression (shiftOperator additiveExpression)* |super (shiftOperator additiveExpression)+ +; +shiftOperator: +‘<<’ |‘>>>’ |‘>>’ +; +additiveExpression: +multiplicativeExpression (additiveOperator multiplicativeExpression)* | +super (additiveOperator multiplicativeExpression)+ +; +additiveOperator: +‘+’ |‘-’ +; +multiplicativeExpression: +unaryExpression (multiplicativeOperator unaryExpression)* |super (multiplicativeOperator unaryExpression)+ +; +multiplicativeOperator: +‘*’ |‘/’ | +‘%’ |‘ ̃/’ +; +unaryExpression: +prefixExpression |postfixExpression |unaryOperator super |‘-’ super |incrementOperator assignableExpression +; +prefixExpression: +prefixOperator unaryExpression +; +postfixExpression: +assignableExpression postfixOperator |primary selector* +; +postfixOperator: +incrementOperator +; +incrementOperator: +‘++’ |‘–’ +; +assignableExpression: +primary (arguments* assignableSelector)+ |super assignableSelector |identifier +; +selector: +assignableSelector |arguments +; +assignableSelector: +‘[’ expression ‘]’ |‘.’ identifier +; +identifier: +IDENTIFIER NO DOLLAR |IDENTIFIER |BUILT IN IDENTIFIER +; +IDENTIFIER NO DOLLAR: +IDENTIFIER START NO DOLLAR IDENTIFIER PART NO DOLLAR* +; +IDENTIFIER: +IDENTIFIER START IDENTIFIER PART* +; +BUILT IN IDENTIFIER:abstract | +assert |class |extends |factory |get |implements |import |interface | +is | +library |negate, |operator |set |source |static |typedef +; +IDENTIFIER START: +IDENTIFIER START NO DOLLAR |’$’ +; +IDENTIFIER START NO DOLLAR: +LETTER |’’ +; +IDENTIFIER PART NO DOLLAR: +IDENTIFIER START NO DOLLAR |DIGIT +; +IDENTIFIER PART: +IDENTIFIER START |DIGIT +; +qualified: +identifier (‘.’ identifier)? +; +isOperator: +is ‘!’? +; +statements: +statement* +; +statement: +label* nonLabelledStatement +; +nonLabelledStatement: +block |initializedVariableDeclaration ’;’ |forStatement |whileStatement |doStatement |switchStatement |ifStatement |tryStatement |breakStatement |continueStatement |returnStatement |throwStatement |expressionStatement |assertStatement |functionSignature functionBody +; +expressionStatement: +expression? ‘;’ | +; +ifStatement: +if ‘(’ expression ‘)’ statement ( else statement)? +; +forStatement: +for ‘(’ forLoopParts ‘)’ statement +; +forLoopParts: +forInitializerStatement expression? ‘;’ expressionList? |declaredIdentifier in expression |identifier in expression +; +forInitializerStatement: +initializedVariableDeclaration ‘;’ |expression? ‘;’ +; +whileStatement:while ‘(’ expression ‘)’ statement +; +doStatement:do statement while ‘(’ expression ‘)’ ‘;’ +; +switchStatement: +switch ‘(’ expression ‘)’ ‘{’ switchCase* defaultCase? ‘}’ +; +switchCase: +label? (case expression ‘:’)+ statements +; +defaultCase: +label? (case expression ‘:’)* default ‘:’ statements +; +tryStatement:try block (catchPart+ finallyPart? | finallyPart) +; +catchPart:catch ‘(’ declaredIndentifier (‘, ’ declaredIndentifier)? ‘)’ block +; +finallyPart:finally block +; +returnStatement: +return expression? ’;’ +; +label: +identifier ’:’ +; +breakStatement:break identifier? ’;’ +; +continueStatement:continue identifier? ’;’ +; +throwStatement:throw expression? ’;’ +; +assertStatement: +assert ’(’ conditionalExpression ’)’ ’;’ | +topLevelDefinition: +classDefinition |interfaceDefinition |functionTypeAlias |functionSignature functionBody | +returnType? getOrSet identifier formalParameterList functionBody | +final type? staticFinalDeclarationList ’;’ |variableDeclaration ’;’ +; +getOrSet:get | +set +; +libraryDefinition: +scriptTag? libraryName import* include* resource* topLevelDefinition* +; +scriptTag: +’#!’ ( ̃NEWLINE)* NEWLINE | +libraryName: +’#’ ’library’ ’(’ stringLiteral ’)’ ’;’ | +resource: +’#’ ’resource’ ’(’ stringLiteral ’)’ ’;’ +; +libraryImport: +’#’ ’import’ ’(’ stringLiteral (’, ’ ’prefix:’ stringLiteral)? ’)’ ’;’ +; +include: +’#’ ’source’ ’(’ stringLiteral ’)’ ’;’ +; +compilationUnit: +topLevelDefinition* EOF +; +scriptDefinition: +scriptTag? libraryName? import* include* resource* topLevelDefinition* +; +type: +qualified typeArguments? +; +typeArguments: +’<’ typeList ’>’ +; +typeList: +type (’, ’ type)* +; +functionTypeAlias: +typedef functionPrefix typeParameters? formalParameterList ’;’ +; +LETTER: +‘a’ .. ‘z’ |‘A’ ..‘Z’ +; +DIGIT: +‘0’ .. ‘9’ +; +WHITESPACE: +(‘\t’ | ‘ ’ | NEWLINE)+ +; +SINGLE LINE COMMENT: +‘//’ ̃(NEWLINE)* (NEWLINE)? +; +MULTI LINE COMMENT: +‘/*’ (.)* +; diff --git a/topics/grammars/dart/spec/grammar.src b/topics/grammars/dart/spec/grammar.src new file mode 100644 index 00000000..67852540 --- /dev/null +++ b/topics/grammars/dart/spec/grammar.src @@ -0,0 +1,461 @@ +variableDeclaration: +declaredIdentifier (‘, ’ identifier)* +; +initializedVariableDeclaration: +declaredIdentifier (‘=’ expression)? (‘, ’ initializedIdentifier)* +; +initializedIdentifierList: +initializedIdentifier (‘, ’ initializedIdentifier)* +; +initializedIdentifier: +identifier (‘=’ expression)? +; +declaredIdentifier: +finalVarOrType identifier +; +finalVarOrType:final type? | +var |type +; +functionSignature: +returnType? identifier formalParameterList +; +functionPrefix: +returnType? identifier +; +functionBody: +‘=>’ expression ‘;’ |block +; +block: +‘{’ statements ‘}’ +; +formalParameterList: +‘(’ ‘)’ |‘(’ normalFormalParameters (‘, namedFormalParameters)? ‘)’ |(namedFormalParameters) +; +normalFormalParameters: +normalFormalParameter (‘, ’ normalFormalParameter)* +; +namedFormalParameters: +‘[’ defaultFormalParameter (‘, ’ defaultFormalParameter)* ‘]’ +; +normalFormalParameter: +functionSignature |fieldFormalParameter |simpleFormalParameter +; +simpleFormalParameter: +declaredIdentifier | +identifier +; +fieldFormalParameter:finalVarOrType? this ‘.’ identifier +; +defaultFormalParameter: +normalFormalParameter (’=’ expression)? +; +classDefinition:class identifier typeParameters? superclass? interfaces? +‘{’ classMemberDefinition* ‘}’; +classMemberDefinition: +declaration ‘;’ |methodSignature functionBody +; +methodSignature: +factoryConstructorSignature |static functionSignature |getterSignature |setterSignature |operatorSignature |functionSignature initializers? |namedConstructorSignature initializers? +; +declaration: +constantConstructorSignature (redirection | initializers)? |constructorSignature (redirection | initializers)? |functionSignature redirection |namedConstructorSignature redirection | +abstract getterSignature |abstract setterSignature |abstract operatorSignature |abstract functionSignature |static final type? staticFinalDeclarationList |static? initializedVariableDeclaration +; +staticFinalDeclarationList: +:staticFinalDeclaration (’, ’ staticFinalDeclaration)* +; +staticFinalDeclaration: +identifier ’=’ expression +; +operatorSignature: +returnType? operator operator formalParameterList +; +operator: +unaryOperator |binaryOperator |’[]’ |’[]=’ | +negate, +; +unaryOperator: +negateOperator +; +binaryOperator: +multiplicativeOperator |additiveOperator |shiftOperator |relationalOperator |equalityOperator |bitwiseOperator | +; +prefixOperator: +additiveOperator |negateOperator +; +negateOperator: +’!’ |’ ̃’ +; +getterSignature:static? returnType? get identifier formalParameterList +; +setterSignature:static? returnType? set identifier formalParameterList +; +constructorSignature: +identifier formalParameterList |namedConstructorSignature +; +namedConstructorSignature: +identifier ‘.’ identifier formalParameterList +; +redirection:‘:’ this (‘.’ identifier)? arguments +; +initializers: +‘:’ superCallOrFieldInitializer (‘, ’ superCallOrFieldInitializer)* +; +superCallOrFieldInitializer:super arguments | +super ‘.’ identifier arguments |fieldInitializer +; +fieldInitializer:(this ‘.’)? identifier ‘=’ conditionalExpression +; +factoryConstructorSignature:factory qualified typeVariables? (‘.’ identifier)? formalParame- +terList +; +constantConstructorSignature:const qualified formalParameterList +; +superclass:extends type +; +interfaces: +implements typeList +; +interfaceDefinition: +interface identifier typeParameters? superinterfaces? factorySpec-ification? ‘{’ (interfaceMemberDefinition)* ‘}’ +; +interfaceMemberDefinition:static final type? initializedIdentifierList ‘;’ | +functionSignature ‘;’ | +constantConstructorSignature ‘;’ |namedConstructorSignature ‘;’ |getterSignature ‘;’ |setterSignature ‘;’ |operatorSignature ‘;’ |variableDeclaration ‘;’ +; +factorySpecification:factory identifier typeParameters? +; +superinterfaces:extends typeList +; +typeParameter:identifier (extends type)? +; +typeParameters: +‘<’ typeParameter (‘,’ typeParameter)* ‘>’ +; +expression: +assignableExpression assignmentOperator expression |conditionalExpression +; +expressionList: +expression (‘, ’ expression)* +; +primary: +thisExpression |super assignableSelector |functionExpression |literal |identifier |newExpression constantObjectExpression |‘(’ expression ‘)’ | +; +literal: +nullLiteral |booleanLiteral |numericLiteral |stringLiteral |mapLiteral |listLiteral +; +nullLiteral: +null +; +numericLiteral: +NUMBER |HEX NUMBER +; +NUMBER: +DIGIT+ (‘.’ DIGIT*)? EXPONENT? |‘.’ DIGIT+ EXPONENT? | +EXPONENT: +(‘e’ | ‘E’) (’+’ | ‘-‘)? DIGIT+ +; +HEX NUMBER: +‘0x’ HEX DIGIT+ |‘0X’ HEX DIGIT+ +; +HEX DIGIT: +‘a’..’f’ |‘A’..’F’ |DIGIT +; +booleanLiteral:true | +false +; +stringLiteral: +‘@’? MULTI LINE STRING |SINGLE LINE STRING +; +SINGLE LINE STRING: +‘”’ STRING CONTENT DQ* ‘”’ |‘’’ STRING CONTENT SQ* ‘\’’ |‘@’ ‘’’ ( ( ‘’’ | NEWLINE ))* ‘’’ |‘@’ ‘”’ ( ( ‘”’ | NEWLINE ))* ‘”’ +; +MULTI LINE STRING: +‘"""’ .* ‘"""’ |‘’’’’ .* ‘’’’’ +; +ESCAPE SEQUENCE: +\n|\r|\f|\b|\t|\v|\ x HEX DIGIT HEX DIGIT |\ u HEX DIGIT HEX DIGIT HEX DIGIT HEX DIGIT |\ u{ HexDigitSequence } +; +HEX DIGIT SEQUENCE: +HEX DIGIT HEX DIGIT? HEX DIGIT? HEX DIGIT? HEX DIGIT?HEX DIGIT? HEX DIGIT? +; +STRING CONTENT DQ: + ̃( ‘\’ | ‘"’ | ‘$’ | NEWLINE ) |‘\’ ̃( NEWLINE ) |STRING INTERPOLATION +; +STRING CONTENT SQ: + ̃( ‘\’ | ‘’’ | ‘$’ | NEWLINE ) |‘\’ ̃( NEWLINE ) |STRING INTERPOLATION +; +NEWLINE: +‘\ n’ |‘\ r’ +; +STRING INTERPOLATION: +‘$’ IDENTIFIER NO DOLLAR |‘$’ ‘{’ Expression ‘}’ +; +listLiteral: +const? typeArguments? ‘[’ (expressionList ‘, ’?)? ‘]’ +; +mapLiteral:const? typeArguments? ‘{’ (mapLiteralEntry (‘, ’ mapLitera- +lEntry)* ‘, ’?)? ‘}’; +mapLiteralEntry: +identifier ‘:’ expression |stringLiteral ‘:’ expression +; +functionExpression: +(returnType? identifier)? formalParameterList functionExpres-sionBody +; +functionExpressionBody: +‘=>’ expression |block +; +thisExpression:this +; +newExpression: +new type (‘.’ identifier)? arguments +; +constOb jectExpression: +const type (’.’ identifier)? arguments +; +arguments: +‘(’ argumentList? ‘)’ +; +argumentList: +namedArgument (‘, ’ namedArgument)* |expressionList (‘, ’ namedArgument)* +; +namedArgument: +label expression +; +assignmentOperator: +‘=’ |compoundAssignmentOperator +; +compoundAssignmentOperator: +‘*=’ |‘/=’ |‘ ̃/=’ |‘%=’ |‘+=’ |‘-=’ |‘<<=’ |‘>’ ’>’ ’>’ ’=’ ? |‘<’ ’<’ ’=’ ? |‘&=’ | +‘ˆ=’ | +‘|=’ +; +conditionalExpression: +logicalOrExpression (‘?’ expression ‘:’ expression)? +; +logicalOrExpression: +logicalAndExpression (‘||’ logicalAndExpression)* +; +logicalAndExpression: +bitwiseOrExpression (‘&&’ bitwiseOrExpression)* +; +bitwiseOrExpression: +bitwiseXorExpression (‘|’ bitwiseXorExpression)* |super (‘|’ bitwiseXorExpression)+ +; +bitwiseXorExpression: +bitwiseAndExpression (‘ˆ’ bitwiseAndExpression)* |super (‘ˆ’ bitwiseAndExpression)+ +; +bitwiseAndExpression: +equalityExpression (‘&’ equalityExpression)* |super (‘&’ equalityExpression)+ +; +bitwiseOperator: +‘&’ |‘ˆ’ | +‘|’ +; +equalityExpression: +relationalExpression (equalityOperator relationalExpression)? | +super equalityOperator relationalExpression +; +equalityOperator: +‘==’ |‘!=’ |‘===’ |‘!==’ +; +relationalExpression: +shiftExpression (isOperator type | relationalOperator shiftExpres-sion)? | +super relationalOperator shiftExpression +; +relationalOperator: +‘>=’ |‘>’ |‘<=’ |‘<’ +; +shiftExpression: +additiveExpression (shiftOperator additiveExpression)* |super (shiftOperator additiveExpression)+ +; +shiftOperator: +‘<<’ |‘>>>’ |‘>>’ +; +additiveExpression: +multiplicativeExpression (additiveOperator multiplicativeExpres-sion)* | +super (additiveOperator multiplicativeExpression)+ +; +additiveOperator: +‘+’ |‘-’ +; +multiplicativeExpression: +unaryExpression (multiplicativeOperator unaryExpression)* |super (multiplicativeOperator unaryExpression)+ +; +multiplicativeOperator: +‘*’ |‘/’ | +‘%’ |‘ ̃/’ +; +unaryExpression: +prefixExpression |postfixExpression |unaryOperator super |‘-’ super |incrementOperator assignableExpression +; +prefixExpression: +prefixOperator unaryExpression +; +postfixExpression: +assignableExpression postfixOperator |primary selector* +; +postfixOperator: +incrementOperator +; +incrementOperator: +‘++’ |‘–’ +; +assignableExpression: +primary (arguments* assignableSelector)+ |super assignableSelector |identifier +; +selector: +assignableSelector |arguments +; +assignableSelector: +‘[’ expression ‘]’ |‘.’ identifier +; +identifier: +IDENTIFIER NO DOLLAR |IDENTIFIER |BUILT IN IDENTIFIER +; +IDENTIFIER NO DOLLAR: +IDENTIFIER START NO DOLLAR IDENTIFIER PART NO DOLLAR* +; +IDENTIFIER: +IDENTIFIER START IDENTIFIER PART* +; +BUILT IN IDENTIFIER:abstract | +assert |class |extends |factory |get |implements |import |interface | +is | +library |negate, |operator |set |source |static |typedef +; +IDENTIFIER START: +IDENTIFIER START NO DOLLAR |’$’ +; +IDENTIFIER START NO DOLLAR: +LETTER |’’ +; +IDENTIFIER PART NO DOLLAR: +IDENTIFIER START NO DOLLAR |DIGIT +; +IDENTIFIER PART: +IDENTIFIER START |DIGIT +; +qualified: +identifier (‘.’ identifier)? +; +isOperator: +is ‘!’? +; +statements: +statement* +; +statement: +label* nonLabelledStatement +; +nonLabelledStatement: +block |initializedVariableDeclaration ’;’ |forStatement |whileStatement |doStatement |switchStatement |ifStatement |tryStatement |breakStatement |continueStatement |returnStatement |throwStatement |expressionStatement |assertStatement |functionSignature functionBody +; +expressionStatement: +expression? ‘;’ | +; +ifStatement: +if ‘(’ expression ‘)’ statement ( else statement)? +; +forStatement: +for ‘(’ forLoopParts ‘)’ statement +; +forLoopParts: +forInitializerStatement expression? ‘;’ expressionList? |declaredIdentifier in expression |identifier in expression +; +forInitializerStatement: +initializedVariableDeclaration ‘;’ |expression? ‘;’ +; +whileStatement:while ‘(’ expression ‘)’ statement +; +doStatement:do statement while ‘(’ expression ‘)’ ‘;’ +; +switchStatement: +switch ‘(’ expression ‘)’ ‘{’ switchCase* defaultCase? ‘}’ +; +switchCase: +label? (case expression ‘:’)+ statements +; +defaultCase: +label? (case expression ‘:’)* default ‘:’ statements +; +tryStatement:try block (catchPart+ finallyPart? | finallyPart) +; +catchPart:catch ‘(’ declaredIndentifier (‘, ’ declaredIndentifier)? ‘)’ block +; +finallyPart:finally block +; +returnStatement: +return expression? ’;’ +; +label: +identifier ’:’ +; +breakStatement:break identifier? ’;’ +; +continueStatement:continue identifier? ’;’ +; +throwStatement:throw expression? ’;’ +; +assertStatement: +assert ’(’ conditionalExpression ’)’ ’;’ | +; +topLevelDefinition: +classDefinition |interfaceDefinition |functionTypeAlias |functionSignature functionBody | +returnType? getOrSet identifier formalParameterList function-Body | +final type? staticFinalDeclarationList ’;’ |variableDeclaration ’;’ +; +getOrSet:get | +set +; +libraryDefinition: +scriptTag? libraryName import* include* resource* topLevelDef-inition* +; +scriptTag: +’#!’ ( ̃NEWLINE)* NEWLINE | +; +libraryName: +’#’ ’library’ ’(’ stringLiteral ’)’ ’;’ | +; +resource: +’#’ ’resource’ ’(’ stringLiteral ’)’ ’;’ +; +libraryImport: +’#’ ’import’ ’(’ stringLiteral (’, ’ ’prefix:’ stringLiteral)? ’) ’;’ +; +include: +’#’ ’source’ ’(’ stringLiteral ’)’ ’;’ +; +compilationUnit: +topLevelDefinition* EOF +; +scriptDefinition: +scriptTag? libraryName? import* include* resource* topLevelDef-inition* +; +type: +qualified typeArguments? +; +typeArguments: +’<’ typeList ’>’ +; +typeList: +type (’, ’ type)* +; +functionTypeAlias: +typedef functionPrefix typeParameters? formalParameterList ’;’ +; +LETTER: +‘a’ .. ‘z’ |‘A’ ..‘Z’ +; +DIGIT: +‘0’ .. ‘9’ +; +WHITESPACE: +(‘\t’ | ‘ ’ | NEWLINE)+ +; +SINGLE LINE COMMENT: +‘//’ ̃(NEWLINE)* (NEWLINE)? +; +MULTI LINE COMMENT: +‘/*’ (.)* +; diff --git a/topics/grammars/dart/spec/post-extract.xbgf b/topics/grammars/dart/spec/post-extract.xbgf new file mode 100644 index 00000000..5665e1cb --- /dev/null +++ b/topics/grammars/dart/spec/post-extract.xbgf @@ -0,0 +1,63 @@ + + + + + + + + operator + + + operator + + + + + + + operator + + + operator + + + + + operatorSignature + + + + + operator + + + operator + + + BUILT_IN_IDENTIFIER + + + + + + import + + + import + + + libraryDefinition + + + + + import + + + import + + + scriptDefinition + + + diff --git a/topics/grammars/dart/spec/unite-misspellings.xbgf b/topics/grammars/dart/spec/unite-misspellings.xbgf new file mode 100644 index 00000000..cc3d0e18 --- /dev/null +++ b/topics/grammars/dart/spec/unite-misspellings.xbgf @@ -0,0 +1,27 @@ + + + + + + constObjectExpression + constantObjectExpression + + + + + Expression + + + Expression + + + + Expression + expression + + + + import + libraryImport + + diff --git a/topics/recovery/hunter/hunter.py b/topics/recovery/hunter/hunter.py index 53eb59c0..03a1a130 100755 --- a/topics/recovery/hunter/hunter.py +++ b/topics/recovery/hunter/hunter.py @@ -57,10 +57,12 @@ 'NONTERMINAL-IF-UPPERCASE', 'NONTERMINAL-IF-LOWERCASE', 'NONTERMINAL-IF-CAMELCASE', + 'NONTERMINAL-IF-MIXEDCASE', 'TERMINAL-IF-UNDEFINED', 'TERMINAL-IF-UPPERCASE', 'TERMINAL-IF-LOWERCASE', 'TERMINAL-IF-CAMELCASE', + 'TERMINAL-IF-MIXEDCASE', 'IGNORE-EXTRA-NEWLINES', 'GLUE-NONALPHANUMERIC-TERMINALS', ] @@ -75,6 +77,9 @@ def isLowerCase(x): def isCamelCase(x): return isUpperCase(x[0]) and not isUpperCase(x) and isAlpha(x) +def isMixedCase(x): + return isLowerCase(x[0]) and not isLowerCase(x) and isAlpha(x) + def isAlphaNum(x): return reduce(lambda a,b:a and (b.isalnum() or b in nonterminals_alphabet),x,True) @@ -205,14 +210,14 @@ def readConfig(f): config[e.tag] = e.text.replace('\\n','\n') else: config[e.tag] = '' - if e.tag in ('nonterminal-if-camelcase','nonterminal-if-uppercase','nonterminal-if-lowercase','nonterminal-if-contains','nonterminal-if-defined','decompose-symbols'): + if e.tag in ('nonterminal-if-camelcase','nonterminal-if-mixedcase','nonterminal-if-uppercase','nonterminal-if-lowercase','nonterminal-if-contains','nonterminal-if-defined','decompose-symbols'): if e.text: config[e.tag] = e.text else: config[e.tag] = '' for x in e.findall('except'): always_terminals.append(x.text) - if e.tag in ('terminal-if-camelcase','terminal-if-uppercase','terminal-if-lowercase','terminal-if-undefined'): + if e.tag in ('terminal-if-camelcase','terminal-if-mixedcase','terminal-if-uppercase','terminal-if-lowercase','terminal-if-undefined'): config[e.tag] = '' for x in e.findall('except'): always_nonterminals.append(x.text) @@ -671,6 +676,10 @@ def map2expr(ss): e.setName(ss[i][1:-1]) es.append(e) i += 1 + elif ss[i] in metasymbols: + print('STEP 9:',ss[i],'found untouched at serialisation stage, turned into a terminal symbol "'+config[ss[i].lower()]+'"') + ss[i] = config['start-terminal-symbol'] + config[ss[i].lower()] + config['end-terminal-symbol'] + continue else: if debug: print('NONTERMINAL',ss[i]) @@ -704,7 +713,7 @@ def map2expr(ss): for es in ess: if len(es) == 0: print('Serialisation warning: empty internal output sequence, treating like epsilon!') - return BGF3.Expression(BGF3.Epsilon()) + e.add(BGF3.Expression(BGF3.Epsilon())) elif len(es) == 1: e.add(BGF3.Expression(es[0])) else: @@ -911,6 +920,9 @@ def convert2terminal(x,defd): if 'nonterminal-if-camelcase' in config.keys() and len(x)>1 and isCamelCase(x): # configuration claims that CamelCase is a nonterminal return x + if 'nonterminal-if-mixedcase' in config.keys() and len(x)>1 and isMixedCase(x): + # configuration claims that mixedCase is a nonterminal + return x # none of the above return config['start-terminal-symbol'] + x + config['end-terminal-symbol'] @@ -935,6 +947,9 @@ def convert2nonterminal(x,defd): if 'terminal-if-camelcase' in config.keys() and isCamelCase(y): # configuration claims that CamelCase is a terminal return x + if 'terminal-if-mixedcase' in config.keys() and isMixedCase(y): + # configuration claims that mixedCase is a terminal + return x if y in defd: # The moment of truth: could it be a defined nonterminal? return y @@ -946,7 +961,7 @@ def balanceProd(p): i = 2 # balance forward while i-1)