Skip to content

Commit

Permalink
Dart grammar extracted from the spec
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@1119 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Oct 10, 2011
1 parent 6171487 commit 83ea9e4
Show file tree
Hide file tree
Showing 15 changed files with 1,972 additions and 10 deletions.
1 change: 1 addition & 0 deletions topics/grammars/dart/ready.lst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
google
spec
37 changes: 37 additions & 0 deletions topics/grammars/dart/spec/Makefile
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions topics/grammars/dart/spec/README.txt
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions topics/grammars/dart/spec/complete.xbgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<xbgf:sequence xmlns:xbgf="http://planet-sl.org/xbgf" xmlns:bgf="http://planet-sl.org/bgf">
<!-- returnType is defined nowhere, its definition grabbed from the ANTLR version of the grammar -->
<xbgf:define>
<bgf:production>
<nonterminal>returnType</nonterminal>
<bgf:expression>
<choice>
<bgf:expression>
<terminal>void</terminal>
</bgf:expression>
<bgf:expression>
<nonterminal>type</nonterminal>
</bgf:expression>
</choice>
</bgf:expression>
</bgf:production>
</xbgf:define>
</xbgf:sequence>
109 changes: 109 additions & 0 deletions topics/grammars/dart/spec/correct.xbgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<xbgf:sequence xmlns:xbgf="http://planet-sl.org/xbgf" xmlns:bgf="http://planet-sl.org/bgf">
<!-- Superfluous colon on p.13 of the PDF:
staticFinalDeclarationList:
:
staticFinalDeclaration (’, ’ staticFinalDeclaration)*
;
-->
<xbgf:abstractize>
<bgf:production>
<nonterminal>staticFinalDeclarationList</nonterminal>
<bgf:expression>
<sequence>
<bgf:expression>
<marked>
<bgf:expression>
<terminal>:</terminal>
</bgf:expression>
</marked>
</bgf:expression>
<bgf:expression>
<nonterminal>staticFinalDeclaration</nonterminal>
</bgf:expression>
<bgf:expression>
<star>
<bgf:expression>
<sequence>
<bgf:expression>
<terminal>,</terminal>
</bgf:expression>
<bgf:expression>
<nonterminal>staticFinalDeclaration</nonterminal>
</bgf:expression>
</sequence>
</bgf:expression>
</star>
</bgf:expression>
</sequence>
</bgf:expression>
</bgf:production>
</xbgf:abstractize>
<!-- strange misspelling encountered in definitions of operator and BUILT_IN_IDENTIFIER -->
<xbgf:replace>
<bgf:expression>
<sequence>
<bgf:expression>
<terminal>negate</terminal>
</bgf:expression>
<bgf:expression>
<terminal>,</terminal>
</bgf:expression>
</sequence>
</bgf:expression>
<bgf:expression>
<terminal>negate</terminal>
</bgf:expression>
</xbgf:replace>
<!-- Cleaning up ANTLR leftovers -->
<xbgf:vertical>
<nonterminal>ESCAPE_SEQUENCE</nonterminal>
</xbgf:vertical>
<xbgf:abstractize>
<bgf:production>
<nonterminal>ESCAPE_SEQUENCE</nonterminal>
<bgf:expression>
<sequence>
<bgf:expression>
<terminal>\</terminal>
</bgf:expression>
<bgf:expression>
<terminal>u</terminal>
</bgf:expression>
<bgf:expression>
<marked>
<bgf:expression>
<sequence>
<bgf:expression>
<terminal>{</terminal>
</bgf:expression>
<bgf:expression>
<terminal>HexDigitSequence</terminal>
</bgf:expression>
<bgf:expression>
<terminal>}</terminal>
</bgf:expression>
</sequence>
</bgf:expression>
</marked>
</bgf:expression>
</sequence>
</bgf:expression>
</bgf:production>
</xbgf:abstractize>
<xbgf:horizontal>
<nonterminal>ESCAPE_SEQUENCE</nonterminal>
</xbgf:horizontal>
<!-- Error raised from ANTLR/LaTeX incompatibility -->
<xbgf:replace>
<bgf:expression>
<terminal>–</terminal>
</bgf:expression>
<bgf:expression>
<terminal>--</terminal>
</bgf:expression>
<in>
<nonterminal>incrementOperator</nonterminal>
</in>
</xbgf:replace>
</xbgf:sequence>
111 changes: 111 additions & 0 deletions topics/grammars/dart/spec/drop-empty-alternatives.xbgf
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<xbgf:sequence xmlns:xbgf="http://planet-sl.org/xbgf" xmlns:bgf="http://planet-sl.org/bgf">
<!-- last alternative in a production ends with a "|" signifying an (empty) alternative after it -->
<!-- binaryOperator -->
<xbgf:vertical>
<nonterminal>binaryOperator</nonterminal>
</xbgf:vertical>
<xbgf:remove>
<vertical>
<bgf:production>
<nonterminal>binaryOperator</nonterminal>
<bgf:expression>
<epsilon/>
</bgf:expression>
</bgf:production>
</vertical>
</xbgf:remove>
<xbgf:horizontal>
<nonterminal>binaryOperator</nonterminal>
</xbgf:horizontal>
<!-- primary -->
<xbgf:vertical>
<nonterminal>primary</nonterminal>
</xbgf:vertical>
<xbgf:remove>
<vertical>
<bgf:production>
<nonterminal>primary</nonterminal>
<bgf:expression>
<epsilon/>
</bgf:expression>
</bgf:production>
</vertical>
</xbgf:remove>
<xbgf:horizontal>
<nonterminal>primary</nonterminal>
</xbgf:horizontal>
<!-- NUMBER -->
<xbgf:vertical>
<nonterminal>NUMBER</nonterminal>
</xbgf:vertical>
<xbgf:remove>
<vertical>
<bgf:production>
<nonterminal>NUMBER</nonterminal>
<bgf:expression>
<epsilon/>
</bgf:expression>
</bgf:production>
</vertical>
</xbgf:remove>
<xbgf:horizontal>
<nonterminal>NUMBER</nonterminal>
</xbgf:horizontal>
<!-- expressionStatement -->
<xbgf:vertical>
<nonterminal>expressionStatement</nonterminal>
</xbgf:vertical>
<xbgf:remove>
<vertical>
<bgf:production>
<nonterminal>expressionStatement</nonterminal>
<bgf:expression>
<epsilon/>
</bgf:expression>
</bgf:production>
</vertical>
</xbgf:remove>
<!-- assertStatement -->
<xbgf:vertical>
<nonterminal>assertStatement</nonterminal>
</xbgf:vertical>
<xbgf:remove>
<vertical>
<bgf:production>
<nonterminal>assertStatement</nonterminal>
<bgf:expression>
<epsilon/>
</bgf:expression>
</bgf:production>
</vertical>
</xbgf:remove>
<!-- scriptTag -->
<xbgf:vertical>
<nonterminal>scriptTag</nonterminal>
</xbgf:vertical>
<xbgf:remove>
<vertical>
<bgf:production>
<nonterminal>scriptTag</nonterminal>
<bgf:expression>
<epsilon/>
</bgf:expression>
</bgf:production>
</vertical>
</xbgf:remove>
<!-- libraryName -->
<xbgf:vertical>
<nonterminal>libraryName</nonterminal>
</xbgf:vertical>
<xbgf:remove>
<vertical>
<bgf:production>
<nonterminal>libraryName</nonterminal>
<bgf:expression>
<epsilon/>
</bgf:expression>
</bgf:production>
</vertical>
</xbgf:remove>
</xbgf:sequence>
55 changes: 55 additions & 0 deletions topics/grammars/dart/spec/ebnf.edd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<edd:config xmlns:edd="http://planet-sl.org/edd">
<!-- Crafted by Vadim Zaytsev, http://grammarware.net -->
<defining-symbol>:</defining-symbol>
<terminator-symbol>;</terminator-symbol>
<definition-separator-symbol>|</definition-separator-symbol>
<start-group-symbol>(</start-group-symbol>
<end-group-symbol>)</end-group-symbol>
<start-terminal-symbol>’</start-terminal-symbol>
<end-terminal-symbol>’</end-terminal-symbol>
<postfix-option-symbol>?</postfix-option-symbol>
<postfix-repetition-star-symbol>*</postfix-repetition-star-symbol>
<!-- the following metasymbol is never explained yet still used-->
<postfix-repetition-plus-symbol>+</postfix-repetition-plus-symbol>
<!-- standard? -->
<nonterminals-may-contain>_</nonterminals-may-contain>
<nonterminal-if-mixedcase/>
<terminal-if-undefined>
<except>EOF</except>
</terminal-if-undefined>
<ignore>
<newline/>
<!-- <lines-containing>#</lines-containing>-->
</ignore>
<!--
SINGLE_LINE_STRING:
’”’ STRING_CONTENT_DQ* ’”’ |’’’ STRING_CONTENT_SQ* ’\’’ |’@’ ’’’ ( ( ’’’ | NEWLINE ))* ’’’ |’@’ ’”’ ( ( ’”’ | NEWLINE ))* ’”’
;
MULTI_LINE_STRING:
’"""’ .* ’"""’ |’’’’’ .* ’’’’’
;
-->
<!-- Fixing SINGLE_LINE_STRING -->
<mask>
<token>’”’</token>
<terminal>"</terminal>
</mask>
<mask>
<token>’’’</token>
<terminal>'</terminal>
</mask>
<mask>
<token>’\’’</token>
<terminal>'</terminal>
</mask>
<!-- Fixing MULTI_LINE_STRING -->
<mask>
<token>’"""’</token>
<terminal>"""</terminal>
</mask>
<mask>
<token>’’’’’</token>
<terminal>'''</terminal>
</mask>
</edd:config>
Loading

0 comments on commit 83ea9e4

Please sign in to comment.