├── .gitignore ├── Contrib ├── Editors │ ├── Sugar.tmbundle │ │ ├── Commands │ │ │ ├── Show class : method definition.tmCommand │ │ │ └── Syntax Validator.tmCommand │ │ ├── DragCommands │ │ │ └── image to string.tmDragCommand │ │ ├── Macros │ │ │ └── Select content of String.tmMacro │ │ ├── Preferences │ │ │ ├── Comments.tmPreferences │ │ │ ├── Indentation.tmPreferences │ │ │ └── Symbols.tmPreferences │ │ ├── Snippets │ │ │ ├── @class.tmSnippet │ │ │ ├── @function.tmSnippet │ │ │ ├── @method.tmSnippet │ │ │ ├── @operation.tmSnippet │ │ │ ├── @property.tmSnippet │ │ │ ├── Continue Line Comment Sugar.tmSnippet │ │ │ ├── UnitTest.tmSnippet │ │ │ ├── bind.tmSnippet │ │ │ ├── click.tmSnippet │ │ │ ├── forin.tmSnippet │ │ │ ├── html button.tmSnippet │ │ │ ├── html div.tmSnippet │ │ │ ├── html img.tmSnippet │ │ │ ├── if.tmSnippet │ │ │ └── trigger.tmSnippet │ │ ├── Syntaxes │ │ │ └── Sugar JavaScript.tmLanguage │ │ ├── Templates │ │ │ └── Class.tmTemplate │ │ │ │ ├── class.sjs │ │ │ │ └── info.plist │ │ └── info.plist │ ├── sugar-mode.el │ └── sugar.vim ├── python-module-loader.py └── sugar-cleaner.py ├── Dependencies ├── d-1.15-patched │ ├── 4calc.g │ ├── 4calc.in │ ├── BUILD_VERSION │ ├── CHANGES │ ├── COPYRIGHT │ ├── Makefile │ ├── README │ ├── arg.c │ ├── arg.h │ ├── baseline │ ├── d.h │ ├── dparse.h │ ├── dparse_tables.h │ ├── dparse_tree.c │ ├── dparse_tree.h │ ├── driver_parsetree.c │ ├── dsymtab.h │ ├── faq.html │ ├── gram.c │ ├── gram.h │ ├── gramgram.h │ ├── grammar.g │ ├── grammar.g.c │ ├── index.html │ ├── lex.c │ ├── lex.h │ ├── lr.c │ ├── lr.h │ ├── make_dparser.1 │ ├── make_dparser.c │ ├── make_dparser.cat │ ├── manual.html │ ├── mkdparse.c │ ├── mkdparse.h │ ├── my.c │ ├── my.g │ ├── parse.c │ ├── parse.h │ ├── parser_tests │ ├── python │ │ ├── Makefile │ │ ├── README │ │ ├── contrib │ │ │ ├── dparserpy-syntax_error.py │ │ │ └── dparserpy.el │ │ ├── dparser.i │ │ ├── dparser.py │ │ ├── dparser_wrap.c │ │ ├── index.html │ │ ├── make_tables.c │ │ ├── py_dparser_manual.html │ │ ├── pydparser.c │ │ ├── pydparser.h │ │ ├── setup.py │ │ └── tests │ │ │ ├── runtests.py │ │ │ ├── test.py │ │ │ ├── test2.py │ │ │ ├── test3.py │ │ │ ├── test4.py │ │ │ ├── test5.py │ │ │ ├── test6.py │ │ │ ├── test7.py │ │ │ ├── test8.py │ │ │ └── test9.py │ ├── read_binary.c │ ├── read_binary.h │ ├── sample.g │ ├── sample_parser.c │ ├── scan.c │ ├── scan.h │ ├── symtab.c │ ├── test_parser.c │ ├── tests │ │ ├── 3 │ │ ├── ansic.test.g │ │ ├── ansic.test.g.1 │ │ ├── ansic.test.g.1.check │ │ ├── ansic.test.g.2 │ │ ├── ansic.test.g.2.check │ │ ├── g1.test.g │ │ ├── g1.test.g.1 │ │ ├── g1.test.g.1.check │ │ ├── g10.test.g │ │ ├── g10.test.g.1 │ │ ├── g10.test.g.1.check │ │ ├── g11.test.g │ │ ├── g11.test.g.1 │ │ ├── g11.test.g.1.check │ │ ├── g11.test.g.2 │ │ ├── g11.test.g.2.check │ │ ├── g11.test.g.3 │ │ ├── g11.test.g.3.check │ │ ├── g12.test.g │ │ ├── g12.test.g.1 │ │ ├── g12.test.g.1.check │ │ ├── g13.test.g │ │ ├── g13.test.g.1 │ │ ├── g13.test.g.1.check │ │ ├── g14.test.g │ │ ├── g14.test.g.1 │ │ ├── g14.test.g.1.check │ │ ├── g15.test.g │ │ ├── g15.test.g.1 │ │ ├── g15.test.g.1.check │ │ ├── g16.test.g │ │ ├── g16.test.g.1 │ │ ├── g16.test.g.1.check │ │ ├── g17.test.g │ │ ├── g17.test.g.1 │ │ ├── g17.test.g.1.check │ │ ├── g18.test.g │ │ ├── g18.test.g.1 │ │ ├── g18.test.g.1.check │ │ ├── g19.test.g │ │ ├── g19.test.g.1 │ │ ├── g19.test.g.1.check │ │ ├── g2.test.g │ │ ├── g2.test.g.1 │ │ ├── g2.test.g.1.check │ │ ├── g20.test.g │ │ ├── g20.test.g.1 │ │ ├── g20.test.g.1.check │ │ ├── g21.test.g │ │ ├── g21.test.g.1 │ │ ├── g21.test.g.1.check │ │ ├── g22.test.g │ │ ├── g22.test.g.1 │ │ ├── g22.test.g.1.check │ │ ├── g23.test.g │ │ ├── g23.test.g.1 │ │ ├── g23.test.g.1.check │ │ ├── g24.test.g │ │ ├── g24.test.g.1 │ │ ├── g24.test.g.1.check │ │ ├── g25.test.g │ │ ├── g25.test.g.1 │ │ ├── g25.test.g.1.check │ │ ├── g26.test.g │ │ ├── g26.test.g.1 │ │ ├── g26.test.g.1.check │ │ ├── g27.test.g │ │ ├── g27.test.g.1 │ │ ├── g27.test.g.1.check │ │ ├── g28.test.g │ │ ├── g28.test.g.1 │ │ ├── g28.test.g.1.check │ │ ├── g28.test.g.2 │ │ ├── g28.test.g.2.check │ │ ├── g29.test.g │ │ ├── g29.test.g.1 │ │ ├── g29.test.g.1.check │ │ ├── g3.test.g │ │ ├── g3.test.g.1 │ │ ├── g3.test.g.1.check │ │ ├── g30.test.g │ │ ├── g30.test.g.1 │ │ ├── g30.test.g.1.check │ │ ├── g31.test.g │ │ ├── g31.test.g.1 │ │ ├── g31.test.g.1.check │ │ ├── g32.test.g │ │ ├── g32.test.g.1 │ │ ├── g32.test.g.1.check │ │ ├── g32.test.g.orig │ │ ├── g33.test.g │ │ ├── g33.test.g.1 │ │ ├── g33.test.g.1.check │ │ ├── g33.test.g.orig │ │ ├── g34.test.g │ │ ├── g34.test.g.1 │ │ ├── g34.test.g.1.check │ │ ├── g35.test.g │ │ ├── g35.test.g.1 │ │ ├── g35.test.g.1.check │ │ ├── g36.test.g │ │ ├── g36.test.g.1 │ │ ├── g36.test.g.1.check │ │ ├── g37.test.g │ │ ├── g37.test.g.1 │ │ ├── g37.test.g.1.check │ │ ├── g38.test.g │ │ ├── g38.test.g.1 │ │ ├── g38.test.g.1.check │ │ ├── g38.test.g.1.flags │ │ ├── g38.test.g.flags │ │ ├── g39.test.g │ │ ├── g39.test.g.1 │ │ ├── g39.test.g.1.check │ │ ├── g4.test.g │ │ ├── g4.test.g.1 │ │ ├── g4.test.g.1.check │ │ ├── g40.test.g │ │ ├── g40.test.g.1 │ │ ├── g40.test.g.1.check │ │ ├── g41.test.g │ │ ├── g41.test.g.1 │ │ ├── g41.test.g.1.check │ │ ├── g41.test.g.1.flags │ │ ├── g41.test.g.flags │ │ ├── g42.include.g │ │ ├── g42.test.g │ │ ├── g42.test.g.1 │ │ ├── g42.test.g.1.check │ │ ├── g43.test.g │ │ ├── g43.test.g.1 │ │ ├── g43.test.g.1.check │ │ ├── g43.test.g.2 │ │ ├── g43.test.g.2.check │ │ ├── g43.test.g.2.flags │ │ ├── g43.test.g.3 │ │ ├── g43.test.g.3.check │ │ ├── g43.test.g.3.flags │ │ ├── g44.test.g │ │ ├── g44.test.g.1 │ │ ├── g44.test.g.1.check │ │ ├── g45.test.g │ │ ├── g45.test.g.1 │ │ ├── g45.test.g.1.check │ │ ├── g46.test.g │ │ ├── g46.test.g.1 │ │ ├── g46.test.g.1.check │ │ ├── g5.test.g │ │ ├── g5.test.g.1 │ │ ├── g5.test.g.1.check │ │ ├── g6.test.g │ │ ├── g6.test.g.1 │ │ ├── g6.test.g.1.check │ │ ├── g7.test.g │ │ ├── g7.test.g.1 │ │ ├── g7.test.g.1.check │ │ ├── g7.test.g.2 │ │ ├── g7.test.g.2.check │ │ ├── g8.test.g │ │ ├── g8.test.g.1 │ │ ├── g8.test.g.1.check │ │ ├── g9.test.g │ │ ├── g9.test.g.1 │ │ ├── g9.test.g.1.check │ │ ├── python.test.g │ │ ├── python.test.g.1 │ │ ├── python.test.g.1.check │ │ ├── sample.test.g │ │ ├── sample.test.g.0 │ │ ├── sample.test.g.0.check │ │ ├── sample.test.g.1 │ │ ├── sample.test.g.1.check │ │ ├── sample.test.g.10 │ │ ├── sample.test.g.10.check │ │ ├── sample.test.g.11 │ │ ├── sample.test.g.11.check │ │ ├── sample.test.g.12 │ │ ├── sample.test.g.12.check │ │ ├── sample.test.g.13 │ │ ├── sample.test.g.13.check │ │ ├── sample.test.g.14 │ │ ├── sample.test.g.14.check │ │ ├── sample.test.g.15 │ │ ├── sample.test.g.15.check │ │ ├── sample.test.g.16 │ │ ├── sample.test.g.16.check │ │ ├── sample.test.g.17 │ │ ├── sample.test.g.17.check │ │ ├── sample.test.g.18 │ │ ├── sample.test.g.18.check │ │ ├── sample.test.g.19 │ │ ├── sample.test.g.19.check │ │ ├── sample.test.g.2 │ │ ├── sample.test.g.2.check │ │ ├── sample.test.g.20 │ │ ├── sample.test.g.20.check │ │ ├── sample.test.g.21 │ │ ├── sample.test.g.21.check │ │ ├── sample.test.g.22 │ │ ├── sample.test.g.22.check │ │ ├── sample.test.g.23 │ │ ├── sample.test.g.23.check │ │ ├── sample.test.g.24 │ │ ├── sample.test.g.24.check │ │ ├── sample.test.g.25 │ │ ├── sample.test.g.25.check │ │ ├── sample.test.g.26 │ │ ├── sample.test.g.26.check │ │ ├── sample.test.g.27 │ │ ├── sample.test.g.27.check │ │ ├── sample.test.g.28 │ │ ├── sample.test.g.28.check │ │ ├── sample.test.g.29 │ │ ├── sample.test.g.29.check │ │ ├── sample.test.g.3 │ │ ├── sample.test.g.3.check │ │ ├── sample.test.g.30 │ │ ├── sample.test.g.30.check │ │ ├── sample.test.g.31 │ │ ├── sample.test.g.31.check │ │ ├── sample.test.g.32 │ │ ├── sample.test.g.32.check │ │ ├── sample.test.g.33 │ │ ├── sample.test.g.33.check │ │ ├── sample.test.g.4 │ │ ├── sample.test.g.4.check │ │ ├── sample.test.g.5 │ │ ├── sample.test.g.5.check │ │ ├── sample.test.g.6 │ │ ├── sample.test.g.6.check │ │ ├── sample.test.g.7 │ │ ├── sample.test.g.7.check │ │ ├── sample.test.g.8 │ │ ├── sample.test.g.8.check │ │ ├── sample.test.g.9 │ │ └── sample.test.g.9.check │ ├── util.c │ ├── util.h │ ├── verilog │ │ ├── Makefile │ │ ├── README │ │ ├── ambig.c │ │ ├── main.c │ │ ├── verilog.g │ │ ├── verilog_tests │ │ ├── vparse.c │ │ └── vparse.h │ ├── version.c │ ├── write_tables.c │ └── write_tables.h └── make-dparser.sh ├── Documentation ├── sugar-quickref.pdf ├── sugar-quickref.svg ├── sugar-reference.html ├── sugar-reference.txt └── sugar-styleguide.txt ├── LANGUAGE ├── README ├── Scripts └── sugar ├── Sources ├── sugar.sgrammar └── sugar │ ├── __init__.py │ ├── grammar.py │ └── main.py ├── TODO ├── Tests ├── Makefile ├── TestSugar.py ├── app-helloworld-class.sg ├── app-helloworld.sg ├── bug-ambiguity.sg ├── bug-arguments-optional.sg ├── bug-assignations-multiple.as ├── bug-assignations-multiple.sg ├── bug-assignment-in-expression.sjs ├── bug-assignment-index.sg ├── bug-for-reverseloops.sg ├── bug-function-anonymous.sg ├── bug-if-oneliner.sg ├── bug-invocation-escaperef.sg ├── bug-iteration-return.sg ├── bug-oop-default-properties.sg ├── bug-oop-shared-properties.sg ├── bug-operation-constructor-chain.sg ├── bug-operator-precedence.sg ├── bug-parens.sg ├── bug-python-variable.sg ├── bug-resolution-20160411.sjs ├── bug-resolution-class_instead_of_local_scope.sg ├── bug-resolution-closure-20160412.sjs ├── bug-resolution-if.sg ├── bug-resolution-inherited_shared.sjs ├── bug-resolver-for.sg ├── bug-runtime-arguments.sg ├── bug-runtime-map-keys.sg ├── bug-runtime-operation-self.sg ├── bug-scoping-2.sg ├── bug-scoping-loop.sg ├── bug-scoping.sg ├── bug-slicing.sg ├── bug-statement.sg ├── bug-syntax-break.sg ├── fixedbug-access.sg ├── fixedbug-arguments.sg ├── fixedbug-attribute-class-name.sg ├── fixedbug-embed-indent.sg ├── fixedbug-embed-multiple.sg ├── fixedbug-for.sg ├── fixedbug-if-1.sg ├── fixedbug-if-3.sg ├── fixedbug-if-assignment.sg ├── fixedbug-if.sg ├── fixedbug-in.sg ├── fixedbug-in2.sg ├── fixedbug-new.sg ├── fixedbug-operators-varnames.sg ├── fixedbug-resolution-invocation.sg ├── fixedbug-scope-field_in_method.sjs ├── fixedbug-statement-singleline.sg ├── fixedbug-string-escape.sg ├── fixedbug-types-translation.sg ├── fixedbug-while-scope.sg ├── js-java-frame.sg ├── oop-abstract.sg ├── oop-callbacks.sg ├── oop-class-classattributes.sg ├── oop-class.sg ├── oop-constructor.sg ├── oop-inheritance-classmethods.sg ├── oop-inheritance.sg ├── oop-module-1.sg ├── oop-module-2.sg ├── oop-module-attributes.sg ├── oop-module-import.sg ├── oop-module-multifile-a.sg ├── oop-module-multifile-b.sg ├── oop-module-shared.sg ├── pnuts-example.spnuts ├── syntax-access.sg ├── syntax-accessor.sg ├── syntax-allocation.sg ├── syntax-annotation.sg ├── syntax-arguments-defaults.sg ├── syntax-arguments-keywords.sg ├── syntax-arguments-optional.sg ├── syntax-arguments-types.sg ├── syntax-arguments-variable.sg ├── syntax-arguments.sg ├── syntax-assignment-conditional.sg ├── syntax-assignment-multiple.sg ├── syntax-assignment.sg ├── syntax-closures.sg ├── syntax-comments.sg ├── syntax-computation.sg ├── syntax-control.sg ├── syntax-declaration.sg ├── syntax-decorator.sg ├── syntax-docstrings.sg ├── syntax-embed.sg ├── syntax-escape-variables.sg ├── syntax-exceptions.sg ├── syntax-for.sg ├── syntax-function.sg ├── syntax-group.sg ├── syntax-identifiers.sg ├── syntax-if-expression.sg ├── syntax-if-sequence.sg ├── syntax-if-singleline.sg ├── syntax-if.sg ├── syntax-import.sg ├── syntax-indent.sg ├── syntax-instanciation.sg ├── syntax-invocation-byname.sg ├── syntax-invocation-escaperef.sg ├── syntax-invocation-noargs.sg ├── syntax-invocation.sg ├── syntax-iteration-filter.sg ├── syntax-iteration-map.sg ├── syntax-iteration.sg ├── syntax-map-implicit.sg ├── syntax-mutator.sg ├── syntax-names.sg ├── syntax-operator-in.sg ├── syntax-operators-multiline.sg ├── syntax-protocol.sg ├── syntax-resolution.sg ├── syntax-rewrite.sg ├── syntax-slice.sg ├── syntax-specific.sg ├── syntax-strings.sg ├── syntax-time.sjs ├── syntax-with-statement.sg ├── test.pnuts ├── test.py ├── testmodule.sg ├── testpackage │ └── testmodule.sg ├── todo-async.sg ├── todo-for-type.sg ├── todo-methods-operators.sg ├── todo-oop-accessors-class.sg ├── todo-oop-accessors-module.sg ├── todo-oop-module-init.sg ├── todo-oop-singleton.sg ├── todo-syntax-assert.sg ├── todo-syntax-conditional-operation.sg ├── todo-syntax-default.sg ├── todo-syntax-filter.sg ├── todo-syntax-in.sg ├── todo-syntax-invocations.sg ├── todo-syntax-reference-module.sg ├── todo-syntax-select.sg ├── todo-syntax-switch.sg ├── todo-syntax-with.sg ├── todo-types-declaration.sg ├── todo-types-translation.sg ├── types-declaration.sg ├── types-dict.sg ├── types-list.sg ├── types-litterals.sg ├── types-rewrite-string.sg ├── types-strings.sg ├── warning-oop-super-without-parent.sg └── warning-value-without-operation.sg ├── bug-comments.sjs ├── bug-if-expression-priority.sjs ├── bug-implicit-args.sjs ├── bug-iteation.sjs ├── install-sugar.sh └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | Dependencies/d-1.15-patched/make_dparser 2 | Dependencies/d-1.15-patched/python/build/* 3 | Dependencies/d-1.15-patched/sample_parser 4 | Dependencies/d-1.15-patched/test_parser 5 | Dependencies/dparser/* 6 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Commands/Show class : method definition.tmCommand: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | beforeRunningCommand 6 | nop 7 | command 8 | echo "Definition of $TM_SELECTED_TEXT : " 9 | egrep "(@method|@function|@class).*$TM_SELECTED_TEXT\b" -s -n -d recurse $TM_PROJECT_DIRECTORY | grep ".sjs" 10 | 11 | fallbackInput 12 | word 13 | input 14 | selection 15 | keyEquivalent 16 | @ 17 | name 18 | Show class / method definition 19 | output 20 | showAsTooltip 21 | scope 22 | source.sjs 23 | uuid 24 | 4FFFED41-B90E-45AB-8D82-09467656D959 25 | 26 | 27 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Commands/Syntax Validator.tmCommand: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | beforeRunningCommand 6 | nop 7 | command 8 | # Quick script to show error number of a sugar erro 9 | source "$TM_SUPPORT_PATH/lib/webpreview.sh" 10 | html_header "Sugar validator" "validating sugar... " 11 | 12 | if sugar $TM_FILEPATH 2>&1 | grep -q line: ; then 13 | echo "<div style=\"background:red ; heigh : 100px; width 300px;\">ERRRROR!</div>" 14 | sugar $TM_FILEPATH 2>&1 | grep line: 15 | echo "<pre>" 16 | sugar $TM_FILEPATH 2>&1 17 | echo "</pre>" 18 | else 19 | echo "<div style=\"background:green ; heigh : 100px; width 300px;\">No errors found ! :-)</div>" 20 | fi 21 | 22 | html_footer 23 | input 24 | none 25 | keyEquivalent 26 | @r 27 | name 28 | Syntax Validator 29 | output 30 | showAsHTML 31 | scope 32 | source.sjs 33 | uuid 34 | EDE8E06B-FFD6-484F-9CEE-D2339BC73BD2 35 | 36 | 37 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/DragCommands/image to string.tmDragCommand: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | beforeRunningCommand 6 | nop 7 | command 8 | echo "\"$TM_DROPPED_FILE\"" 9 | draggedFileExtensions 10 | 11 | png 12 | jpg 13 | PNG 14 | JPG 15 | gif 16 | GIF 17 | jpeg 18 | JPEG 19 | 20 | input 21 | selection 22 | name 23 | image to string 24 | output 25 | insertAsSnippet 26 | uuid 27 | CC366021-26D5-4E86-81D1-C21937EAB6D6 28 | 29 | 30 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Macros/Select content of String.tmMacro: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | commands 6 | 7 | 8 | argument 9 | 10 | action 11 | findPrevious 12 | findInProjectIgnoreCase 13 | 14 | findString 15 | " 16 | ignoreCase 17 | 18 | regularExpression 19 | 20 | replaceAllScope 21 | document 22 | wrapAround 23 | 24 | 25 | command 26 | findWithOptions: 27 | 28 | 29 | command 30 | moveRight: 31 | 32 | 33 | argument 34 | 35 | action 36 | findNext 37 | findInProjectIgnoreCase 38 | 39 | findString 40 | .*\" 41 | ignoreCase 42 | 43 | regularExpression 44 | 45 | replaceAllScope 46 | document 47 | wrapAround 48 | 49 | 50 | command 51 | findWithOptions: 52 | 53 | 54 | command 55 | moveLeftAndModifySelection: 56 | 57 | 58 | keyEquivalent 59 | @C 60 | name 61 | Select content of String 62 | scope 63 | string 64 | uuid 65 | AF2C33BA-080D-42D0-87D8-B289BD61B11F 66 | 67 | 68 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Preferences/Comments.tmPreferences: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Comments 7 | scope 8 | source.sjs 9 | settings 10 | 11 | shellVariables 12 | 13 | 14 | name 15 | TM_COMMENT_START 16 | value 17 | # 18 | 19 | 20 | 21 | uuid 22 | 2970E86D-F674-4468-A9FE-EB188F8F86BF 23 | 24 | 25 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Preferences/Indentation.tmPreferences: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Indentation 7 | scope 8 | source.sjs 9 | settings 10 | 11 | decreaseIndentPattern 12 | (?x)^ 13 | (\s* 14 | ( 15 | @?end 16 | |(?:else|catch|finally) #normal keywords 17 | |\| 18 | |\} 19 | |\) 20 | ) 21 | ) 22 | increaseIndentPattern 23 | (?x)^ 24 | (\s* 25 | (?: 26 | (@(?:module|class|method|function|constructor|operation)) # Stuff that begins by @! 27 | |(?:for|while|else|try|catch|finally) # normal behavior stuff 28 | |if\s*(?!.*->) # Ident normal when but not "when ->" 29 | |.*\{(?!.*\}) # so it indents after doc comments 30 | |.*\((?!.*\)) # for { and ( FIXME 31 | |\| # To re-indent avec doc comments 32 | ) 33 | ) 34 | unIndentedLinePattern 35 | ^\s*$ 36 | 37 | uuid 38 | ACACF068-0A2C-4D21-A1CE-74DBB21461D7 39 | 40 | 41 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Preferences/Symbols.tmPreferences: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | name 6 | Symbols 7 | scope 8 | entity.name 9 | settings 10 | 11 | showInSymbolList 12 | 1 13 | symbolTransformation 14 | 15 | s/(@constructor)(.*)/$1( $2 )/g; # ajoute des parenthèses pour les paramètres du constructeur 16 | s/((@method|@function|@operation)(\s+\w+\s+))(.*)/$1( $4 )/g; # ajoute des parenthèses pour les paramètres des methodes 17 | s/(@method|@function|@operation)//g; # removes @method, @function and @operation from the symbol browser for faster reading 18 | 19 | 20 | uuid 21 | B09F3057-CBF4-4CC6-9A05-86AEEE03C3E6 22 | 23 | 24 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/@class.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | @class ${1:name} 7 | 8 | $0 9 | 10 | @constructor 11 | 12 | @end 13 | 14 | @end 15 | name 16 | @class 17 | scope 18 | source.sjs 19 | tabTrigger 20 | @c 21 | uuid 22 | 79C7CB07-4696-4A0F-BA02-3F9F2DB6F19E 23 | 24 | 25 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/@function.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | @function ${1:name} 7 | $0 8 | @end 9 | name 10 | @function 11 | scope 12 | source.sjs 13 | tabTrigger 14 | @f 15 | uuid 16 | EEEBF1B0-BCCF-4197-9943-4545B1085237 17 | 18 | 19 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/@method.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | @method ${1:name} 7 | $0 8 | @end 9 | name 10 | @method 11 | scope 12 | source.sjs 13 | tabTrigger 14 | @m 15 | uuid 16 | EC248975-E866-4B8D-802B-C4491695DCCA 17 | 18 | 19 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/@operation.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | @operation ${1:name} 7 | $0 8 | @end 9 | name 10 | @operation 11 | scope 12 | source.sjs 13 | tabTrigger 14 | @o 15 | uuid 16 | 5B15130D-E3D0-4896-8069-4EE0C0493281 17 | 18 | 19 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/@property.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | @property ${1:name} 7 | name 8 | @property 9 | scope 10 | source.sjs 11 | tabTrigger 12 | @p 13 | uuid 14 | 330B55B8-9C64-4979-AA38-1B88726B08A8 15 | 16 | 17 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/Continue Line Comment Sugar.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | 7 | `# extract comment type from the scope name 8 | # and convert it to the actual character(s) 9 | CH=$(perl <<<$TM_SCOPE -pe 's/.*\bcomment\.line\.([^. ]*).*/$1/') 10 | grep -w ^$CH <<EOF|cut -f2|tr -d \n 11 | number-sign # 12 | documentation | 13 | EOF` $0 14 | keyEquivalent 15 | 16 | name 17 | Continue Line Comment Sugar 18 | scope 19 | comment.line 20 | uuid 21 | B7F5980A-4BCD-4AED-8E92-AD6111ACC8AF 22 | 23 | 24 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/UnitTest.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | @class ${1:TestName}:UnitTest 7 | 8 | @constructor _name 9 | super( _name ) 10 | @end 11 | 12 | @method setup 13 | $0 14 | @end 15 | 16 | @end 17 | name 18 | UnitTest 19 | scope 20 | source.sjs 21 | tabTrigger 22 | test 23 | uuid 24 | EF6B1DDE-9C5E-42D0-A49D-77BC16E21D8C 25 | 26 | 27 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/bind.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bundleUUID 6 | C5F73589-7D9B-4E77-9D55-9CF0F4DBA689 7 | content 8 | \$( ${1:bindElement} ) bind( "${2:eventname}", { 9 | ${0:content} 10 | }) 11 | name 12 | bind 13 | scope 14 | source.sjs 15 | tabTrigger 16 | bind 17 | uuid 18 | 2F260EC2-0D07-4E94-AF74-E888A38AD60B 19 | 20 | 21 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/click.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bundleUUID 6 | C5F73589-7D9B-4E77-9D55-9CF0F4DBA689 7 | content 8 | \$( ${1:bindelement} ) click ({ 9 | ${0:content} 10 | }) 11 | name 12 | click 13 | scope 14 | source.sjs 15 | tabTrigger 16 | click 17 | uuid 18 | CA8D1539-EA7B-4DC8-BC37-A135D8FD4857 19 | 20 | 21 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/forin.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | for ${1:element} in ${2:start} .. ${3:end} 7 | $0 8 | end 9 | name 10 | forin 11 | scope 12 | source.sjs 13 | tabTrigger 14 | for 15 | uuid 16 | 66072416-FE42-451B-AAAD-B132C8B1FEE4 17 | 18 | 19 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/html button.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bundleUUID 6 | C5F73589-7D9B-4E77-9D55-9CF0F4DBA689 7 | content 8 | ${1:varname} = html input({class:"${2:classname}", type:"button", value:"${0:content}"}) 9 | name 10 | html button 11 | scope 12 | source.sjs 13 | tabTrigger 14 | button 15 | uuid 16 | ED66DC33-26A3-45EA-A6C9-84C8D73A3A96 17 | 18 | 19 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/html div.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | var ${1:varname} = html div({class:"${2:classname}"} 7 | ${0:content} 8 | ) 9 | 10 | name 11 | html div 12 | scope 13 | source.sjs 14 | tabTrigger 15 | div 16 | uuid 17 | 1A205830-A880-46F9-88F0-53FE6AE59B61 18 | 19 | 20 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/html img.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bundleUUID 6 | C5F73589-7D9B-4E77-9D55-9CF0F4DBA689 7 | content 8 | html img({src:"${0:url}"}) 9 | name 10 | html img 11 | scope 12 | source.sjs 13 | tabTrigger 14 | img 15 | uuid 16 | 2DABFBF8-7346-4CE9-94F9-E825B5B7FDE9 17 | 18 | 19 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/if.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | content 6 | if ${1:condition} 7 | $0 8 | end 9 | name 10 | if 11 | scope 12 | source.sjs 13 | tabTrigger 14 | if 15 | uuid 16 | C7AD658B-BED4-4A40-90DD-8221117D66AF 17 | 18 | 19 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Snippets/trigger.tmSnippet: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bundleUUID 6 | C5F73589-7D9B-4E77-9D55-9CF0F4DBA689 7 | content 8 | \$( ${1:triggerElement} ) trigger( "${0:eventname}" ) 9 | name 10 | trigger 11 | scope 12 | source.sjs 13 | tabTrigger 14 | trigger 15 | uuid 16 | 94DE9338-4681-431B-916D-4E209CF4851D 17 | 18 | 19 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Templates/Class.tmTemplate/class.sjs: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # Project : Akoha 3 | # Author : ${TM_USERNAME} <${TM_EMAIL}> 4 | # ----------------------------------------------------------------------------- 5 | # Creation date : ${TM_DATE} 6 | # ----------------------------------------------------------------------------- 7 | 8 | # ----------------------------------------------------------------------------- 9 | # 10 | # ${TM_NEW_FILE_BASENAME} CLASS 11 | # 12 | # ----------------------------------------------------------------------------- 13 | 14 | @class ${TM_NEW_FILE_BASENAME} 15 | 16 | @constructor 17 | 18 | @end 19 | 20 | @end -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/Templates/Class.tmTemplate/info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | command 6 | if [[ ! -f "$TM_NEW_FILE" ]]; then 7 | TM_YEAR=`date +%Y` \ 8 | TM_DATE=`date +%Y-%m-%d` \ 9 | TM_USERNAME=`niutil -readprop / /users/\$USER realname` \ 10 | perl -pe 's/\$\{([^}]*)\}/$ENV{$1}/g' \ 11 | < class.sjs > "$TM_NEW_FILE" 12 | fi 13 | extension 14 | sjs 15 | keyEquivalent 16 | @C 17 | name 18 | Class 19 | scope 20 | source.sjs 21 | uuid 22 | 2F5E1B8C-002E-47E4-A85C-EBF2A8C7ABC6 23 | 24 | 25 | -------------------------------------------------------------------------------- /Contrib/Editors/Sugar.tmbundle/info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | deleted 6 | 7 | CCFD55DB-BE07-4F24-97D8-197744BBFDF4 8 | 9 | name 10 | Sugar 11 | ordering 12 | 13 | 5C74AC12-869D-41D8-935B-65CCA1BD7D7E 14 | 79C7CB07-4696-4A0F-BA02-3F9F2DB6F19E 15 | EDE8E06B-FFD6-484F-9CEE-D2339BC73BD2 16 | B09F3057-CBF4-4CC6-9A05-86AEEE03C3E6 17 | B7F5980A-4BCD-4AED-8E92-AD6111ACC8AF 18 | EC248975-E866-4B8D-802B-C4491695DCCA 19 | 5B15130D-E3D0-4896-8069-4EE0C0493281 20 | 330B55B8-9C64-4979-AA38-1B88726B08A8 21 | 66072416-FE42-451B-AAAD-B132C8B1FEE4 22 | 1A205830-A880-46F9-88F0-53FE6AE59B61 23 | C7AD658B-BED4-4A40-90DD-8221117D66AF 24 | EEEBF1B0-BCCF-4197-9943-4545B1085237 25 | 2970E86D-F674-4468-A9FE-EB188F8F86BF 26 | ACACF068-0A2C-4D21-A1CE-74DBB21461D7 27 | 2F260EC2-0D07-4E94-AF74-E888A38AD60B 28 | CA8D1539-EA7B-4DC8-BC37-A135D8FD4857 29 | ED66DC33-26A3-45EA-A6C9-84C8D73A3A96 30 | 2DABFBF8-7346-4CE9-94F9-E825B5B7FDE9 31 | 94DE9338-4681-431B-916D-4E209CF4851D 32 | 2F5E1B8C-002E-47E4-A85C-EBF2A8C7ABC6 33 | AF2C33BA-080D-42D0-87D8-B289BD61B11F 34 | 4FFFED41-B90E-45AB-8D82-09467656D959 35 | CC366021-26D5-4E86-81D1-C21937EAB6D6 36 | EF6B1DDE-9C5E-42D0-A49D-77BC16E21D8C 37 | 38 | uuid 39 | C5F73589-7D9B-4E77-9D55-9CF0F4DBA689 40 | 41 | 42 | -------------------------------------------------------------------------------- /Contrib/Editors/sugar.vim: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebastien/sugar/4b00379b15023529c81ba0459f3e0d09e340b7f2/Contrib/Editors/sugar.vim -------------------------------------------------------------------------------- /Contrib/python-module-loader.py: -------------------------------------------------------------------------------- 1 | # This is a stub module that will compile the Sugar code into python and 2 | # populate this module with it. It is a good example of how to write a Python 3 | # module in Sugar 4 | # 5 | # To use it, simply replace MODULE by the name of your module, which must have 6 | # the same name as your python module, except with the 'spy' extension: 7 | # 8 | # mymodule.py (this file with MODULE=mymodule) 9 | # mymodule.spy (the Sugar file) 10 | # 11 | # Now, when importing 'mymodule' from Python, 'mymodule.spy' will be compiled to 12 | # the '_mymodule.py' module, which will then be loaded by the 'mymodule.py' 13 | # module. 14 | import os, stat 15 | import sugar.sugar as sugar 16 | if not os.path.exists("_MODULE.py") \ 17 | or os.stat("MODULE.spy")[stat.ST_MTIME] > os.stat("_MODULE.py")[stat.ST_MTIME]: 18 | f = file("_MODULE.py","w") 19 | f.write(sugar.runAsString(["-clpy", "MODULE.spy"])) 20 | f.close() 21 | from _MODULE import * 22 | if __name__ == "__main__": 23 | import sys 24 | sys.exit(_MODULE.__main__(sys.argv)) 25 | # EOF 26 | -------------------------------------------------------------------------------- /Contrib/sugar-cleaner.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | import os, sys, re 3 | 4 | __doc__ = """\ 5 | Cleans the given Sugar source files by : 6 | 7 | - Converting empty lines that only contains spaces to empty lines 8 | - Gettin rid of trailing spaces 9 | """ 10 | 11 | RE_EMPTY_LINE = re.compile("s+") 12 | 13 | def clean_sugar_text( text ): 14 | res = [] 15 | for line in text.split("\n"): 16 | if not line or RE_EMPTY_LINE.match(line): 17 | res.append("") 18 | else: 19 | while line and line[-1] in "\t ": 20 | line = line[:-1] 21 | res.append(line) 22 | res = "\n".join(res) 23 | if res:return res[:-1] 24 | else: return res 25 | 26 | text = RE_EMPTY_LINES.sub(text,"") 27 | return RE_TRAILING_SPACES.sub(text,"") 28 | 29 | if __name__ == "__main__": 30 | for a in sys.argv[1:]: 31 | print "Cleaning", a 32 | text = open(a,'r').read() 33 | open(a,'w').write(clean_sugar_text(text)) 34 | # EOF 35 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/4calc.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | #include 4 | 5 | typedef struct My_ParseNode { 6 | int value; 7 | } My_ParseNode; 8 | #define D_ParseNode_User My_ParseNode 9 | } 10 | 11 | translation_unit : 12 | statement* 13 | ; 14 | 15 | statement : 16 | expr ';' { printf("%d\n", $0.value); } 17 | ; 18 | 19 | expr : 20 | integer { $$.value = atoi($n0.start_loc.s); } 21 | | expr '+' expr $right 10 { $$.value = $0.value + $2.value; } 22 | | expr '-' expr $right 10 { $$.value = $0.value - $2.value; } 23 | | expr '*' expr $right 20 { $$.value = $0.value * $2.value; } 24 | | expr '/' expr $right 20 { $$.value = $0.value / $2.value; } 25 | | '(' expr ')' { $$.value = $1.value; } 26 | ; 27 | 28 | integer : 29 | "-?[0-9]+" 30 | ; 31 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/4calc.in: -------------------------------------------------------------------------------- 1 | (2 + 2) * 2 ; 2 ; 2 | 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/BUILD_VERSION: -------------------------------------------------------------------------------- 1 | 27 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Copyright (c) 1994-2004 John Bradley Plevyak, All Rights Reserved 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 7 | 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 10 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/README: -------------------------------------------------------------------------------- 1 | This is DParser, a scannerless GLR parser. It uses to Tomita algorithm, 2 | and incorporates BNF production syntax, regular expression terminals, 3 | and a state-specific symbol table. 4 | 5 | It can be compiled to work with or without the Boehm Garbage Collector. 6 | To compile with GC, uncomment the line D_USE_GC=1 in the Makefile. 7 | 8 | The result is natural grammars and powerful parsing. 9 | 10 | To build: 'gmake' (only available with source code package) 11 | To test: 'gmake test' (only available with source code package) 12 | To install: 'gmake install' (binary or source code packages) 13 | 14 | For python support, '(cd python; gmake install)' 15 | 16 | Refer to the manual for more information. 17 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/arg.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 1994-2004 John Plevyak, All Rights Reserved 3 | */ 4 | #include 5 | #include 6 | #include 7 | 8 | #ifndef __alpha 9 | #define atoll atol 10 | #endif 11 | 12 | /* Argument Handling 13 | */ 14 | struct ArgumentState; 15 | 16 | typedef void ArgumentFunction(struct ArgumentState *arg_state, char *arg); 17 | 18 | typedef struct { 19 | char *name; 20 | char key; 21 | char *description; 22 | char *type; 23 | void *location; 24 | char *env; 25 | ArgumentFunction *pfn; 26 | } ArgumentDescription; 27 | 28 | typedef struct ArgumentState { 29 | char **file_argument; 30 | int nfile_arguments; 31 | char *program_name; 32 | ArgumentDescription *desc; 33 | } ArgumentState; 34 | 35 | void usage(ArgumentState *arg_state, char *arg_unused); 36 | void process_args(ArgumentState *arg_state, char **argv); 37 | void free_args(ArgumentState *arg_state); 38 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/baseline: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/tcsh 2 | 3 | setenv MAKE gmake 4 | parser_tests 5 | foreach f (tests/*.out) 6 | cp $f $f:r.check 7 | end 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/dparse_tree.h: -------------------------------------------------------------------------------- 1 | /* 2 | $URL: http://manta.univ.gda.pl/svn/wb/parsing/dparser/D/dparse_tree.h $ 3 | $Revision: 1.1 $ 4 | 5 | This interface provides a `print_parsetree' function that can 6 | be used to print a parse tree built by Dparser. The implementation 7 | of `print_parsetree' calls, on every node of the parse tree, 8 | a function `fn` that should print the node. Two such functions are 9 | provided: `print_node_default' which uses indentation to show the parse 10 | tree and `print_node_parenthesised' which uses parens. 11 | 12 | Three additional files provide an example: 13 | -- `driver_parsetree.c' contains a program illustrating the use of `print_parsetree', 14 | -- `4calc.g' contains a grammar for a simple calculator, 15 | -- `4calc.in' an expression to parse. 16 | The following commands can be used to compile and try out the example: 17 | make_dparser 4calc.g 18 | cc -o 4calc driver_parsetree.c 4calc.g.d_parser.c -I/usr/local/include -L/usr/local/lib -ldparse 19 | ./4calc 4calc.in 20 | */ 21 | 22 | #ifndef _parsetree_H_ 23 | #define _parsetree_H_ 24 | 25 | #include "dparse.h" 26 | 27 | 28 | /* `print_node_fn_t' type defines a class of callback functions that 29 | the `print_parsetree' function uses to print a node */ 30 | 31 | typedef void (print_node_fn_t)(int depth, char *token_name, char *token_value, void *client_data); 32 | 33 | /* if `fn' is NULL, then the function `print_node_default' is used */ 34 | 35 | void 36 | print_parsetree(D_ParserTables pt, D_ParseNode *pn, print_node_fn_t fn, void *client_data); 37 | 38 | 39 | /* `print_node_default' truncates `token_value' to 44 characters 40 | and replaces newlines with spaces */ 41 | 42 | void 43 | print_node_default(int depth, char *token_name, char *token_value, void *client_data); 44 | 45 | void 46 | print_node_parenthesised(int depth, char *token_name, char *token_value, void *client_data); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/driver_parsetree.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebastien/sugar/4b00379b15023529c81ba0459f3e0d09e340b7f2/Dependencies/d-1.15-patched/driver_parsetree.c -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/gramgram.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2002-2004 John Plevyak, All Rights Reserved 3 | */ 4 | struct Production; 5 | struct Rule; 6 | struct Elem; 7 | 8 | typedef struct ParseNode_User { 9 | struct Production *p; 10 | struct Rule *r; 11 | struct Elem *e; 12 | unsigned int kind; 13 | } ParseNode_User; 14 | 15 | #define D_ParseNode_User ParseNode_User 16 | 17 | #define D_ParseNode_Globals struct Grammar 18 | 19 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/lex.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2002-2004 John Plevyak, All Rights Reserved 3 | */ 4 | 5 | #ifndef _lex_H_ 6 | #define _lex_H_ 7 | 8 | /* #define LIVE_DIFF_IN_TRANSITIONS */ 9 | 10 | struct Grammar; 11 | 12 | typedef struct ScanStateTransition { 13 | uint index; 14 | VecAction live_diff; 15 | VecAction accepts_diff; 16 | } ScanStateTransition; 17 | 18 | typedef struct ScanState { 19 | uint index; 20 | struct ScanState *chars[256]; 21 | VecAction accepts; 22 | VecAction live; 23 | ScanStateTransition *transition[256]; 24 | } ScanState; 25 | 26 | void build_scanners(struct Grammar *g); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/lr.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2002-2004 John Plevyak, All Rights Reserved 3 | */ 4 | 5 | #ifndef _lr_H_ 6 | #define _lr_H_ 7 | 8 | void build_LR_tables(Grammar *g); 9 | void sort_VecAction(VecAction *v); 10 | uint elem_symbol(Grammar *g, Elem *e); 11 | State *goto_State(State *s, Elem *e); 12 | void free_Action(Action *a); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/mkdparse.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2002-2004 John Plevyak, All Rights Reserved 3 | */ 4 | 5 | #include "gramgram.h" 6 | #include "d.h" 7 | #include "mkdparse.h" 8 | 9 | static void 10 | mkdparse_internal(Grammar *g, char *grammar_pathname, char *str) { 11 | if (!grammar_pathname) 12 | grammar_pathname = "-"; 13 | if (parse_grammar(g, grammar_pathname, str) < 0) 14 | d_fail("unable to parse grammar '%s'", grammar_pathname); 15 | if (g->productions.n < 2) 16 | d_fail("no productions in grammar '%s'", grammar_pathname); 17 | if (build_grammar(g) < 0) 18 | d_fail("unable to load grammar '%s'", grammar_pathname); 19 | } 20 | 21 | void 22 | mkdparse(Grammar *g, char *grammar_pathname) { 23 | mkdparse_internal(g, grammar_pathname, 0); 24 | } 25 | 26 | void 27 | mkdparse_from_string(Grammar *g, char *str) { 28 | mkdparse_internal(g, 0, str); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/mkdparse.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2002-2004 John Plevyak, All Rights Reserved 3 | */ 4 | #ifndef _mkdparse_H_ 5 | #define _mkdparse_H_ 6 | 7 | #include 8 | #if defined(__cplusplus) 9 | extern "C" { 10 | #endif 11 | 12 | struct Grammar; 13 | 14 | void mkdparse(struct Grammar *g, char *grammar_pathname); 15 | void mkdparse_from_string(struct Grammar *g, char *str); 16 | 17 | #if defined(__cplusplus) 18 | } 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/my.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dparse.h" 3 | extern D_ParserTables parser_tables_gram; 4 | int 5 | main(int argc, char *argv[]) { 6 | char s[256], *ss; 7 | D_Parser *p = new_D_Parser(&parser_tables_gram, sizeof(D_ParseNode_User)); 8 | if (fgets(s,255,stdin) && dparse(p, s, strlen(s)) && !p->syntax_errors) 9 | printf("success\n"); 10 | else 11 | printf("failure\n"); 12 | } 13 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/my.g: -------------------------------------------------------------------------------- 1 | phrase : words ( ABC | AB | A ) words; 2 | words : word*; 3 | word : "[a-z]+"; 4 | A : "a[a-z]*"; 5 | AB : A "b[a-z]*"; 6 | ABC : AB "c[a-z]*"; 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/parser_tests: -------------------------------------------------------------------------------- 1 | #!/bin/tcsh 2 | 3 | #setenv VALGRIND 'linux32 valgrind --tool=memcheck --leak-check=yes --show-reachable=yes' 4 | setenv VALGRIND '' 5 | 6 | cp BUILD_VERSION Makefile *.c *.h grammar.g tests 7 | cd tests 8 | $MAKE -s make_dparser 9 | $MAKE gram 10 | $MAKE -s make_dparser 11 | set failed = 0 12 | foreach g (*.test.g) 13 | rm -f sample_parser 14 | if (-e $g.flags) then 15 | set flags = `cat $g.flags` 16 | else 17 | set flags = 18 | endif 19 | $VALGRIND ./make_dparser $flags $g 20 | $MAKE -s sample_parser SAMPLE_GRAMMAR=$g:t 21 | foreach t ( $g.[0-9] $g.[0-9][0-9] ) 22 | if (-e $t.flags) then 23 | set flags = `cat $t.flags` 24 | else 25 | set flags = 26 | endif 27 | $VALGRIND ./sample_parser $flags -v $t >&! $t.out 28 | diff $t.out $t.check 29 | if ($?) then 30 | echo $t "******** FAILED ********" 31 | set failed = `expr $failed + 1` 32 | else 33 | echo $t "PASSED" 34 | endif 35 | end 36 | end 37 | echo "---------------------------------------" 38 | if (! $failed) then 39 | echo "ALL tests PASSED" 40 | else 41 | echo "********" $failed "test(s) FAILED *********" 42 | endif 43 | rm -f sample_parser BUILD_VERSION Makefile *.c *.h *.o make_dparser libdparse.a grammar.g 44 | cd .. 45 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/Makefile: -------------------------------------------------------------------------------- 1 | PYTHON=python2.7 2 | all: 3 | echo "type 'make install' as root to install" 4 | 5 | install: 6 | $(PYTHON) setup.py install 7 | 8 | clean: 9 | rm -rf build dparser.pyc tests/d_parser_mach_gen.* 10 | 11 | test: 12 | $(PYTHON) tests/test.py 13 | $(PYTHON) tests/test2.py 14 | $(PYTHON) tests/test3.py 15 | $(PYTHON) tests/test4.py 16 | $(PYTHON) tests/test5.py 17 | $(PYTHON) tests/test6.py 18 | $(PYTHON) tests/test7.py 19 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/README: -------------------------------------------------------------------------------- 1 | This module was created by Brian Sabbey (sabbey at u.washington.edu). 2 | 3 | See index.html for details. 4 | 5 | Swig: 6 | swig -python -shadow dparser.i 7 | 8 | ignore dparser_swig.py 9 | 10 | made with SWIG Version 1.1 (Patch 5) 11 | may not work with later versions 12 | 13 | Thanks to: 14 | 15 | Brennan Evans for more general unix support. 16 | 17 | Milosz Krajewski for non-unix support (mostly superseded by binary table support in d parser) and directory independence. 18 | 19 | Yves Forkl for bugs, usability suggestions, and emacs lisp code to jump to syntax error location. 20 | 21 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/contrib/dparserpy-syntax_error.py: -------------------------------------------------------------------------------- 1 | ### PYTHON FRAGMENT 2 | 3 | # suggestions for code improvement are highly welcome ;-) 4 | 5 | def syntax_error(loc): 6 | contextwidth_left = 30 7 | contextwidth_right = 30 8 | ellipsis = '[...]' 9 | locbuf_flattened = loc.buf.replace("\n","\254") # \254 is 'not sign' 10 | 11 | spanstart = loc.s - contextwidth_left 12 | mn = max(spanstart, 0) 13 | if spanstart > 0: 14 | before = ellipsis + locbuf_flattened[mn + len(ellipsis):loc.s] 15 | else: 16 | before = locbuf_flattened[mn:loc.s] 17 | space = ' '*(contextwidth_left - len(before)) 18 | before = space + before 19 | 20 | spanend = loc.s + contextwidth_right 21 | mx = min(spanend, len(locbuf_flattened)) 22 | after = locbuf_flattened[loc.s:mx] 23 | if len(after) > (contextwidth_right - len(ellipsis)): 24 | after = locbuf_flattened[loc.s:(mx - len(ellipsis))] + ellipsis 25 | 26 | print "-"*79 27 | print "File %s:\n" % inputfilename 28 | print before +\ 29 | " ____________\n" +\ 30 | " "*contextwidth_left +\ 31 | "/syntax error at line " + str(loc.line) +\ 32 | " (buffer pos. " + str(loc.s) + ")" 33 | print " "*contextwidth_left + after 34 | print "-"*79 35 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/dparser.i: -------------------------------------------------------------------------------- 1 | %module dparser_swig 2 | %{ 3 | #include "pydparser.h" 4 | %} 5 | 6 | %typemap(python, in) PyObject* { 7 | $target = $source; 8 | } 9 | 10 | %typemap(python, out) PyObject* { 11 | $target = $source; 12 | } 13 | 14 | %include pydparser.h 15 | 16 | typedef struct d_loc_t { 17 | char *pathname; 18 | int previous_col, col, line; 19 | } d_loc_t; 20 | 21 | typedef struct D_ParseNode { 22 | int symbol; 23 | d_loc_t start_loc; 24 | D_ParseNode_Globals *globals; 25 | user_pyobjects user; 26 | } D_ParseNode; 27 | 28 | D_ParseNode *d_get_child(D_ParseNode *pn, int child); 29 | D_ParseNode *d_find_in_tree(D_ParseNode *pn, int symbol); 30 | int d_get_number_of_children(D_ParseNode *pn); 31 | 32 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | DParser for Python 4 | 5 | 6 |

DParser for Python

7 | 8 | DParser is a simple but powerful tool for parsing, written by J. Plevyak. DParser for Python gives Python 9 | programmers a seamless interface to DParser. 10 |

11 | 12 | The features that set this Python parser apart from other Python parsers are: 13 |

    14 |
  • it can deal with any grammar (GLR) 15 |
  • it is fast (based in C) 16 |
  • it does not require a compiler to operate. 17 |
18 | DParser for Python also has many easy-to-use features found in other Python parsers: 19 |
    20 |
  • it does not require explicit definitions of tokens 21 |
  • it does not require a separate, non-Python grammar file 22 |
  • it uses function documentation strings to specify grammar rules 23 |
  • it does not output parser code that the user must compile or run. 24 |
25 | 26 | A simple example-- a grammar to add numbers: 27 |
28 | from dparser import Parser
29 | 
30 | def d_add(t):              # actions must start with 'd_'
31 |     "exp : exp '+' exp"    # literals are put directly into grammar rules
32 |     return t[0] + t[2]
33 |     
34 | def d_number(t):
35 |     'exp : "[0-9]+" '  # regular expressions are enclosed in double quotes
36 |     return int(t[0])
37 |     
38 | print Parser().parse("2+3+4")
39 | 
40 | ==> 9
41 | 
42 |

43 | Also see the slightly longer requisite calculator example. 44 |

45 | 46 |

Documentation

47 | DParser for Python Documentation 48 |

49 | DParser for Python requires at least Python 2.2 50 |

51 |

Contact

52 | 53 | Brian Sabbey (sabbey_at_u_dot_washington_dot_edu.) 54 | 55 |

56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/make_tables.c: -------------------------------------------------------------------------------- 1 | #include "../gramgram.h" 2 | #include "../d.h" 3 | #include "../mkdparse.h" 4 | 5 | int 6 | make_tables(char *grammar_string, char *grammar_pathname) { 7 | Grammar *g; 8 | g = new_D_Grammar(grammar_pathname); 9 | g->set_op_priority_from_rule = 0; 10 | g->right_recursive_BNF = 0; 11 | g->states_for_whitespace = 1; 12 | g->states_for_all_nterms = 1; 13 | g->tokenizer = 0; 14 | g->longest_match = 0; 15 | strcpy(g->grammar_ident, "gram"); 16 | g->scanner_blocks = 4; 17 | g->scanner_block_size = 0; 18 | g->write_line_directives = 1; 19 | g->write_header = -1; 20 | g->token_type = 0; 21 | strcpy(g->write_extension, "dat"); 22 | 23 | mkdparse_from_string(g, grammar_string); 24 | 25 | if (write_binary_tables(g) < 0) 26 | d_fail("unable to write tables"); 27 | 28 | free_D_Grammar(g); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/pydparser.h: -------------------------------------------------------------------------------- 1 | typedef struct user_pyobjects { 2 | PyObject *t; 3 | PyObject *s; 4 | int inced_global_state; 5 | } user_pyobjects; 6 | 7 | #ifndef SWIG 8 | #define D_ParseNode_User user_pyobjects 9 | #define D_ParseNode_Globals PyObject 10 | #include "../d.h" 11 | #endif 12 | 13 | void my_d_loc_t_s_set(d_loc_t *dlt, D_Parser *dp, int val); 14 | int my_d_loc_t_s_get(d_loc_t *dlt, D_Parser *dp); 15 | void my_D_ParseNode_end_set(D_ParseNode *dpn, D_Parser *dp, int val); 16 | void my_D_ParseNode_end_skip_set(D_ParseNode *dpn, D_Parser *dp, int val); 17 | int my_D_ParseNode_end_get(D_ParseNode *dpn, D_Parser *dp); 18 | int my_D_ParseNode_end_skip_get(D_ParseNode *dpn, D_Parser *dp); 19 | PyObject *my_D_ParseNode_symbol_get(D_ParseNode *dpn, D_Parser *dp); 20 | 21 | void remove_parse_tree_viewer(D_Parser* dp); 22 | void add_parse_tree_viewer(D_Parser* dp); 23 | void del_parser(D_Parser *dp); 24 | D_Parser *make_parser(long int idpt, 25 | PyObject *self, 26 | PyObject *reject, 27 | PyObject *make_token, 28 | PyObject *loc_type, 29 | PyObject *node_info_type, 30 | PyObject *actions, 31 | PyObject *initial_white_space_fn, 32 | PyObject *syntax_error_fn, 33 | PyObject *ambiguity_fn, 34 | int dont_fixup_internal_productions, 35 | int dont_merge_epsilon_trees, 36 | int commit_actions_interval, 37 | int error_recovery, 38 | int print_debug_info, 39 | int partial_parses, 40 | int dont_compare_stacks, 41 | int dont_use_eagerness_for_disambiguation, 42 | int dont_use_height_for_disambiguation, 43 | char *start_state, 44 | int takes_strings, 45 | int takes_globals); 46 | PyObject *run_parser(D_Parser *dp, PyObject* string, int buf_idx); 47 | int make_tables(char *grammar_string, char *grammar_pathname); 48 | long int load_parser_tables(char *tables_name); 49 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup, Extension 2 | from distutils.command.install_data import install_data 3 | import os, sys 4 | 5 | #Pete Shinner's distutils data file fix... from distutils-sig 6 | #data installer with improved intelligence over distutils 7 | #data files are copied into the project directory instead 8 | #of willy-nilly 9 | class smart_install_data(install_data): 10 | def run(self): 11 | #need to change self.install_dir to the library dir 12 | install_cmd = self.get_finalized_command('install') 13 | self.install_dir = getattr(install_cmd, 'install_lib') 14 | return install_data.run(self) 15 | 16 | module_swigc = Extension('dparser_swigc', 17 | sources = ['dparser_wrap.c', 'pydparser.c', 'make_tables.c'], 18 | define_macros = [('SWIG_GLOBAL', None)], 19 | libraries = ['mkdparse', 'dparse'], 20 | library_dirs = ['../'], 21 | extra_compile_args = ['-Wall']) 22 | 23 | setup(name="dparser", 24 | cmdclass = {"install_data": smart_install_data}, 25 | version = "1.9", 26 | description = 'DParser for Python', 27 | py_modules = ["dparser"], 28 | ext_modules = [module_swigc], 29 | ) 30 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/tests/runtests.py: -------------------------------------------------------------------------------- 1 | import glob, os 2 | for i in glob.glob('test*.py'): 3 | os.system('python %s' % i) 4 | os.system('rm d_parser*') 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/tests/test.py: -------------------------------------------------------------------------------- 1 | from dparser import Parser 2 | 3 | def d_S(t): 4 | '''S : d '+' d''' 5 | return t[0] + t[2] 6 | 7 | def d_number(t): 8 | '''d : "[0-9]+" ''' 9 | return int(t[0]) 10 | 11 | def skip_space(loc): 12 | while loc.s < len(loc.buf) and loc.buf[loc.s:loc.s+len('hello')] == 'hello': 13 | loc.s = loc.s + len('hello') 14 | 15 | parser = Parser(make_grammar_file=1) 16 | 17 | buf = 'hi10hello+3hellohi' 18 | 19 | if parser.parse(buf, buf_offset=2, partial_parses=1, initial_skip_space_fn = skip_space) != 13: 20 | print 'fail' 21 | 22 | buf = '87+5' 23 | if parser.parse(buf, initial_skip_space_fn = skip_space) != 92: 24 | print 'fail' 25 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/tests/test2.py: -------------------------------------------------------------------------------- 1 | from dparser import Parser 2 | 3 | def d_add(t): 4 | '''add : add '+' mul 5 | | mul''' 6 | if(len(t) == 1): 7 | return t[0] 8 | return t[0] + t[2] 9 | 10 | def d_mul(t): 11 | '''mul : mul '*' exp 12 | | exp''' 13 | if(len(t) == 1): 14 | return t[0] 15 | return t[0]*t[2] 16 | 17 | def d_exp(t): 18 | '''exp : number1 19 | | number2 20 | | '(' add ')' ''' 21 | if(len(t) == 1): 22 | return int(t[0]) 23 | return t[1] 24 | 25 | def d_number1(t): 26 | '''number1 : number''' 27 | return t[0] 28 | 29 | def d_number2(t): 30 | '''number2 : number''' 31 | return t[0] 32 | 33 | def d_number(t): 34 | '''number : "[0-9]+"''' 35 | return t[0] 36 | 37 | def ambiguity_func(v): 38 | return v[0] 39 | 40 | def d_whitespace(t, spec): 41 | "whitespace : ' '*" 42 | 43 | if Parser().parse('1 +2* (3+ 4+5)', ambiguity_fn = ambiguity_func, print_debug_info=0) != 25: 44 | print 'fail' 45 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/tests/test3.py: -------------------------------------------------------------------------------- 1 | from dparser import Parser 2 | 3 | def d_add1(t): 4 | '''add : add '+' mul''' 5 | return t[0] + t[2] 6 | 7 | def d_add2(t, nodes): 8 | '''add : mul''' 9 | return nodes[0].user.t 10 | 11 | def d_mul1(t): 12 | '''mul : mul '*' exp''' 13 | return t[0]*t[2] 14 | 15 | def d_mul2(t): 16 | '''mul : exp''' 17 | return t[0] 18 | 19 | def d_exp1(t): 20 | '''exp : "[0-9]+"''' 21 | return int(t[0]) 22 | 23 | def d_exp2(t): 24 | '''exp : '(' add ')' ''' 25 | return t[1] 26 | 27 | if Parser().parse('''3*(3+4)''') != 21: 28 | print 'fail' 29 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/tests/test4.py: -------------------------------------------------------------------------------- 1 | import dparser 2 | 3 | def d_S(t): 4 | "S: a | b" 5 | return 'S' 6 | 7 | def d_a(t): 8 | "a : x1 x1 'y'" 9 | 10 | def d_b(t): 11 | "b : x2 x2 'y'" 12 | 13 | def d_x1(t, spec): 14 | "x1 : 'x'" 15 | 16 | def d_x2(t, spec): 17 | "x2 : 'x'" 18 | if spec: 19 | return dparser.Reject 20 | 21 | def syntax_error(t): 22 | print 'fail' 23 | 24 | parser = dparser.Parser() 25 | parser.parse('xxy', syntax_error_fn = syntax_error) 26 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/tests/test5.py: -------------------------------------------------------------------------------- 1 | import dparser 2 | 3 | def d_h(t): 4 | 'h : h1 | h2' # uh oh, h1 and h2 are both matched by the letter a 5 | return t[0] 6 | 7 | def d_h1(t, spec_only): # h1 will be called for speculative parses only 8 | "h1 : 'a'" 9 | return 1 # This parse will be accepted since dparser.Reject is not returned. Its return value for the final parse will also be 1. 10 | 11 | def d_h2(t, spec): 12 | "h2 : 'a'" 13 | if spec: 14 | return dparser.Reject # don't let h2 match. If this were not here, a dparser.AmbiguityException exception would result 15 | return 2 16 | 17 | parser = dparser.Parser() 18 | if parser.parse('a') != 1: 19 | print 'error' 20 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/tests/test6.py: -------------------------------------------------------------------------------- 1 | # replaces the '%' symbol with '+', leaving the return values of actions usable for other things, such as type information, 2 | # and leaving whitespace intact. 3 | 4 | from dparser import Parser 5 | 6 | # turn a tree of strings into a single string (slowly): 7 | def stringify(s): 8 | if type(s) == str: 9 | return s 10 | out = '' 11 | for c in s: 12 | out += stringify(c) 13 | return out 14 | 15 | def d_add1(t, s): 16 | "add : add '%' exp" 17 | s[1] = '+ ' # replace the % with + 18 | 19 | def d_add2(t, s): 20 | "add : exp" 21 | 22 | def d_exp(t): 23 | 'exp : "[0-9]+" ' 24 | 25 | # if the start action specifies the 's' argument, then parser 26 | # will contain a member, s, 27 | 28 | parser = Parser() 29 | parser.parse('1 % 2 % 3') 30 | if stringify(parser.s) != '1 + 2 + 3': 31 | print 'error' 32 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/tests/test7.py: -------------------------------------------------------------------------------- 1 | # the 'nodes' argument to actions is useful for obtaining line number information and such 2 | 3 | from dparser import Parser 4 | 5 | def d_start(t, nodes, this): # in this example, nodes[0] is the D_ParseNode for 'noun' 6 | 'start : noun verb' 7 | 8 | # the 'buf' member contains the entire string that is being parsed 9 | buf = nodes[0].buf 10 | noun = nodes[0] 11 | 12 | # the 'end', 'end_skip', and 'start_loc.s' members of nodes[0] are indices into relevant parts of buf: 13 | buf[noun.start_loc.s:noun.end] # 'cat' 14 | buf[noun.start_loc.s:] # 'cat flies' 15 | buf[noun.end:] # ' flies' 16 | buf[noun.end_skip:] # 'flies' 17 | 18 | # line numbers and columns: 19 | noun.start_loc.line 20 | noun.start_loc.col 21 | 22 | # the 'this' argument is the D_ParseNode for this action: 23 | buf[this.start_loc.s:this.end] # 'cat flies' 24 | 25 | # children of a node can also be obtained with the 'c' member: 26 | # this.c[0] is the same as nodes[0] 27 | 28 | def d_noun(t, this): 29 | "noun : 'cat'" 30 | return t[0] 31 | 32 | def d_verb(t, this): 33 | "verb : 'flies'" 34 | return t[0] 35 | 36 | Parser().parse('cat flies') 37 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/tests/test8.py: -------------------------------------------------------------------------------- 1 | from dparser import Parser 2 | 3 | def d_s(t): 4 | "s : a" 5 | 6 | def d_a(t, spec): 7 | "a ::= 'a'" 8 | 9 | parser = Parser() 10 | 11 | parser.parse('a') 12 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/python/tests/test9.py: -------------------------------------------------------------------------------- 1 | import dparser 2 | from time import time 3 | from gc import get_objects, collect 4 | from random import random 5 | 6 | def d_S(t, s, spec): 7 | '''S : a b c''' 8 | 9 | def d_a(t, s, g, spec): 10 | '''a : 'a' | b ''' 11 | s = 'b1' 12 | g[0] = ['b2'] 13 | 14 | 15 | def d_b(t, g, s, spec): 16 | '''b : d | 'b' | 'B' ''' 17 | g[0] = ['b3'] 18 | if random() < 0.5: 19 | global raised 20 | raised = 1 21 | raise 'b4' 22 | return ['b5'] 23 | 24 | def d_c(t, nodes, this, parser, s, spec): 25 | '''c : 'c' ''' 26 | 27 | def d_d(t, s, spec): 28 | '''d : 'd' ''' 29 | 30 | p = dparser.Parser() 31 | 32 | caught = 0 33 | for mx in [1,10,100,1000]: 34 | t = time() 35 | i = 0 36 | bc = len(get_objects()) 37 | while i < mx: 38 | try: 39 | raised = 0 40 | f = p.parse('a d c', print_debug_info=0) 41 | except: 42 | raised = 0 43 | if raised: 44 | print 'fail' 45 | i += 1 46 | ac = len(get_objects()) 47 | x = time() 48 | ''' 49 | print """Created Objects per Iteration: --> %s <-- 50 | """ % ((ac-bc)/i) 51 | ''' 52 | if ac-bc !=0: 53 | print 'fail ac-bc' 54 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/read_binary.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2002-2004 John Plevyak, All Rights Reserved 3 | */ 4 | 5 | D_ParserTables *read_binary_tables(char *file_name, D_ReductionCode spec_code, D_ReductionCode final_code); 6 | D_ParserTables *read_binary_tables_from_file(FILE *fp, D_ReductionCode spec_code, D_ReductionCode final_code); 7 | D_ParserTables *read_binary_tables_from_string(unsigned char *buf, D_ReductionCode spec_code, D_ReductionCode final_code); 8 | 9 | typedef struct BinaryTablesHead { 10 | int n_relocs; 11 | int n_strings; 12 | int d_parser_tables_loc; 13 | int tables_size; 14 | int strings_size; 15 | } BinaryTablesHead; 16 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/scan.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2002-2004 John Plevyak, All Rights Reserved 3 | */ 4 | 5 | #ifndef _scan_H_ 6 | #define _scan_H_ 7 | 8 | #include "d.h" 9 | 10 | typedef struct ShiftResult { 11 | struct SNode *snode; 12 | D_Shift *shift; 13 | d_loc_t loc; 14 | } ShiftResult; 15 | 16 | int scan_buffer(d_loc_t *loc, D_State *st, ShiftResult *result); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/3: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | A: ID ( ',' ID { printf( "moreIDs\n" ); } )* ';' ; 5 | ID: "[a-z]+" { printf( "ID\n" ); } ; 6 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/ansic.test.g.1: -------------------------------------------------------------------------------- 1 | int i = 1; 2 | int x = &; 3 | int j = 2; 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/ansic.test.g.1.check: -------------------------------------------------------------------------------- 1 | ansic.test.g.1:2: syntax error after '&' 2 | 153 states 59 scans 58 shifts 97 reductions 0 compares 0 ambiguities 3 | (( int ((( i )( = ((((((((((((( 1 )))))))))))))))) ; )( int ((( j )( = ((((((((((((( 2 )))))))))))))))) ; )) 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g1.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | S: A S 'b' | 'x'; 5 | A: [ printf("speculative e-reduce A\n"); ] 6 | { printf("final e-reduce A\n"); }; 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g1.test.g.1: -------------------------------------------------------------------------------- 1 | xbbb 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g1.test.g.1.check: -------------------------------------------------------------------------------- 1 | speculative e-reduce A 2 | final e-reduce A 3 | final e-reduce A 4 | final e-reduce A 5 | 14 states 6 scans 5 shifts 4 reductions 0 compares 0 ambiguities 6 | ((( x b ) b ) b ) 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g10.test.g: -------------------------------------------------------------------------------- 1 | S: 'a' 'b' 'c'; 2 | whitespace: "[ \t\n]*"; 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g10.test.g.1: -------------------------------------------------------------------------------- 1 | a b c 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g10.test.g.1.check: -------------------------------------------------------------------------------- 1 | 5 states 3 scans 3 shifts 1 reductions 0 compares 0 ambiguities 2 | ( a b c ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g11.test.g: -------------------------------------------------------------------------------- 1 | S: A B C; 2 | A: 'a'?; 3 | B: 'b'*; 4 | C: 'c'+; 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g11.test.g.1: -------------------------------------------------------------------------------- 1 | abc 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g11.test.g.1.check: -------------------------------------------------------------------------------- 1 | 17 states 8 scans 3 shifts 10 reductions 0 compares 0 ambiguities 2 | ( a b c ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g11.test.g.2: -------------------------------------------------------------------------------- 1 | cc 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g11.test.g.2.check: -------------------------------------------------------------------------------- 1 | 13 states 5 scans 2 shifts 8 reductions 0 compares 0 ambiguities 2 | (( c c )) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g11.test.g.3: -------------------------------------------------------------------------------- 1 | c 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g11.test.g.3.check: -------------------------------------------------------------------------------- 1 | 9 states 4 scans 1 shifts 5 reductions 0 compares 0 ambiguities 2 | ( c ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g12.test.g: -------------------------------------------------------------------------------- 1 | P: | 'a' P 'a' | 'b' P 'b'; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g12.test.g.1: -------------------------------------------------------------------------------- 1 | a a a a b a b b a b a a a a 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g12.test.g.1.check: -------------------------------------------------------------------------------- 1 | 48 states 34 scans 24 shifts 15 reductions 0 compares 0 ambiguities 2 | ( a ( a ( a ( a ( b ( a ( b b ) a ) b ) a ) a ) a ) a ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g13.test.g: -------------------------------------------------------------------------------- 1 | S : 'i' S ('e' S)? | 'x'; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g13.test.g.1: -------------------------------------------------------------------------------- 1 | i i x e x 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g13.test.g.1.check: -------------------------------------------------------------------------------- 1 | 14 states 6 scans 5 shifts 10 reductions 1 compares 0 ambiguities 2 | ( i ( i x ( e x ))) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g14.test.g: -------------------------------------------------------------------------------- 1 | S : 'i' S | 'i' S 'e' S | 'x'; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g14.test.g.1: -------------------------------------------------------------------------------- 1 | i i x e x 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g14.test.g.1.check: -------------------------------------------------------------------------------- 1 | 11 states 6 scans 5 shifts 7 reductions 1 compares 0 ambiguities 2 | ( i ( i x e x )) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g15.test.g: -------------------------------------------------------------------------------- 1 | S : A | B; 2 | A : 'a'; 3 | B : 'a'; 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g15.test.g.1: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g15.test.g.1.check: -------------------------------------------------------------------------------- 1 | 5 states 1 scans 1 shifts 4 reductions 1 compares 1 ambiguities 2 | a 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g16.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | S : 'a' ('b' { printf("(b)\n"); })* 'c'; 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g16.test.g.1: -------------------------------------------------------------------------------- 1 | a b b b c 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g16.test.g.1.check: -------------------------------------------------------------------------------- 1 | (b) 2 | (b) 3 | (b) 4 | 14 states 5 scans 5 shifts 7 reductions 0 compares 0 ambiguities 5 | ( a ( b b b ) c ) 6 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g17.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | A: ID moreIDs* ';' ; 5 | moreIDs: ',' ID { printf( "moreIDs\n" ); } ; 6 | ID: "[a-z]+" { printf( "ID\n" ); } ; 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g17.test.g.1: -------------------------------------------------------------------------------- 1 | abc,def,ghi; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g17.test.g.1.check: -------------------------------------------------------------------------------- 1 | ID 2 | ID 3 | moreIDs 4 | ID 5 | moreIDs 6 | 16 states 6 scans 6 shifts 8 reductions 0 compares 0 ambiguities 7 | ( abc (( , def )( , ghi )) ; ) 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g18.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | A: ID ( ',' ID { printf( "moreIDs\n" ); } )* ';' ; 5 | ID: "[a-z]+" { printf( "ID\n" ); } ; 6 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g18.test.g.1: -------------------------------------------------------------------------------- 1 | abc,def,ghi; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g18.test.g.1.check: -------------------------------------------------------------------------------- 1 | ID 2 | ID 3 | moreIDs 4 | ID 5 | moreIDs 6 | 16 states 6 scans 6 shifts 8 reductions 0 compares 0 ambiguities 7 | ( abc (( , def )( , ghi )) ; ) 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g19.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | ${declare all_matches A} 5 | A: ID moreIDs* ';' ; 6 | moreIDs: ',' ID { printf( "moreIDs\n" ); } ; 7 | ID: "[a-z]+" { printf( "ID\n" ); } ; 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g19.test.g.1: -------------------------------------------------------------------------------- 1 | abc,def,ghi; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g19.test.g.1.check: -------------------------------------------------------------------------------- 1 | ID 2 | ID 3 | moreIDs 4 | ID 5 | moreIDs 6 | 16 states 6 scans 6 shifts 8 reductions 0 compares 0 ambiguities 7 | ( abc (( , def )( , ghi )) ; ) 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g2.test.g: -------------------------------------------------------------------------------- 1 | A: 'd' | B; 2 | B: A; 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g2.test.g.1: -------------------------------------------------------------------------------- 1 | d 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g2.test.g.1.check: -------------------------------------------------------------------------------- 1 | 4 states 1 scans 1 shifts 3 reductions 1 compares 0 ambiguities 2 | d 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g20.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | ${tokenize all_matches A} 5 | A: ID ( ',' ID { printf( "moreIDs\n" ); } )* ';' ; 6 | ID: "[a-z]+" { printf( "ID\n" ); } ; 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g20.test.g.1: -------------------------------------------------------------------------------- 1 | abc,def,ghi; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g20.test.g.1.check: -------------------------------------------------------------------------------- 1 | ID 2 | ID 3 | moreIDs 4 | ID 5 | moreIDs 6 | 16 states 6 scans 6 shifts 8 reductions 0 compares 0 ambiguities 7 | ( abc (( , def )( , ghi )) ; ) 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g21.test.g: -------------------------------------------------------------------------------- 1 | S : S bop S | uop S | 'x'; 2 | bop : '+' $binary_op_left 2 3 | | $binary_op_left 1; 4 | uop : '+' $unary_op_right 3; 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g21.test.g.1: -------------------------------------------------------------------------------- 1 | x + x 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g21.test.g.1.check: -------------------------------------------------------------------------------- 1 | 12 states 7 scans 4 shifts 5 reductions 0 compares 0 ambiguities 2 | ( x + x ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g22.test.g: -------------------------------------------------------------------------------- 1 | E : E bop F | F; 2 | bop: '+' $binary_op_left 2 | $binary_op_left 1; 3 | F : uop F | 'x'; 4 | uop: '+' $unary_op_right 3; 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g22.test.g.1: -------------------------------------------------------------------------------- 1 | x + x 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g22.test.g.1.check: -------------------------------------------------------------------------------- 1 | 14 states 7 scans 5 shifts 8 reductions 1 compares 0 ambiguities 2 | ( x + x ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g23.test.g: -------------------------------------------------------------------------------- 1 | ${declare set_op_priority_from_rule} 2 | S : S '+' S $left 2 | S S $left 1 | '+' S $unary_right 3 | 'x'; 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g23.test.g.1: -------------------------------------------------------------------------------- 1 | x + x 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g23.test.g.1.check: -------------------------------------------------------------------------------- 1 | 10 states 8 scans 5 shifts 5 reductions 1 compares 0 ambiguities 2 | ( x + x ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g24.test.g: -------------------------------------------------------------------------------- 1 | S: number*; 2 | number ::= integer | longinteger | floatnumber | imagnumber; 3 | integer ::= decimalinteger | octinteger | hexinteger; 4 | decimalinteger ::= nonzerodigit digit* | '0'; 5 | octinteger ::= '0' octdigit+; 6 | hexinteger ::= '0' ('x' | 'X') hexdigit+; 7 | floatnumber ::= pointfloat | exponentfloat; 8 | pointfloat ::= intpart? fraction | intpart '.'; 9 | exponentfloat ::= (intpart | pointfloat) exponent; 10 | intpart ::= digit+; 11 | fraction ::= "." digit+; 12 | exponent ::= ("e" | "E") ("+" | "-")? digit+; 13 | imagnumber ::= (floatnumber | intpart) ("j" | "J"); 14 | longinteger ::= integer ("l" | "L"); 15 | nonzerodigit ::= "[1-9]"; 16 | digit ::= "[0-9]"; 17 | octdigit ::= "[0-7]"; 18 | hexdigit ::= digit | "[a-fA-F]"; 19 | 20 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g24.test.g.1: -------------------------------------------------------------------------------- 1 | 123.456e-10 2 | 123.456e-10J 3 | 01234 4 | 234L 5 | 0xBADFEED 6 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g24.test.g.1.check: -------------------------------------------------------------------------------- 1 | 18 states 6 scans 5 shifts 11 reductions 0 compares 0 ambiguities 2 | ( 123.456e-10 123.456e-10J 01234 234L 0xBADFEED ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g25.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include "dparse_tables.h" 3 | 4 | void mywhite(struct D_Parser *p, d_loc_t *loc, void **p_globals) { 5 | while (*loc->s == ' ') loc->s++; 6 | } 7 | 8 | } 9 | 10 | ${declare whitespace mywhite} 11 | S: '\n' '\t' '\n'; 12 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g25.test.g.1: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g25.test.g.1.check: -------------------------------------------------------------------------------- 1 | 5 states 3 scans 3 shifts 1 reductions 0 compares 0 ambiguities 2 | ( 3 | 4 | ) 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g26.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | 5 | S: a [ printf("S\n"); ]; 6 | a ::= 'a' [ printf("a\n"); ]; 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g26.test.g.1: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g26.test.g.1.check: -------------------------------------------------------------------------------- 1 | a 2 | S 3 | 3 states 1 scans 1 shifts 1 reductions 0 compares 0 ambiguities 4 | a 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g27.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | S: A+; 5 | A: 'a' B* { 6 | int i; 7 | printf("["); 8 | for (i = 0; i < d_get_number_of_children(&$n1); i++) 9 | printf("(%c)", *d_get_child(&$n1, i)->start_loc.s); 10 | printf("]\n"); 11 | }; 12 | B: 'b' | 'B'; 13 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g27.test.g.1: -------------------------------------------------------------------------------- 1 | a b B b 2 | a 3 | a b 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g27.test.g.1.check: -------------------------------------------------------------------------------- 1 | [(b)(B)(b)] 2 | [] 3 | [(b)] 4 | 40 states 15 scans 7 shifts 29 reductions 0 compares 0 ambiguities 5 | (( a ( b B b ))( a )( a b )) 6 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g28.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | 4 | typedef struct My_Sym { 5 | int value; 6 | } My_Sym; 7 | #define D_UserSym My_Sym 8 | typedef struct My_ParseNode { 9 | int value; 10 | struct D_Scope *scope; 11 | } My_ParseNode; 12 | #define D_ParseNode_User My_ParseNode 13 | } 14 | 15 | translation_unit: statement*; 16 | 17 | statement 18 | : expression ';' 19 | { printf("%d\n", $0.value); } 20 | | '{' statement* '}' 21 | [ ${scope} = enter_D_Scope(${scope}, $n0.scope); ] 22 | { ${scope} = commit_D_Scope(${scope}); } 23 | ; 24 | 25 | expression 26 | : identifier ':' expression 27 | [ 28 | D_Sym *s; 29 | ${scope} = new_D_Scope(${scope}); 30 | s = NEW_D_SYM(${scope}, $n0.start_loc.s, $n0.end); 31 | s->user.value = $2.value; 32 | $$.value = s->user.value; 33 | ] 34 | | identifier '=' expression 35 | [ D_Sym *s = find_D_Sym(${scope}, $n0.start_loc.s, $n0.end); 36 | s = UPDATE_D_SYM(s, &${scope}); 37 | s->user.value = $2.value; 38 | $$.value = s->user.value; 39 | ] 40 | | integer 41 | [ $$.value = atoi($n0.start_loc.s); ] 42 | | identifier 43 | [ D_Sym *s = find_D_Sym(${scope}, $n0.start_loc.s, $n0.end); 44 | if (s) 45 | $$.value = s->user.value; 46 | ] 47 | | expression '+' expression 48 | [ $$.value = $0.value + $1.value; ] 49 | ; 50 | 51 | integer: "-?([0-9]|0(x|X))[0-9]*(u|U|b|B|w|W|L|l)*" $term -1; 52 | identifier: "[a-zA-Z_][a-zA-Z_0-9]*"; 53 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g28.test.g.1: -------------------------------------------------------------------------------- 1 | a: 1; 2 | a; 3 | { 4 | a: 2; 5 | a; 6 | } 7 | a; 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g28.test.g.1.check: -------------------------------------------------------------------------------- 1 | 1 2 | 1 3 | 2 4 | 2 5 | 1 6 | 52 states 24 scans 16 shifts 33 reductions 0 compares 0 ambiguities 7 | ((( a : 1 ) ; )( a ; )( { ((( a : 2 ) ; )( a ; )) } )( a ; )) 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g28.test.g.2: -------------------------------------------------------------------------------- 1 | a: 1; 2 | { 3 | a: 2; 4 | a; 5 | a: 3; 6 | { 7 | a; 8 | a: 4; 9 | a; 10 | a = 5; 11 | a; 12 | } 13 | a; 14 | { 15 | a = 6; 16 | } 17 | a; 18 | } 19 | a; 20 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g28.test.g.2.check: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 2 4 | 3 5 | 3 6 | 4 7 | 4 8 | 5 9 | 5 10 | 3 11 | 6 12 | 6 13 | 1 14 | 129 states 64 scans 44 shifts 80 reductions 0 compares 0 ambiguities 15 | ((( a : 1 ) ; )( { ((( a : 2 ) ; )( a ; )(( a : 3 ) ; )( { (( a ; )(( a : 4 ) ; )( a ; )(( a = 5 ) ; )( a ; )) } )( a ; )( { (( a = 6 ) ; ) } )( a ; )) } )( a ; )) 16 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g29.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | 4 | typedef struct My_Sym { 5 | int value; 6 | } My_Sym; 7 | #define D_UserSym My_Sym 8 | typedef struct My_ParseNode { 9 | int value; 10 | struct D_Scope *scope; 11 | } My_ParseNode; 12 | #define D_ParseNode_User My_ParseNode 13 | } 14 | 15 | translation_unit: statement*; 16 | 17 | statement 18 | : expression ';' 19 | { printf("%d\n", $0.value); } 20 | | '{' new_scope statement* '}' 21 | [ ${scope} = enter_D_Scope(${scope}, $n0.scope); ] 22 | ; 23 | 24 | new_scope: [ ${scope} = new_D_Scope(${scope}); ]; 25 | 26 | expression 27 | : identifier ':' expression 28 | [ 29 | D_Sym *s; 30 | if (find_D_Sym_in_Scope(${scope}, ${scope}, $n0.start_loc.s, $n0.end)) 31 | printf("duplicate identifier line %d\n", $n0.start_loc.line); 32 | s = NEW_D_SYM(${scope}, $n0.start_loc.s, $n0.end); 33 | s->user.value = $2.value; 34 | $$.value = s->user.value; 35 | ] 36 | | identifier '=' expression 37 | [ D_Sym *s = find_D_Sym(${scope}, $n0.start_loc.s, $n0.end); 38 | s = UPDATE_D_SYM(s, &${scope}); 39 | s->user.value = $2.value; 40 | $$.value = s->user.value; 41 | ] 42 | | integer 43 | [ $$.value = atoi($n0.start_loc.s); ] 44 | | identifier 45 | [ D_Sym *s = find_D_Sym(${scope}, $n0.start_loc.s, $n0.end); 46 | if (s) 47 | $$.value = s->user.value; 48 | ] 49 | | expression '+' expression 50 | [ $$.value = $0.value + $1.value; ] 51 | ; 52 | 53 | integer: "-?([0-9]|0(x|X))[0-9]*(u|U|b|B|w|W|L|l)*" $term -1; 54 | identifier: "[a-zA-Z_][a-zA-Z_0-9]*"; 55 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g29.test.g.1: -------------------------------------------------------------------------------- 1 | a: 1; 2 | { 3 | a: 2; 4 | a; 5 | a: 3; 6 | { 7 | a; 8 | a: 4; 9 | a; 10 | a = 5; 11 | a; 12 | } 13 | a; 14 | { 15 | a = 6; 16 | } 17 | a: 7; 18 | a; 19 | } 20 | a; 21 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g29.test.g.1.check: -------------------------------------------------------------------------------- 1 | duplicate identifier line 5 2 | duplicate identifier line 17 3 | 1 4 | 2 5 | 2 6 | 3 7 | 3 8 | 4 9 | 4 10 | 5 11 | 5 12 | 3 13 | 6 14 | 7 15 | 7 16 | 1 17 | 143 states 70 scans 48 shifts 87 reductions 0 compares 0 ambiguities 18 | ((( a : 1 ) ; )( { ((( a : 2 ) ; )( a ; )(( a : 3 ) ; )( { (( a ; )(( a : 4 ) ; )( a ; )(( a = 5 ) ; )( a ; )) } )( a ; )( { (( a = 6 ) ; ) } )(( a : 7 ) ; )( a ; )) } )( a ; )) 19 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g3.test.g: -------------------------------------------------------------------------------- 1 | E: E '+' E | "[abc]"; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g3.test.g.1: -------------------------------------------------------------------------------- 1 | b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g3.test.g.1.check: -------------------------------------------------------------------------------- 1 | 103 states 77 scans 75 shifts 2951 reductions 2600 compares 0 ambiguities 2 | ((((((((((((((((((((((((( b + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g30.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include "stdio.h" 3 | } 4 | 5 | S: A { printf("."); } B; 6 | A: 'a' { printf("a"); }; 7 | B: 'b' { printf("b"); }; 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g30.test.g.1: -------------------------------------------------------------------------------- 1 | ab 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g30.test.g.1.check: -------------------------------------------------------------------------------- 1 | a.b7 states 2 scans 2 shifts 3 reductions 0 compares 0 ambiguities 2 | ( a b ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g31.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | 5 | ${pass sym for_all postorder} 6 | ${pass gen for_all postorder} 7 | 8 | translation_unit: statement*; 9 | 10 | statement 11 | : expression ';' 12 | { 13 | printf("final expression\n"); 14 | d_pass(${parser}, &$n, ${pass sym}); 15 | d_pass(${parser}, &$n, ${pass gen}); 16 | } 17 | ; 18 | 19 | expression 20 | : identifier '=' expression $right 1 21 | sym: { printf("sym =\n"); } 22 | gen: { printf("gen =\n"); } 23 | | integer 24 | gen: { printf("gen integer\n"); } 25 | sym: { printf("sym integer\n"); } 26 | | expression '+' expression $right 2 27 | sym: { printf("sym +\n"); } 28 | ; 29 | 30 | integer: "-?([0-9]|0(x|X))[0-9]*(u|U|b|B|w|W|L|l)*" $term -1; 31 | identifier: "[a-zA-Z_][a-zA-Z_0-9]*"; 32 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g31.test.g.1: -------------------------------------------------------------------------------- 1 | 1; 2 | 2 + 3; 3 | b = 3 + 4; 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g31.test.g.1.check: -------------------------------------------------------------------------------- 1 | final expression 2 | sym integer 3 | gen integer 4 | final expression 5 | sym integer 6 | sym integer 7 | sym + 8 | gen integer 9 | gen integer 10 | final expression 11 | sym integer 12 | sym integer 13 | sym + 14 | sym = 15 | gen integer 16 | gen integer 17 | gen = 18 | 39 states 17 scans 13 shifts 26 reductions 0 compares 0 ambiguities 19 | (( 1 ; )(( 2 + 3 ) ; )(( b = ( 3 + 4 )) ; )) 20 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g32.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | #include 4 | #include 5 | char *xdup(char *s, char *e) { 6 | char *ss = malloc( e - s + 2 ); 7 | memcpy(ss, s, e-s); 8 | ss[e-s] = 0; 9 | return ss; 10 | } 11 | } 12 | 13 | translation_unit: statement*; 14 | 15 | statement 16 | : expression ';' 17 | { printf("(%s)expression ;(%s)", 18 | xdup(d_ws_before(${parser}, &$n), $n.start_loc.s), 19 | xdup($n.end, d_ws_after(${parser}, &$n))); 20 | } 21 | ; 22 | 23 | expression 24 | : identifier '=' expression $right 1 25 | { printf("(%s)= in expression(%s)", 26 | xdup(d_ws_before(${parser}, &$n1), $n1.start_loc.s), 27 | xdup($n1.end, d_ws_after(${parser}, &$n1))); 28 | } 29 | | integer 30 | { printf("(%s)expression: integer(%s)", 31 | xdup(d_ws_before(${parser}, &$n0), $n0.start_loc.s), 32 | xdup($n0.end, d_ws_after(${parser}, &$n0))); 33 | } 34 | | expression '+' expression $right 2 35 | { printf("(%s)+ in expression(%s)", 36 | xdup(d_ws_before(${parser}, &$n1), $n1.start_loc.s), 37 | xdup($n1.end, d_ws_after(${parser}, &$n1))); 38 | } 39 | ; 40 | 41 | integer: "-?([0-9]|0(x|X))[0-9]*(u|U|b|B|w|W|L|l)*" $term -1; 42 | identifier: "[a-zA-Z_][a-zA-Z_0-9]*" 43 | { printf("(%s)identifier(%s)", 44 | xdup(d_ws_before(${parser}, &$n0), $n0.start_loc.s), 45 | xdup($n0.end, d_ws_after(${parser}, &$n0))); 46 | } 47 | ; 48 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g32.test.g.1: -------------------------------------------------------------------------------- 1 | /* start */ 2 | a /*some a*/ = /*after = before 1 */ 1 /* after 1 before ; */ ; 3 | /* end */ 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g32.test.g.1.check: -------------------------------------------------------------------------------- 1 | (/* start */ 2 | )identifier( /*some a*/ )( /*after = before 1 */ )expression: integer( /* after 1 before ; */ )( /*some a*/ )= in expression( /*after = before 1 */ )(/* start */ 3 | )expression ;( 4 | /* end */ 5 | )14 states 6 scans 4 shifts 8 reductions 0 compares 0 ambiguities 6 | (( a = 1 ) ; ) 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g32.test.g.orig: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | #include 4 | char *xdup(char *s, char *e) { 5 | char *ss = malloc( e - s + 2 ); 6 | memcpy(ss, s, e-s); 7 | ss[e-s] = 0; 8 | return ss; 9 | } 10 | } 11 | 12 | translation_unit: statement*; 13 | 14 | statement 15 | : expression ';' 16 | { printf("(%s)expression ;(%s)", 17 | xdup(d_ws_before(${parser}, &$n), $n.start_loc.s), 18 | xdup($n.end, d_ws_after(${parser}, &$n))); 19 | } 20 | ; 21 | 22 | expression 23 | : identifier '=' expression $right 1 24 | { printf("(%s)= in expression(%s)", 25 | xdup(d_ws_before(${parser}, &$n1), $n1.start_loc.s), 26 | xdup($n1.end, d_ws_after(${parser}, &$n1))); 27 | } 28 | | integer 29 | { printf("(%s)expression: integer(%s)", 30 | xdup(d_ws_before(${parser}, &$n0), $n0.start_loc.s), 31 | xdup($n0.end, d_ws_after(${parser}, &$n0))); 32 | } 33 | | expression '+' expression $right 2 34 | { printf("(%s)+ in expression(%s)", 35 | xdup(d_ws_before(${parser}, &$n1), $n1.start_loc.s), 36 | xdup($n1.end, d_ws_after(${parser}, &$n1))); 37 | } 38 | ; 39 | 40 | integer: "-?([0-9]|0(x|X))[0-9]*(u|U|b|B|w|W|L|l)*" $term -1; 41 | identifier: "[a-zA-Z_][a-zA-Z_0-9]*" 42 | { printf("(%s)identifier(%s)", 43 | xdup(d_ws_before(${parser}, &$n0), $n0.start_loc.s), 44 | xdup($n0.end, d_ws_after(${parser}, &$n0))); 45 | } 46 | ; 47 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g33.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | #include 4 | #include 5 | #include "dparse_tables.h" 6 | extern D_Symbol d_symbols_gram[]; 7 | char *xdup(char *s, char *e) { 8 | char *ss = malloc( e - s + 2 ); 9 | memcpy(ss, s, e-s); 10 | ss[e-s] = 0; 11 | return ss; 12 | } 13 | } 14 | 15 | ${pass sym for_all postorder} 16 | ${pass gen for_all postorder} 17 | 18 | translation_unit: statement*; 19 | 20 | _: 21 | sym: { 22 | printf("default sym(%s : \"%s\")\n", 23 | d_symbols_gram[$n.symbol].name, 24 | xdup($n.start_loc.s, $n.end) 25 | ); 26 | } 27 | gen: { 28 | printf("default gen(%s : \"%s\")\n", 29 | d_symbols_gram[$n.symbol].name, 30 | xdup($n.start_loc.s, $n.end) 31 | ); 32 | } 33 | ; 34 | 35 | statement 36 | : expression ';' 37 | { 38 | printf("final expression\n"); 39 | d_pass(${parser}, &$n, ${pass sym}); 40 | d_pass(${parser}, &$n, ${pass gen}); 41 | } 42 | ; 43 | 44 | expression 45 | : identifier '=' expression $right 1 46 | sym: { printf("sym expression: =\n"); } 47 | | integer 48 | gen: { printf("gen expression: integer\n"); } 49 | sym: { printf("sym expression: integer\n"); } 50 | | expression '+' expression $right 2 51 | sym: { printf("sym +\n"); } 52 | ; 53 | 54 | integer: "-?([0-9]|0(x|X))[0-9]*(u|U|b|B|w|W|L|l)*" $term -1 55 | sym: { printf("sym integer\n"); } 56 | ; 57 | identifier: "[a-zA-Z_][a-zA-Z_0-9]*"; 58 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g33.test.g.1: -------------------------------------------------------------------------------- 1 | 1; 2 | 2 + 3; 3 | b = 3 + 4; 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g33.test.g.1.check: -------------------------------------------------------------------------------- 1 | final expression 2 | sym integer 3 | sym expression: integer 4 | default sym(statement : "1;") 5 | default gen(integer : "1") 6 | gen expression: integer 7 | default gen(statement : "1;") 8 | final expression 9 | sym integer 10 | sym expression: integer 11 | sym integer 12 | sym expression: integer 13 | sym + 14 | default sym(statement : "2 + 3;") 15 | default gen(integer : "2") 16 | gen expression: integer 17 | default gen(integer : "3") 18 | gen expression: integer 19 | default gen(expression : "2 + 3") 20 | default gen(statement : "2 + 3;") 21 | final expression 22 | default sym(identifier : "b") 23 | sym integer 24 | sym expression: integer 25 | sym integer 26 | sym expression: integer 27 | sym + 28 | sym expression: = 29 | default sym(statement : "b = 3 + 4;") 30 | default gen(identifier : "b") 31 | default gen(integer : "3") 32 | gen expression: integer 33 | default gen(integer : "4") 34 | gen expression: integer 35 | default gen(expression : "3 + 4") 36 | default gen(expression : "b = 3 + 4") 37 | default gen(statement : "b = 3 + 4;") 38 | 39 states 17 scans 13 shifts 26 reductions 0 compares 0 ambiguities 39 | (( 1 ; )(( 2 + 3 ) ; )(( b = ( 3 + 4 )) ; )) 40 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g33.test.g.orig: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | #include 4 | #include "dparse_tables.h" 5 | extern D_Symbol d_symbols_gram[]; 6 | char *xdup(char *s, char *e) { 7 | char *ss = malloc( e - s + 2 ); 8 | memcpy(ss, s, e-s); 9 | ss[e-s] = 0; 10 | return ss; 11 | } 12 | } 13 | 14 | ${pass sym for_all postorder} 15 | ${pass gen for_all postorder} 16 | 17 | translation_unit: statement*; 18 | 19 | _: 20 | sym: { 21 | printf("default sym(%s : \"%s\")\n", 22 | d_symbols_gram[$n.symbol].name, 23 | xdup($n.start_loc.s, $n.end) 24 | ); 25 | } 26 | gen: { 27 | printf("default gen(%s : \"%s\")\n", 28 | d_symbols_gram[$n.symbol].name, 29 | xdup($n.start_loc.s, $n.end) 30 | ); 31 | } 32 | ; 33 | 34 | statement 35 | : expression ';' 36 | { 37 | printf("final expression\n"); 38 | d_pass(${parser}, &$n, ${pass sym}); 39 | d_pass(${parser}, &$n, ${pass gen}); 40 | } 41 | ; 42 | 43 | expression 44 | : identifier '=' expression $right 1 45 | sym: { printf("sym expression: =\n"); } 46 | | integer 47 | gen: { printf("gen expression: integer\n"); } 48 | sym: { printf("sym expression: integer\n"); } 49 | | expression '+' expression $right 2 50 | sym: { printf("sym +\n"); } 51 | ; 52 | 53 | integer: "-?([0-9]|0(x|X))[0-9]*(u|U|b|B|w|W|L|l)*" $term -1 54 | sym: { printf("sym integer\n"); } 55 | ; 56 | identifier: "[a-zA-Z_][a-zA-Z_0-9]*"; 57 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g34.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | 5 | ${declare longest_match identifier} 6 | 7 | P: S*; 8 | 9 | S: 'do' identifier 10 | { printf("do identifier\n"); } 11 | | identifier 12 | { printf("identifier\n"); } 13 | | identifierX 14 | { printf("identifierX\n"); } 15 | ; 16 | 17 | identifier: "[a-z]+" $term -1; 18 | identifierX: "[a-z]+X" $term -1; 19 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g34.test.g.1: -------------------------------------------------------------------------------- 1 | dont 2 | thinkX 3 | do thinkit 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g34.test.g.1.check: -------------------------------------------------------------------------------- 1 | identifier 2 | identifierX 3 | do identifier 4 | 19 states 5 scans 4 shifts 13 reductions 0 compares 0 ambiguities 5 | ( dont thinkX ( do thinkit )) 6 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g35.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | 5 | S: identifier* 6 | { printf("identifier\n"); } 7 | ; 8 | 9 | identifier: "[a-z<>=+]+"; 10 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g35.test.g.1: -------------------------------------------------------------------------------- 1 | asdf 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g35.test.g.1.check: -------------------------------------------------------------------------------- 1 | identifier 2 | 7 states 2 scans 1 shifts 4 reductions 0 compares 0 ambiguities 3 | asdf 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g36.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include 3 | } 4 | 5 | ${declare all_matches S} 6 | ${declare longest_match do} 7 | 8 | P: S*; 9 | 10 | S: do identifier 11 | { printf("do identifier\n"); } 12 | | identifier 13 | { printf("identifier\n"); } 14 | | identifierX 15 | { printf("identifierX\n"); } 16 | ; 17 | 18 | do ::= 'do'; 19 | identifier: "[a-z]+" $term -1; 20 | identifierX: "[a-z]+X" $term -1; 21 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g36.test.g.1: -------------------------------------------------------------------------------- 1 | dont 2 | formulaX 3 | formula 4 | do form 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g36.test.g.1.check: -------------------------------------------------------------------------------- 1 | identifier 2 | identifierX 3 | identifier 4 | do identifier 5 | 32 states 8 scans 8 shifts 23 reductions 1 compares 0 ambiguities 6 | ( dont formulaX formula ( do form )) 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g37.test.g: -------------------------------------------------------------------------------- 1 | S: 'tHiS'/i "tH[a-z]T"/i; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g37.test.g.1: -------------------------------------------------------------------------------- 1 | THIS that 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g37.test.g.1.check: -------------------------------------------------------------------------------- 1 | 4 states 2 scans 2 shifts 1 reductions 0 compares 0 ambiguities 2 | ( THIS that ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g38.test.g: -------------------------------------------------------------------------------- 1 | S: A B; 2 | A: 'this'; 3 | B: 'that'; 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g38.test.g.1: -------------------------------------------------------------------------------- 1 | that 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g38.test.g.1.check: -------------------------------------------------------------------------------- 1 | 3 states 1 scans 1 shifts 1 reductions 0 compares 0 ambiguities 2 | that 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g38.test.g.1.flags: -------------------------------------------------------------------------------- 1 | -S 3 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g38.test.g.flags: -------------------------------------------------------------------------------- 1 | -A 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g39.test.g: -------------------------------------------------------------------------------- 1 | S: '\x74\d104\141t'; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g39.test.g.1: -------------------------------------------------------------------------------- 1 | that 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g39.test.g.1.check: -------------------------------------------------------------------------------- 1 | 3 states 1 scans 1 shifts 1 reductions 0 compares 0 ambiguities 2 | that 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g4.test.g: -------------------------------------------------------------------------------- 1 | { 2 | extern char *ops; 3 | extern void *ops_cache; 4 | int ops_scan(char *ops, void *ops_cache, char **as, 5 | int *col, int *line, unsigned char *op_assoc, int *op_priority); 6 | } 7 | 8 | X: '1' (${scan ops_scan(ops, ops_cache)} '2')*; 9 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g4.test.g.1: -------------------------------------------------------------------------------- 1 | 1 + 2 + 2 + 2 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g4.test.g.1.check: -------------------------------------------------------------------------------- 1 | 19 states 8 scans 7 shifts 10 reductions 0 compares 0 ambiguities 2 | ( 1 (( + 2 )( + 2 )( + 2 ))) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g40.test.g: -------------------------------------------------------------------------------- 1 | { 2 | 3 | struct D_Sym; 4 | struct D_Scope; 5 | 6 | typedef struct My_ParseNode { 7 | struct D_Sym *sym; 8 | struct D_Scope *saved_scope; 9 | } My_ParseNode; 10 | #define D_ParseNode_User My_ParseNode 11 | 12 | #define NEW_SYM(_s, _scope, _start, _end) do { \ 13 | _scope = enter_D_Scope(_scope, _scope); /* clone scope */ \ 14 | _s = NEW_D_SYM(_scope, _start, _end); \ 15 | } while (0) 16 | 17 | } 18 | 19 | statement: expression ';' ; 20 | 21 | expression 22 | : identifier 23 | | def_identifier expression $right 5100 /* define variable */ 24 | | def_function expression $right 5100 /* define function */ 25 | [ ${scope} = enter_D_Scope(${scope}, $0.saved_scope); ] 26 | | pre_operator expression 27 | | expression binary_operator expression 28 | ; 29 | 30 | def_identifier: identifier ':' 31 | [ NEW_SYM($$.sym, ${scope}, $n0.start_loc.s, $n0.end); ] 32 | ; 33 | 34 | def_function: identifier identifier+ ':' 35 | [ 36 | NEW_SYM($$.sym, ${scope}, $n0.start_loc.s, $n0.end); 37 | $$.saved_scope = ${scope}; 38 | ${scope} = new_D_Scope(${scope}); 39 | ] 40 | ; 41 | 42 | binary_operator 43 | : '+' $binary_op_left 9500 44 | | $binary_op_left 7000 45 | ; 46 | 47 | pre_operator 48 | : '+' $unary_op_right 9800 49 | ; 50 | 51 | identifier: "[a-zA-Z_][a-zA-Z0-9_]*" $term -1; 52 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g40.test.g.1: -------------------------------------------------------------------------------- 1 | a b : b + b; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g40.test.g.1.check: -------------------------------------------------------------------------------- 1 | 59 states 41 scans 21 shifts 36 reductions 2 compares 0 ambiguities 2 | ((( a b : )( b + b )) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g41.test.g: -------------------------------------------------------------------------------- 1 | h : h1 h2; 2 | h1 : 'a'; 3 | h2 : 'b'; 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g41.test.g.1: -------------------------------------------------------------------------------- 1 | a b 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g41.test.g.1.check: -------------------------------------------------------------------------------- 1 | 6 states 2 scans 2 shifts 3 reductions 0 compares 0 ambiguities 2 | ( a b ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g41.test.g.1.flags: -------------------------------------------------------------------------------- 1 | -S 1 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g41.test.g.flags: -------------------------------------------------------------------------------- 1 | -A 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g42.include.g: -------------------------------------------------------------------------------- 1 | A: 'a'; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g42.test.g: -------------------------------------------------------------------------------- 1 | 2 | S: A B; 3 | 4 | include "g42.include.g" 5 | 6 | B: 'b'; 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g42.test.g.1: -------------------------------------------------------------------------------- 1 | a b 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g42.test.g.1.check: -------------------------------------------------------------------------------- 1 | 6 states 2 scans 2 shifts 3 reductions 0 compares 0 ambiguities 2 | ( a b ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g43.test.g: -------------------------------------------------------------------------------- 1 | S: A B C D; 2 | A: ('a' '1')?; 3 | B: ('b' '1')*; 4 | C: ('c' '1')+; 5 | D: (('d' '1')('d' '2')?)*; 6 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g43.test.g.1: -------------------------------------------------------------------------------- 1 | a 1 b 1 b 1 c 1 c 1 d 1 d 2 d 1 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g43.test.g.1.check: -------------------------------------------------------------------------------- 1 | 63 states 27 scans 17 shifts 38 reductions 0 compares 0 ambiguities 2 | (( a 1 )(( b 1 )( b 1 ))(( c 1 )( c 1 ))((( d 1 )( d 2 ))( d 1 ))) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g43.test.g.2: -------------------------------------------------------------------------------- 1 | a 1 b 1 b 1 c 1 c 1 d 1 d 2 d 1 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g43.test.g.2.check: -------------------------------------------------------------------------------- 1 | 63 states 27 scans 17 shifts 38 reductions 0 compares 0 ambiguities 2 | (( a 1 )( b 1 b 1 )( c 1 c 1 )( d 1 d 2 d 1 )) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g43.test.g.2.flags: -------------------------------------------------------------------------------- 1 | -e 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g43.test.g.3: -------------------------------------------------------------------------------- 1 | a 1 b 1 b 1 c 1 c 1 d 1 d 2 d 1 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g43.test.g.3.check: -------------------------------------------------------------------------------- 1 | 63 states 27 scans 17 shifts 38 reductions 0 compares 0 ambiguities 2 | (( a 1 )((( b 1 ))( b 1 ))(( c 1 )( c 1 ))(((( d 1 )( d 2 )))(( d 1 )))) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g43.test.g.3.flags: -------------------------------------------------------------------------------- 1 | -f 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g44.test.g: -------------------------------------------------------------------------------- 1 | S: A; 2 | A ::= B; 3 | B ::= "[0-9]+" $name "someint"; 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g44.test.g.1: -------------------------------------------------------------------------------- 1 | 123 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g44.test.g.1.check: -------------------------------------------------------------------------------- 1 | 3 states 1 scans 1 shifts 1 reductions 0 compares 0 ambiguities 2 | 123 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g45.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include "stdio.h" 3 | #include "dparse.h" 4 | D_Scope *saved = 0; 5 | } 6 | 7 | S: def use; 8 | 9 | def: 'a' { 10 | D_Scope *s = ${scope}; 11 | ${scope} = enter_D_Scope(${scope}, ${scope}); 12 | saved = ${scope}; 13 | NEW_D_SYM(${scope}, "a", 0); 14 | ${scope} = enter_D_Scope(${scope}, s); 15 | }; 16 | 17 | use: 'b' { 18 | if (find_D_Sym(${scope}, "a", 0)) 19 | printf("failed1\n"); 20 | else 21 | printf("succeed1\n"); 22 | ${scope} = scope_D_Scope(${scope}, saved); 23 | if (find_D_Sym(${scope}, "a", 0)) 24 | printf("succeed2\n"); 25 | else 26 | printf("failed2\n"); 27 | }; 28 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g45.test.g.1: -------------------------------------------------------------------------------- 1 | a b 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g45.test.g.1.check: -------------------------------------------------------------------------------- 1 | succeed1 2 | succeed2 3 | 6 states 2 scans 2 shifts 3 reductions 0 compares 0 ambiguities 4 | ( a b ) 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g46.test.g: -------------------------------------------------------------------------------- 1 | 2 | A : "foo/bar" "barrel"; 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g46.test.g.1: -------------------------------------------------------------------------------- 1 | foobarrel 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g46.test.g.1.check: -------------------------------------------------------------------------------- 1 | 4 states 2 scans 2 shifts 1 reductions 0 compares 0 ambiguities 2 | ( foo barrel ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g5.test.g: -------------------------------------------------------------------------------- 1 | A : 'i' A ('e' A)? | 'x'; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g5.test.g.1: -------------------------------------------------------------------------------- 1 | i i x 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g5.test.g.1.check: -------------------------------------------------------------------------------- 1 | 7 states 4 scans 3 shifts 4 reductions 0 compares 0 ambiguities 2 | ( i ( i x )) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g6.test.g: -------------------------------------------------------------------------------- 1 | S: 'b' A; 2 | A : 'a' A B | ; 3 | B : ; 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g6.test.g.1: -------------------------------------------------------------------------------- 1 | b a a 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g6.test.g.1.check: -------------------------------------------------------------------------------- 1 | 14 states 4 scans 3 shifts 7 reductions 0 compares 0 ambiguities 2 | ( b ( a ( a ))) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g7.test.g: -------------------------------------------------------------------------------- 1 | { 2 | #include "g7.test.g.d_parser.h" 3 | int myscanner(char **s, int *col, int *line, unsigned short *symbol, 4 | int *term_priority, unsigned char *op_assoc, int *op_priority) 5 | { 6 | if (**s == 'a') { 7 | (*s)++; 8 | *symbol = A; 9 | return 1; 10 | } else if (**s == 'b') { 11 | (*s)++; 12 | *symbol = BB; 13 | return 1; 14 | } else if (**s == 'c') { 15 | (*s)++; 16 | *symbol = CCC; 17 | return 1; 18 | } else if (**s == 'd') { 19 | (*s)++; 20 | *symbol = DDDD; 21 | return 1; 22 | } else 23 | return 0; 24 | } 25 | 26 | } 27 | ${scanner myscanner} 28 | ${token A BB CCC DDDD} 29 | 30 | S: A (BB CCC)+ SS; 31 | SS: DDDD; 32 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g7.test.g.1: -------------------------------------------------------------------------------- 1 | a b c b c d 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g7.test.g.1.check: -------------------------------------------------------------------------------- 1 | 13 states 6 scans 6 shifts 6 reductions 0 compares 0 ambiguities 2 | ( a (( b c )( b c )) d ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g7.test.g.2: -------------------------------------------------------------------------------- 1 | abcbcbcd 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g7.test.g.2.check: -------------------------------------------------------------------------------- 1 | 17 states 8 scans 8 shifts 8 reductions 0 compares 0 ambiguities 2 | ( a (( b c )( b c )( b c )) d ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g8.test.g: -------------------------------------------------------------------------------- 1 | A: 'd' $left 2 | B $left 1; 2 | B: A; 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g8.test.g.1: -------------------------------------------------------------------------------- 1 | d 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g8.test.g.1.check: -------------------------------------------------------------------------------- 1 | 4 states 1 scans 1 shifts 3 reductions 1 compares 0 ambiguities 2 | d 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g9.test.g: -------------------------------------------------------------------------------- 1 | E: E '+' E $binary_left 1 | "[abc]"; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g9.test.g.1: -------------------------------------------------------------------------------- 1 | b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/g9.test.g.1.check: -------------------------------------------------------------------------------- 1 | 103 states 77 scans 75 shifts 2951 reductions 0 compares 0 ambiguities 2 | ((((((((((((((((((((((((( b + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) + b ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.0: -------------------------------------------------------------------------------- 1 | x++.y; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.0.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'y' line 1: not found 3 | 24 states 12 scans 6 shifts 13 reductions 0 compares 0 ambiguities 4 | ((( x ++ ) . y ) ; ) 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.1: -------------------------------------------------------------------------------- 1 | 2 + 3 * 4; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.1.check: -------------------------------------------------------------------------------- 1 | 32 states 12 scans 9 shifts 20 reductions 0 compares 0 ambiguities 2 | (( 2 + ( 3 * 4 )) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.10: -------------------------------------------------------------------------------- 1 | 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 2 + 3 + 4; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.10.check: -------------------------------------------------------------------------------- 1 | 132 states 52 scans 49 shifts 79 reductions 0 compares 0 ambiguities 2 | ((((((((((((( 1 + 2 ) + 3 ) + 4 ) + 5 ) + 6 ) + 7 ) + 8 ) + 9 ) + 1 ) + 2 ) + 3 ) + 4 ) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.11: -------------------------------------------------------------------------------- 1 | +++++++++++1; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.11.check: -------------------------------------------------------------------------------- 1 | 25 states 11 scans 8 shifts 19 reductions 0 compares 0 ambiguities 2 | (( ++ ( ++ ( ++ ( ++ ( ++ ( + 1 )))))) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.12: -------------------------------------------------------------------------------- 1 | 1 * 2 + 3; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.12.check: -------------------------------------------------------------------------------- 1 | 32 states 12 scans 9 shifts 19 reductions 0 compares 0 ambiguities 2 | ((( 1 * 2 ) + 3 ) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.13: -------------------------------------------------------------------------------- 1 | if (x) if (y) z else q; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.13.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'y' line 1: not found 3 | ref Sym 'z' line 1: not found 4 | ref Sym 'q' line 1: not found 5 | 33 states 20 scans 12 shifts 18 reductions 1 compares 0 ambiguities 6 | (( if ( x ) ( if ( y ) z else q )) ; ) 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.14: -------------------------------------------------------------------------------- 1 | 1 + 2 + 3; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.14.check: -------------------------------------------------------------------------------- 1 | 32 states 12 scans 9 shifts 19 reductions 0 compares 0 ambiguities 2 | ((( 1 + 2 ) + 3 ) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.15: -------------------------------------------------------------------------------- 1 | 1 + 2 + 3 + 4; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.15.check: -------------------------------------------------------------------------------- 1 | 42 states 16 scans 13 shifts 25 reductions 0 compares 0 ambiguities 2 | (((( 1 + 2 ) + 3 ) + 4 ) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.16: -------------------------------------------------------------------------------- 1 | + + 1; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.16.check: -------------------------------------------------------------------------------- 1 | 17 states 7 scans 4 shifts 11 reductions 0 compares 0 ambiguities 2 | (( + ( + 1 )) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.17: -------------------------------------------------------------------------------- 1 | 1 2 + 3; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.17.check: -------------------------------------------------------------------------------- 1 | 28 states 11 scans 7 shifts 18 reductions 0 compares 0 ambiguities 2 | (( 1 ( 2 + 3 )) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.18: -------------------------------------------------------------------------------- 1 | do a while b; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.18.check: -------------------------------------------------------------------------------- 1 | ref Sym 'a' line 1: not found 2 | ref Sym 'b' line 1: not found 3 | 19 states 10 scans 6 shifts 9 reductions 0 compares 0 ambiguities 4 | (( do a while b ) ; ) 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.19: -------------------------------------------------------------------------------- 1 | for (x = 1; x < y; x++) h; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.19.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'x' line 1: not found 3 | ref Sym 'y' line 1: not found 4 | ref Sym 'x' line 1: not found 5 | ref Sym 'h' line 1: not found 6 | 66 states 33 scans 16 shifts 37 reductions 0 compares 0 ambiguities 7 | (( for ( ( x = 1 )( ; ( x < y )( ; ( x ++ ))) ) h ) ; ) 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.2: -------------------------------------------------------------------------------- 1 | 1 * 2 * 3; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.2.check: -------------------------------------------------------------------------------- 1 | 32 states 12 scans 9 shifts 19 reductions 0 compares 0 ambiguities 2 | ((( 1 * 2 ) * 3 ) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.20: -------------------------------------------------------------------------------- 1 | x ? y : z ? d : e; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.20.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'y' line 1: not found 3 | ref Sym 'z' line 1: not found 4 | ref Sym 'd' line 1: not found 5 | ref Sym 'e' line 1: not found 6 | 33 states 19 scans 11 shifts 18 reductions 0 compares 0 ambiguities 7 | (( x ? y : ( z ? d : e )) ; ) 8 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.21: -------------------------------------------------------------------------------- 1 | a = 1 + 2 + 3 + 4 + 5 + 6; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.21.check: -------------------------------------------------------------------------------- 1 | ref Sym 'a' line 1: not found 2 | 69 states 29 scans 24 shifts 46 reductions 0 compares 0 ambiguities 3 | (( a = ((((( 1 + 2 ) + 3 ) + 4 ) + 5 ) + 6 )) ; ) 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.23: -------------------------------------------------------------------------------- 1 | 1 + --a; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.23.check: -------------------------------------------------------------------------------- 1 | ref Sym 'a' line 1: not found 2 | 24 states 10 scans 6 shifts 14 reductions 0 compares 0 ambiguities 3 | (( 1 + ( -- a )) ; ) 4 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.24: -------------------------------------------------------------------------------- 1 | if (x) y + z * n else q + s * t; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.24.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'y' line 1: not found 3 | ref Sym 'z' line 1: not found 4 | ref Sym 'n' line 1: not found 5 | ref Sym 'q' line 1: not found 6 | ref Sym 's' line 1: not found 7 | ref Sym 't' line 1: not found 8 | 65 states 34 scans 26 shifts 38 reductions 0 compares 0 ambiguities 9 | (( if ( x ) ( y + ( z * n )) else ( q + ( s * t ))) ; ) 10 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.25: -------------------------------------------------------------------------------- 1 | if (x) y else z + 5; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.25.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'y' line 1: not found 3 | ref Sym 'z' line 1: not found 4 | 36 states 19 scans 12 shifts 19 reductions 0 compares 0 ambiguities 5 | (( if ( x ) y else ( z + 5 )) ; ) 6 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.26: -------------------------------------------------------------------------------- 1 | if (x) y else if (y) z else if (z) zz else zzz; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.26.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'y' line 1: not found 3 | ref Sym 'y' line 1: not found 4 | ref Sym 'z' line 1: not found 5 | ref Sym 'z' line 1: not found 6 | ref Sym 'zz' line 1: not found 7 | ref Sym 'zzz' line 1: not found 8 | 51 states 32 scans 20 shifts 26 reductions 0 compares 0 ambiguities 9 | (( if ( x ) y else ( if ( y ) z else ( if ( z ) zz else zzz ))) ; ) 10 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.27: -------------------------------------------------------------------------------- 1 | if (x) if (y) if (z) zz; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.27.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'y' line 1: not found 3 | ref Sym 'z' line 1: not found 4 | ref Sym 'zz' line 1: not found 5 | 33 states 20 scans 14 shifts 15 reductions 0 compares 0 ambiguities 6 | (( if ( x ) ( if ( y ) ( if ( z ) zz ))) ; ) 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.28: -------------------------------------------------------------------------------- 1 | if (x) y z else q; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.28.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'y' line 1: not found 3 | ref Sym 'z' line 1: not found 4 | ref Sym 'q' line 1: not found 5 | 31 states 18 scans 9 shifts 16 reductions 0 compares 0 ambiguities 6 | (( if ( x ) ( y z ) else q ) ; ) 7 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.29: -------------------------------------------------------------------------------- 1 | if (x) y z; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.29.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'y' line 1: not found 3 | ref Sym 'z' line 1: not found 4 | 25 states 14 scans 7 shifts 13 reductions 0 compares 0 ambiguities 5 | (( if ( x ) ( y z )) ; ) 6 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.3: -------------------------------------------------------------------------------- 1 | 1 * 2 + 3 * 4; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.3.check: -------------------------------------------------------------------------------- 1 | 42 states 16 scans 13 shifts 26 reductions 0 compares 0 ambiguities 2 | ((( 1 * 2 ) + ( 3 * 4 )) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.30: -------------------------------------------------------------------------------- 1 | 1 2 + 3 4 + 5 6 + 7 8 + 9 a + b; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.30.check: -------------------------------------------------------------------------------- 1 | ref Sym 'a' line 1: not found 2 | ref Sym 'b' line 1: not found 3 | 90 states 39 scans 27 shifts 60 reductions 0 compares 0 ambiguities 4 | (((((( 1 ( 2 + 3 ))( 4 + 5 ))( 6 + 7 ))( 8 + 9 ))( a + b )) ; ) 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.31: -------------------------------------------------------------------------------- 1 | 1 2 + 3 4 + 5 6 + 7; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.31.check: -------------------------------------------------------------------------------- 1 | 60 states 25 scans 17 shifts 40 reductions 0 compares 0 ambiguities 2 | (((( 1 ( 2 + 3 ))( 4 + 5 ))( 6 + 7 )) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.32: -------------------------------------------------------------------------------- 1 | 1 + 1.1 + 0.1 + -0.1 + -.1 + 1.0e10; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.32.check: -------------------------------------------------------------------------------- 1 | 62 states 24 scans 21 shifts 37 reductions 0 compares 0 ambiguities 2 | (((((( 1 + 1.1 ) + 0.1 ) + -0.1 ) + -.1 ) + 1.0e10 ) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.33: -------------------------------------------------------------------------------- 1 | for (x = 1) h; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.33.check: -------------------------------------------------------------------------------- 1 | ref Sym 'x' line 1: not found 2 | ref Sym 'h' line 1: not found 3 | 29 states 16 scans 8 shifts 14 reductions 0 compares 0 ambiguities 4 | (( for ( ( x = 1 ) ) h ) ; ) 5 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.4: -------------------------------------------------------------------------------- 1 | 1 2 + 3 * 4 5; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.4.check: -------------------------------------------------------------------------------- 1 | 44 states 18 scans 12 shifts 30 reductions 0 compares 0 ambiguities 2 | ((( 1 ( 2 + ( 3 * 4 ))) 5 ) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.5: -------------------------------------------------------------------------------- 1 | 1 2 + 3; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.5.check: -------------------------------------------------------------------------------- 1 | 28 states 11 scans 7 shifts 18 reductions 0 compares 0 ambiguities 2 | (( 1 ( 2 + 3 )) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.6: -------------------------------------------------------------------------------- 1 | 1 + 2; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.6.check: -------------------------------------------------------------------------------- 1 | 22 states 8 scans 5 shifts 13 reductions 0 compares 0 ambiguities 2 | (( 1 + 2 ) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.7: -------------------------------------------------------------------------------- 1 | 1 2 + 3; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.7.check: -------------------------------------------------------------------------------- 1 | 28 states 11 scans 7 shifts 18 reductions 0 compares 0 ambiguities 2 | (( 1 ( 2 + 3 )) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.8: -------------------------------------------------------------------------------- 1 | 1 + 2 + 3 + 4 + 5 + 6 + 7; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.8.check: -------------------------------------------------------------------------------- 1 | 72 states 28 scans 25 shifts 43 reductions 0 compares 0 ambiguities 2 | ((((((( 1 + 2 ) + 3 ) + 4 ) + 5 ) + 6 ) + 7 ) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.9: -------------------------------------------------------------------------------- 1 | 1 + 2 + 3 + 4 + 5 + 6; 2 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/tests/sample.test.g.9.check: -------------------------------------------------------------------------------- 1 | 62 states 24 scans 21 shifts 37 reductions 0 compares 0 ambiguities 2 | (((((( 1 + 2 ) + 3 ) + 4 ) + 5 ) + 6 ) ; ) 3 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/verilog/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile 3 | # 4 | # $Revision: 1.1 $ 5 | # 6 | 7 | DPARSERDIR= .. 8 | GRAMMAR= verilog.g 9 | DPARSEFLAGS= -l -v 10 | 11 | TARGET= v 12 | CSRCS= main.c vparse.c ambig.c 13 | OBJS= $(CSRCS:.c=.o) $(GRAMMAR).d_parser.o 14 | INCDIRSS= -I$(DPARSERDIR) 15 | CFLAGS= -g $(INCDIRSS) 16 | 17 | ######### 18 | 19 | target: $(TARGET) 20 | 21 | ########## 22 | 23 | $(TARGET): $(OBJS) 24 | $(CC) $(CFLAGS) -o $@ $(OBJS) \ 25 | -L$(DPARSERDIR) -ldparse 26 | 27 | $(GRAMMAR).d_parser.c: $(GRAMMAR) 28 | $(DPARSERDIR)/make_dparser $(DPARSEFLAGS) $(GRAMMAR) 29 | 30 | lint: 31 | lint $(CFLAGS) $(CSRCS) 32 | 33 | test: $(TARGET) 34 | ./verilog_tests 35 | grep succeeded log.txt | wc -l 36 | grep failed log.txt | wc -l 37 | 38 | clean: 39 | rm -f $(GRAMMAR).d_parser.c $(TARGET) $(OBJS) log.txt 40 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/verilog/README: -------------------------------------------------------------------------------- 1 | 2 | This Verilog grammar was contributed by Thomas Skibo (thanx!). 3 | 4 | To make, type 'make'. 5 | 6 | To test, get the test suite from ftp://icarus.com/pub/eda/verilog/tests 7 | 8 | and untar into this directory, then type 'make test'. 9 | 10 | The result should be: 11 | 12 | ./verilog_tests 13 | grep succeeded log.txt | wc -l 14 | 383 15 | grep failed log.txt | wc -l 16 | 8 17 | 18 | The failures represent unsupported features: 19 | 20 | testsuite/ivltests/always3.1.1K.v failed 21 | testsuite/ivltests/function3.11E.v failed 22 | testsuite/ivltests/signed1.v failed 23 | testsuite/ivltests/signed2.v failed 24 | testsuite/ivltests/signed3.v failed 25 | testsuite/ivltests/signed4.v failed 26 | testsuite/ivltests/wildsense.v failed 27 | testsuite/ivltests/specify_01.v failed 28 | 29 | see log.txt for details. 30 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/verilog/ambig.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * ambig.c 4 | * 5 | * $Revision: 1.1 $ 6 | */ 7 | 8 | #include "d.h" 9 | #undef DPN_TO_PN 10 | #define DPN_TO_PN(_dpn) \ 11 | ((PNode *)(((char*)(_dpn))-(int)(&((PNode*)0)->parse_node))) 12 | 13 | extern void print_paren(PNode *); 14 | 15 | struct D_ParseNode * 16 | my_ambiguity_fn(struct D_Parser *pp, int n, struct D_ParseNode **v ) 17 | { 18 | int i; 19 | char *s; 20 | printf( "my_ambiguity_fn: %d possibilities:\n", n ); 21 | 22 | s = v[0]->start_loc.s; 23 | while (s != v[0]->end) 24 | putchar( s[0] ), s++; 25 | 26 | for (i=0; i! log.txt 5 | 6 | foreach file ( `find testsuite -name '*.v' -print` ) 7 | echo =================== $file ================ >> log.txt 8 | ./v $file >>& log.txt 9 | end 10 | 11 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/verilog/vparse.h: -------------------------------------------------------------------------------- 1 | /* vparse.h 2 | * 3 | * Utilities used during parsing Verilog files. 4 | * 5 | */ 6 | 7 | extern int v_iskeyword( const char *, const char * ); 8 | extern void v_parse_init( void ); 9 | extern int v_getfile( const char *, char **, int * ); 10 | 11 | extern char *v_incdirs; 12 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2002-2004 John Plevyak, All Rights Reserved 3 | */ 4 | #include "d.h" 5 | 6 | void 7 | d_version(char *v) { 8 | v += sprintf(v, "%d.%d", D_MAJOR_VERSION, D_MINOR_VERSION); 9 | if (D_BUILD_VERSION) 10 | v += sprintf(v, ".%d", D_BUILD_VERSION); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /Dependencies/d-1.15-patched/write_tables.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2002-2004 John Plevyak, All Rights Reserved 3 | */ 4 | 5 | int write_c_tables(Grammar *g); 6 | int write_binary_tables(Grammar *g); 7 | int write_binary_tables_to_file(Grammar *g, FILE *fp); 8 | int write_binary_tables_to_string(Grammar *g, 9 | unsigned char **str, unsigned int *str_len); 10 | -------------------------------------------------------------------------------- /Dependencies/make-dparser.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # NOTE: This script must be run from the Sugar/Dependencies directory 3 | DPARSER=d-1.15-patched 4 | if [ $PYTHONPATH ]; then 5 | PPATH=$PYTHONPATH 6 | else 7 | PPATH=`python2.7 -c "import sys;print ':'.join(filter(lambda x:x and x.find('.egg') == -1,sys.path))"` 8 | fi 9 | 10 | mkdir dparser 11 | pushd $DPARSER 12 | make 13 | cd python 14 | python setup.py build 15 | cp `find build -name "dparser.py"` ../../dparser 16 | cp `find build -name "dparser_swigc.so"` ../../dparser 17 | popd 18 | # FIXME: In some cases, there is no PYTHONPATH 19 | echo =========================================================== 20 | echo NOTE: Please copy 'dparser/*' to one of this location 21 | echo =========================================================== 22 | echo $PPATH | sed 's|:|\n|g' | sort 23 | echo =========================================================== 24 | echo For example: 25 | echo $ cp 'dparser/*' `echo $PPATH|cut -d':' -f1` 26 | echo =========================================================== 27 | # EOF 28 | -------------------------------------------------------------------------------- /Documentation/sugar-quickref.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebastien/sugar/4b00379b15023529c81ba0459f3e0d09e340b7f2/Documentation/sugar-quickref.pdf -------------------------------------------------------------------------------- /Scripts/sugar: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import sys, sugar.main 3 | print sugar.main.run(sys.argv[1:]) 4 | -------------------------------------------------------------------------------- /Sources/sugar/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebastien/sugar/4b00379b15023529c81ba0459f3e0d09e340b7f2/Sources/sugar/__init__.py -------------------------------------------------------------------------------- /Tests/Makefile: -------------------------------------------------------------------------------- 1 | # Sugar test makefile (02-Oct-2007) 2 | TEST_DIR=tests 3 | SOURCE_SG=$(filter-out bug-%,$(filter-out todo-%,$(wildcard *.sg))) 4 | PRODUCT_JS=$(SOURCE_SG:%.sg=$(TEST_DIR)/js/%.js) 5 | PRODUCT_AS=$(SOURCE_SG:%.sg=$(TEST_DIR)/as/%.as) 6 | PRODUCT_PY=$(SOURCE_SG:%.sg=$(TEST_DIR)/py/%.py) 7 | PRODUCT_PNUTS=$(SOURCE_SG:%.sg=$(TEST_DIR)/pnuts/%.pnuts) 8 | SUGAR=sugar 9 | 10 | .PHONY: all clean 11 | 12 | all: $(PRODUCT_JS) $(PRODUCT_AS) $(PRODUCT_PY) $(PRODUCT_PNUTS) 13 | 14 | clean: 15 | rm -rf $(TEST_DIR) 16 | 17 | $(TEST_DIR)/js/%.js: %.sg $(TEST_DIR)/js 18 | $(SUGAR) -cljavascript $< > $@ 19 | 20 | $(TEST_DIR)/as/%.as: %.sg $(TEST_DIR)/as 21 | $(SUGAR) -clactionscript $< > $@ 22 | 23 | $(TEST_DIR)/py/%.py: %.sg $(TEST_DIR)/py 24 | $(SUGAR) -clpython $< > $@ 25 | 26 | $(TEST_DIR)/pnuts/%.pnuts: %.sg $(TEST_DIR)/pnuts 27 | $(SUGAR) -clpnuts $< > $@ 28 | 29 | $(TEST_DIR)/pnuts: 30 | mkdir -p $@ 31 | 32 | $(TEST_DIR)/js: 33 | mkdir -p $@ 34 | 35 | $(TEST_DIR)/as: 36 | mkdir -p $@ 37 | 38 | $(TEST_DIR)/py: 39 | mkdir -p $@ 40 | 41 | # EOF 42 | -------------------------------------------------------------------------------- /Tests/TestSugar.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from glob import glob 3 | from sugar import main as sugar 4 | for p in glob("*.s*"): 5 | print sugar.run(["-cljs", "-t",p]) 6 | # EOF 7 | -------------------------------------------------------------------------------- /Tests/app-helloworld-class.sg: -------------------------------------------------------------------------------- 1 | @class Hello 2 | @property world="world" 3 | @method hello 4 | print ("Hello,", world, "!") 5 | @end 6 | @end 7 | 8 | @main 9 | (new Hello()) hello() 10 | @end 11 | -------------------------------------------------------------------------------- /Tests/app-helloworld.sg: -------------------------------------------------------------------------------- 1 | @main 2 | print "Hello, World !" 3 | @end 4 | -------------------------------------------------------------------------------- /Tests/bug-ambiguity.sg: -------------------------------------------------------------------------------- 1 | var a = 1 2 | var b = 1 3 | a() b 4 | a() (b) 5 | a() [0] 6 | 7 | -------------------------------------------------------------------------------- /Tests/bug-arguments-optional.sg: -------------------------------------------------------------------------------- 1 | @class A 2 | @method ignore elements... 3 | return wrappedElement ignore (...elements) 4 | @end 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/bug-assignations-multiple.as: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sebastien/sugar/4b00379b15023529c81ba0459f3e0d09e340b7f2/Tests/bug-assignations-multiple.as -------------------------------------------------------------------------------- /Tests/bug-assignations-multiple.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: This will call f multiple times, instead of storing this in an 2 | # intermediate result 3 | var a,b,c,d = f() 4 | -------------------------------------------------------------------------------- /Tests/bug-assignment-in-expression.sjs: -------------------------------------------------------------------------------- 1 | @function f a 2 | return (a += 1) 3 | @end 4 | -------------------------------------------------------------------------------- /Tests/bug-assignment-index.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: This fails with the following error 2 | # File "/Users/sebastien/Local/Python/lambdafactory/model.py", line 702, in copy 3 | # op_copy.addOpArgument(a.copy().detach()) 4 | # File "/Users/sebastien/Local/Python/lambdafactory/model.py", line 923, in copy 5 | # value_copy=Value._copy(self) 6 | # File "/Users/sebastien/Local/Python/lambdafactory/model.py", line 381, in _copy 7 | # copy = self.__class__(*arguments) 8 | #TypeError: __init__() takes exactly 2 arguments (1 given) 9 | # DATE: 13-Feb-2008 10 | 11 | new_cells[-1] += "%" 12 | new_cells[-1] += "." 13 | new_cells[-1] += c 14 | 15 | # EOF 16 | -------------------------------------------------------------------------------- /Tests/bug-for-reverseloops.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: JavaScript and ActionScript backend got the order of the iteration 2 | # wrong at some point if we had -X...Y 3 | for i in 0..1 4 | print ("1:", i) 5 | end 6 | 7 | for i in 0..0 8 | print ("2:", i) 9 | end 10 | 11 | for i in -1..0 12 | print ("3:", i) 13 | end 14 | 15 | for i in -1..-1 16 | print ("4:", i) 17 | end 18 | 19 | for i in 10..-10 20 | print ("5:", i) 21 | end 22 | 23 | for i in -10..10 24 | print ("6:", i) 25 | end 26 | 27 | # EOF 28 | -------------------------------------------------------------------------------- /Tests/bug-function-anonymous.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: {|} is not recognized as an anonymous function declaration 2 | # DATE: 28-Jan-2008 3 | @function f 4 | return {|} 5 | @end 6 | # EOF 7 | -------------------------------------------------------------------------------- /Tests/bug-if-oneliner.sg: -------------------------------------------------------------------------------- 1 | # DESC: The conditionals get represented as two ifs... 2 | # DATE: 22-Jan-2008 3 | if isExpanded -> contract () 4 | else -> expand () 5 | # EOF 6 | -------------------------------------------------------------------------------- /Tests/bug-invocation-escaperef.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: 2 | # syntax error, line:18 3 | # ...tingPanel .nestedbox") 4 | # [syntax error]$ "#TestArea .box" hover ... 5 | # DATE: 08-Feb-2008 6 | $(document) ready { 7 | testing HTMLReporter Install () 8 | var floating_panel = $(".FloatingPanel") 9 | var markers = placement mark ' $(".FloatingPanel .nestedbox") 10 | $ "#TestArea .box" hover () 11 | } 12 | $(document) ready { 13 | testing HTMLReporter Install () 14 | var floating_panel = $(".FloatingPanel") 15 | # NOTE: Removing the empty line after does not cause any problem 16 | var markers = placement mark ' $(".FloatingPanel .nestedbox") 17 | 18 | $ "#TestArea .box" hover () 19 | } 20 | # EOF 21 | -------------------------------------------------------------------------------- /Tests/bug-iteration-return.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: In the JavaScript backend, the 'return True' does not exit the 2 | # function, but only returns from the closure... which is kind of normal, but we 3 | # need to properly define this edge case. 4 | @function f 5 | 0..10 :: {i| 6 | if i == 9 7 | return True 8 | end 9 | } 10 | return False 11 | @end 12 | -------------------------------------------------------------------------------- /Tests/bug-oop-default-properties.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: The default value for 'a' in B is the 1, should be 2 (especially in 2 | # Python BE). 3 | @class A 4 | @property a = 1 5 | @constructor 6 | print ("A:" + a) 7 | @end 8 | @end 9 | @class B:A 10 | @property a = 2 11 | @end 12 | 13 | @main 14 | var a = new A() 15 | var b = new B() 16 | @end 17 | -------------------------------------------------------------------------------- /Tests/bug-oop-shared-properties.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: If a property default value is a reference to a shared value, 2 | # there is a failure at definition (in JavaScript) 3 | # DATE: 01-Feb-2008 4 | 5 | @class A 6 | @shared P 7 | @property p = P 8 | @end 9 | 10 | # EOF 11 | -------------------------------------------------------------------------------- /Tests/bug-operation-constructor-chain.sg: -------------------------------------------------------------------------------- 1 | # BUG: this outputs 'new Visualization('#radial')(add)(1, 2)' 2 | # instead of 'new Visualization('#radial').add(1, 2)' 3 | new Visualization "#radial" add () 4 | -------------------------------------------------------------------------------- /Tests/bug-operator-precedence.sg: -------------------------------------------------------------------------------- 1 | var a 2 | var b 3 | var c 4 | 5 | if a > b and a < b + c 6 | return false 7 | end 8 | var d = a and not b 9 | var d = not a and b 10 | var d = not a or b != c 11 | -------------------------------------------------------------------------------- /Tests/bug-parens.sg: -------------------------------------------------------------------------------- 1 | @class Templates 2 | 3 | @operation createCitation cit 4 | var tags_html = html div({_:'tags'} 5 | 'tagged as ' 6 | html ul() 7 | ) 8 | var cit_html = html div ({_:'citation'} 9 | html div({_:'text'}, cit getText()) 10 | html div({_:'about'}, 'appears in', '(', ', ', ')') 11 | ) 12 | return cit_html 13 | @end 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Tests/bug-python-variable.sg: -------------------------------------------------------------------------------- 1 | @function f 2 | # PROBLEM: This will be converted to 3 | # r 4 | # instead of 5 | # r = None 6 | var r 7 | @end 8 | -------------------------------------------------------------------------------- /Tests/bug-resolution-20160411.sjs: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: In this non-functional example copied and trimmed from 2 | # the `physics` module, `False` is not resolved 3 | # to its `false` JS equivalent. 4 | # REVISION: 48b999b020ac86d62fcdb729f1bd503b079b48e4 5 | # DATE: 2016-04-11 6 | @class A 7 | 8 | @property p1 = False 9 | @property p2:Boolean = True 10 | 11 | @method f a 12 | if a is Undefined 13 | return True 14 | else 15 | return False 16 | end 17 | @end 18 | 19 | @end 20 | # EOF 21 | -------------------------------------------------------------------------------- /Tests/bug-resolution-class_instead_of_local_scope.sg: -------------------------------------------------------------------------------- 1 | # BUG: Class scope is taken instead of closure arguments scope 2 | # DATE: 31-Jul-2008 3 | @class PresenceController 4 | 5 | @property channel 6 | @property visitors = {} 7 | @property observers = [] 8 | 9 | @constructor 10 | channel = new channels AsyncChannel () 11 | refresh () 12 | update () 13 | @end 14 | 15 | @method refresh 16 | var f = channel get ( 17 | "/api/visitor/all/" + (new Date() getTime()) 18 | ) onSucceed {visitors| 19 | observers :: {o| 20 | # FIXME: Will be converted to 21 | # o.setAllVisitors(__this__.visitors) 22 | # instead of 23 | # o.setAllVisitors(visitors) 24 | o setAllVisitors (visitors) 25 | } 26 | } 27 | @end 28 | @end 29 | -------------------------------------------------------------------------------- /Tests/bug-resolution-closure-20160412.sjs: -------------------------------------------------------------------------------- 1 | @class A 2 | 3 | @property p 4 | 5 | @method m a, b 6 | return {p,a,b| 7 | p = a + b 8 | } 9 | @end 10 | 11 | @method n a, b 12 | return {pp,aa,bb| 13 | p = a + b 14 | } 15 | @end 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Tests/bug-resolution-if.sg: -------------------------------------------------------------------------------- 1 | @class Context 2 | 3 | @property text:String 4 | @property textLength: 5 | @property offset: = 0 6 | 7 | @constructor text, offset=0 8 | if text 9 | setText(text, offset) 10 | end 11 | @end 12 | 13 | @method setText text, offset=0 14 | self text = text 15 | self offset = offset 16 | textLength = len(text) 17 | @end 18 | 19 | # FIXME: Don't know if this should be in context 20 | @method skip expression 21 | | Skips the characters matching the given expression (if any), starting from 22 | | the current offset. 23 | if expression 24 | var match = expression match (text, offset) 25 | print ("MATCH", match) 26 | # PROBLEM: match is resolved as a method, while it should be 27 | # resolved as a variable in the if. 28 | if match 29 | offset = match end() 30 | end 31 | end 32 | @end 33 | 34 | @method match expression 35 | # TODO: Add skip ignored characters 36 | return expression match (text, offset) 37 | @end 38 | 39 | @method search expression 40 | return expression search (text, offset) 41 | @end 42 | 43 | @end 44 | 45 | 46 | -------------------------------------------------------------------------------- /Tests/bug-resolution-inherited_shared.sjs: -------------------------------------------------------------------------------- 1 | @class M 2 | @shared S="From M" 3 | @constructor 4 | print (S) 5 | @end 6 | @end 7 | 8 | @class A:M 9 | @shared S="From A" 10 | @end 11 | 12 | @class B:A 13 | @shared S="From B" 14 | @end 15 | 16 | new M() 17 | new A() 18 | new B() 19 | -------------------------------------------------------------------------------- /Tests/bug-resolver-for.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: Iterations do not seem to define the slots in the dataflow properly 2 | 3 | # This works (I don't get why) 4 | for v,i in [10,11,12,13,14] 5 | print ("v:", v, "i:", i) 6 | end 7 | 8 | # This does not work (says that j is undefined) 9 | for j in 0..10 10 | print ("1:", j) 11 | end 12 | 13 | # EOF 14 | -------------------------------------------------------------------------------- /Tests/bug-runtime-arguments.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: The arguments... does not work for JS backend when 'arguments' is 2 | # used 3 | # DATE: 04-Feb-2008 4 | @function i, arguments... 5 | print (arguments) 6 | @end 7 | # EOF 8 | -------------------------------------------------------------------------------- /Tests/bug-runtime-map-keys.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: Cannot use expressions as keys in dictinoary declaration in 2 | # JavaScript backend. 3 | # DATE: 01-Feb-2008 4 | var d = "pouet" 5 | var m = {(d):"key should be 'pouet'"} 6 | var n = {("pouet"):"key should be 'pouet'"} 7 | var o = {pouet:"key should be 'pouet'"} 8 | # EOF 9 | -------------------------------------------------------------------------------- /Tests/bug-runtime-operation-self.sg: -------------------------------------------------------------------------------- 1 | # DATE: 27-Feb-2008 2 | @class Editor 3 | 4 | @shared INSTANCE 5 | 6 | @property ui 7 | @property editedPastie 8 | @property editedPastieBox 9 | 10 | @operation GetInstance 11 | # NOTE: The problem is that at this point the 'this' 12 | # is not the class 13 | print ("THIS IS ", self) 14 | console log (self) 15 | if self INSTANCE is Undefined -> INSTANCE = new self() 16 | return self INSTANCE 17 | @end 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Tests/bug-scoping-2.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: SNIP should not be resolved to the local snip at that point 2 | @shared SNIP 3 | @class AbstractWriter: Pass 4 | @shared SNIP = SNIP 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/bug-scoping-loop.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: When iterations (for..in) are used, if the body is wrapped in a 2 | # closure, we must ensure that assignation will actually mutate the enclosing 3 | # slot, while this should not be the case with closures. 4 | @function f 5 | var a = 1 6 | var b = 2 7 | var ra = a 8 | var rb = b 9 | for i in 0..(a * 10) 10 | for j in 0..(b * 10) 11 | ra = i 12 | rb = j 13 | end 14 | end 15 | print ("Expects: ra:9 rb:19") 16 | print ("ra:", ra) 17 | print ("rb:", rb) 18 | @end 19 | @function g 20 | var a = 1 21 | var b = 2 22 | var ra = a 23 | var rb = b 24 | for i in 0..(a * 10) 25 | for j in 0..(b * 10) 26 | f = { 27 | ra = i 28 | rb = j 29 | } 30 | f() 31 | end 32 | end 33 | print ("Expects: ra:1 rb:1") 34 | print ("ra:", ra) 35 | print ("rb:", rb) 36 | @end 37 | f() 38 | g() 39 | -------------------------------------------------------------------------------- /Tests/bug-scoping.sg: -------------------------------------------------------------------------------- 1 | @function f 2 | # PROBLEM: v should be undefined (but no error is reported) 3 | var v = v + 1 4 | # PROBLEM: y should be undefined (but no error is reported) 5 | var x = y + 10 6 | var y = 1 7 | @end 8 | # EOF 9 | -------------------------------------------------------------------------------- /Tests/bug-slicing.sg: -------------------------------------------------------------------------------- 1 | var name = (new RegExp("in\\-\\w+")) exec ( input attr "class" ) [3:] 2 | -------------------------------------------------------------------------------- /Tests/bug-statement.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: The statements after the ';' are not displayed 2 | @function a 3 | return 1 4 | @end 5 | 6 | @function b 7 | return 2 8 | @end 9 | 10 | @main 11 | a() ; b() ; a() ; b() 12 | @end 13 | -------------------------------------------------------------------------------- /Tests/bug-syntax-break.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: breaking loops 2 | # SYNTAX: break keyword, or closure returning False if applied to iterator 3 | @module BreakTest 4 | 5 | @function f1 6 | var i = 0 7 | while True 8 | i += 1 9 | if i == 10 -> break 10 | end 11 | @end 12 | 13 | @function f2 14 | for i in 0..20 15 | if i == 10 -> break 16 | end 17 | @end 18 | 19 | @function f3 20 | 0..20 :: {j| 21 | i = j 22 | if i == 10 -> return False 23 | } 24 | @end 25 | 26 | # EOF 27 | -------------------------------------------------------------------------------- /Tests/fixedbug-access.sg: -------------------------------------------------------------------------------- 1 | @main 2 | var doc = $("#wikiPage")[0] contentWindow document 3 | var city = Cells input("city") 4 | @end 5 | -------------------------------------------------------------------------------- /Tests/fixedbug-arguments.sg: -------------------------------------------------------------------------------- 1 | @class A 2 | @property a = 1 3 | @property b = 2 4 | @constructor a, b 5 | a = a + 1 6 | self a = a 7 | self b = b 8 | @end 9 | @end 10 | -------------------------------------------------------------------------------- /Tests/fixedbug-attribute-class-name.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: In JavaScript, this resulted in 2 | # // 8< ---[cells.js]--- 3 | # var cells={} 4 | # cells.A=Extend.Class({ 5 | # name:'cells.A', parent:undefined, 6 | # shared:{ 7 | # Pouet:0 8 | # } 9 | # }) 10 | # cells.B=Extend.Class({ 11 | # name:'cells.Pouet', parent:cells.A, 12 | # shared:{ 13 | # Pouet:0 14 | # } 15 | # }) 16 | # cells.init= function(){ 17 | # var __this__=cells; 18 | # } 19 | # cells.init() 20 | # // -- 21 | # DATE: 2007-10-24 22 | @class A 23 | @shared Pouet:Number = 0 24 | @end 25 | @class B: A 26 | @end 27 | 28 | 29 | -------------------------------------------------------------------------------- /Tests/fixedbug-embed-indent.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: Indentation is absorbed in embedded code 2 | @function f 3 | while True 4 | @embed JavaScript 5 | |if ( declaration.operations != undefined ) { 6 | | for ( var name in declaration.operations ) { 7 | | class_object[name] = declaration.operations[name] 8 | |}} 9 | | 10 | |if ( declaration.attributes != undefined ) { 11 | | for ( var name in declaration.attributes ) { 12 | | class_object[name] = declaration.attributes[name] 13 | |}} 14 | @end 15 | end 16 | @end 17 | -------------------------------------------------------------------------------- /Tests/fixedbug-embed-multiple.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: the first @end and the second @embed are not recognized, and are 2 | # directly embedded 3 | # DATE : 20-Jun-2007 4 | @function create declaration 5 | 6 | @embed JavaScript 7 | |class_object._init = declaration.init 8 | @end 9 | 10 | {name| 11 | var parent_proto = declaration parent prototype 12 | return {parent_proto[name] apply (target, arguments)} 13 | } 14 | 15 | @embed JavaScript 16 | |instance_proto.init = declaration.init 17 | @end 18 | 19 | @end 20 | # EOF 21 | -------------------------------------------------------------------------------- /Tests/fixedbug-for.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: The for...in is written as 2 | # (for.cell in __this__.cells) 3 | # if ( (c.id == cell.id) ) 4 | # { 5 | # return true 6 | # } 7 | @function cellInQueue cell 8 | | Tells if the given cell is in the waiting queue for this stream 9 | for cell in cells 10 | if (c id == cell id) -> return True 11 | end 12 | for cell in syncCells 13 | if (c id == cell id) -> return True 14 | end 15 | return False 16 | @end 17 | -------------------------------------------------------------------------------- /Tests/fixedbug-if-1.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: That was causing an exception 2 | # File "/Users/sebastien/Local/Python/lambdafactory/javascript.py", line 489, in writeSelection 3 | # assert isinstance(rule, interfaces.IMatchProcessOperation) 4 | @class Application 5 | @operation searchContent criteria 6 | if criteria is Undefined -> criteria = $ "#searchBox" val() 7 | if matching_pages length > 0 8 | print "POUET" 9 | end 10 | @end 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /Tests/fixedbug-if-3.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: 'if targetAnchor' was printed as 'if.targetAnchor' in JavaScript 2 | # TEST EMPTY sugar -ljs $FILE | grep 'if.targetAnchor' 3 | @class bozo 4 | @method bozozo targetAnchor 5 | if targetAnchor == "E" 6 | if True -> return false 7 | if targetAnchor == "W" or targetAnchor == "NW" or targetAnchor == "N" 8 | return False 9 | end 10 | 11 | return true 12 | @end 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/fixedbug-if-assignment.sg: -------------------------------------------------------------------------------- 1 | # DATE: 09-Feb-2008 2 | # This was compiled to JavaScript as 3 | # 4 | # if ( states ) 5 | # {__this__.statePredicates} = states; 6 | # if ( triggerOperation ) 7 | # {__this__.triggerCallback} = triggerOperation; 8 | 9 | if states -> statePredicates = states 10 | if triggerOperation -> triggerCallback = triggerOperation 11 | if triggerOperation -> triggerCallback = triggerOperation + 1; pouet = 1 12 | if triggerOperation -> triggerCallback = triggerOperation + 1; pouet = 1 ; kapouet = 2 13 | -------------------------------------------------------------------------------- /Tests/fixedbug-if.sg: -------------------------------------------------------------------------------- 1 | @main 2 | # BUG: This should be allowed 3 | pouet \if "asdaas" 4 | @end 5 | -------------------------------------------------------------------------------- /Tests/fixedbug-in.sg: -------------------------------------------------------------------------------- 1 | print ("POUET" + e inPlaceEditor) 2 | # Fails because the 'in' of 'inPlaceEditor' is recognized as an operator. 3 | # Starngely, the following works 4 | print ("POUET" + (e inPlaceEditor)) 5 | print ("POUET" + e andPlaceEditor) 6 | print ("POUET" + e orPlaceEditor) 7 | -------------------------------------------------------------------------------- /Tests/fixedbug-in2.sg: -------------------------------------------------------------------------------- 1 | 2 | # BUG: It seems like 'innerHTML' is parsed as 'in nerHTML' 3 | @function getPageContent 4 | var iframe = $("#editableArea")[0] 5 | var content = Undefined 6 | if (jQuery browser msie) 7 | # PROBLEM 8 | content = iframe contentWindow document body innerHTML 9 | # SOLUTION 10 | #content = (iframe contentWindow document body innerHTML) 11 | else 12 | # PROBLEM 13 | content = iframe contentWindow body innerHTML 14 | # SOLUTION 15 | #content = (iframe contentWindow body innerHTML) 16 | end 17 | return content 18 | @end 19 | -------------------------------------------------------------------------------- /Tests/fixedbug-new.sg: -------------------------------------------------------------------------------- 1 | @class A 2 | @method newFile 3 | @end 4 | @method fromStream stream, addEOL=False 5 | newFile(path) 6 | @end 7 | @end 8 | 9 | var a = A() 10 | a fromStream() 11 | -------------------------------------------------------------------------------- /Tests/fixedbug-operators-varnames.sg: -------------------------------------------------------------------------------- 1 | @function canEdit 2 | return isEditable and Application inEditMode() and isEdited is False and isThereAnEditedElement is False 3 | @end 4 | -------------------------------------------------------------------------------- /Tests/fixedbug-resolution-invocation.sg: -------------------------------------------------------------------------------- 1 | # DATE: 20-Feb-2008 2 | # DESCRIPTION: 3 | # bugresolutioninvocation.foo().bugresolutioninvocation.foo() 4 | # o.bugresolutioninvocation.foo().bugresolutioninvocation.foo().bugresolutioninvocation.foo() 5 | @function foo 6 | @end 7 | foo () foo () 8 | o foo () foo () foo () 9 | # EOF 10 | -------------------------------------------------------------------------------- /Tests/fixedbug-scope-field_in_method.sjs: -------------------------------------------------------------------------------- 1 | @class A 2 | @property a = 1 3 | @constructor 4 | @end 5 | @end 6 | @class B: A 7 | @method getA 8 | return a 9 | @end 10 | @end 11 | -------------------------------------------------------------------------------- /Tests/fixedbug-statement-singleline.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: The rest of a ';' joined statement list is swallowed 2 | # DATE: 10-Feb-2008 3 | var a = 1 4 | var a = 1 ; a = 2 5 | var a = 1 ; a = 2 ; var c 6 | -------------------------------------------------------------------------------- /Tests/fixedbug-string-escape.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: Parens are eaten 2 | # DATE: 05-Mar-2008 3 | print ("\"" + 'a' + "\"") 4 | print ("\\" + 'a' + "\\") 5 | # Gets translated (JS) to 6 | # var model=eval((("(" + eval((("\\"" + str_model) + "\\""))) + ") 7 | # EOF 8 | -------------------------------------------------------------------------------- /Tests/fixedbug-types-translation.sg: -------------------------------------------------------------------------------- 1 | @function f 2 | var triggered = [] 3 | # PROBLEM: The following line is translated in JS to 4 | # if ( (triggered.find(1) == -1) ) 5 | # while find should be rewritten, as specified in the DataTypes.sg module. 6 | # this means that the invocation in the if is not linked properly to the 7 | # triggered slot defined above. 8 | if triggered find (1) == -1 9 | print "OK" 10 | end 11 | @end 12 | -------------------------------------------------------------------------------- /Tests/fixedbug-while-scope.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: The 'cell' function overrides the 'cell' variable defined locally 2 | # in the 'while' look of the 'continue' method 3 | @module Cells 4 | @class Stream 5 | 6 | @method continue 7 | | Continues the execution of the stream, until the list of cells 8 | | is empty. 9 | # We could do self :: {v|...} 10 | while hasNext() 11 | var v = next() 12 | var cell = v[0] 13 | # We take the 'triggerLimit' into account to absorb 14 | # the effect of feedback loops. 15 | if cellsCount[cell id] is Undefined 16 | cell trigger (v[1], v[2]) 17 | cellsCount[cell id] = 1 18 | if cellsCount[cell id] < cell triggerLimit 19 | cell trigger (v[1], v[2]) 20 | cellsCount[cell id] += 1 21 | end 22 | end 23 | @end 24 | @end 25 | 26 | @function cell name, states 27 | return new Cell(name, states) 28 | @end 29 | 30 | 31 | # EOF 32 | 33 | -------------------------------------------------------------------------------- /Tests/js-java-frame.sg: -------------------------------------------------------------------------------- 1 | @shared Frame 2 | @shared Button 3 | 4 | @class Window 5 | @property awtUI 6 | @constructor title 7 | awtUI = new Frame(title) 8 | awtUI add (new Button "Hello, Sugar ;)") 9 | awtUI setSize (300,200) 10 | awtUI setVisible (True) 11 | @end 12 | @end 13 | 14 | @function initialize 15 | Frame = Packages java awt Frame 16 | Button = Packages java awt Button 17 | new Window() 18 | @end 19 | 20 | initialize() 21 | 22 | # EOF 23 | -------------------------------------------------------------------------------- /Tests/oop-abstract.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Astract contstructs (1.0) 2 | # SYNTAX: Prefix function/class/method/operation with @abstract, and remove 3 | # body. 4 | 5 | @abstract @function f 6 | | Lorem ipsum dolor sit amet 7 | 8 | @abstract @function g a, b 9 | | Lorem ipsum dolor sit amet 10 | 11 | @abstract @class A 12 | 13 | @abstract @method m1 14 | | Lorem ipsum dolor sit amet 15 | 16 | @abstract @method m2 a, b 17 | | Lorem ipsum dolor sit amet 18 | 19 | @abstract @method m3:any a, b 20 | | Lorem ipsum dolor sit amet 21 | 22 | @abstract @method m4:any a:any, b 23 | | Lorem ipsum dolor sit amet 24 | 25 | @abstract @method m5:any a:any, b:any 26 | | Lorem ipsum dolor sit amet 27 | 28 | @abstract @operation o1 29 | | Lorem ipsum dolor sit amet 30 | 31 | @abstract @operation o2 a, b 32 | | Lorem ipsum dolor sit amet 33 | 34 | @end 35 | 36 | @protocol A 37 | 38 | @abstract @method m1 39 | | Lorem ipsum dolor sit amet 40 | 41 | @abstract @method m2 a, b 42 | | Lorem ipsum dolor sit amet 43 | 44 | @abstract @method m3:any a, b 45 | | Lorem ipsum dolor sit amet 46 | 47 | @abstract @method m4:any a:any, b 48 | | Lorem ipsum dolor sit amet 49 | 50 | @abstract @method m5:any a:any, b:any 51 | | Lorem ipsum dolor sit amet 52 | 53 | @abstract @operation o1 54 | | Lorem ipsum dolor sit amet 55 | 56 | @abstract @operation o2 a, b 57 | | Lorem ipsum dolor sit amet 58 | 59 | @end 60 | 61 | # EOF 62 | -------------------------------------------------------------------------------- /Tests/oop-callbacks.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Test the giving of callbacks as parameters 2 | # PROBLEM: Unless typing is implemented stuff like 'a doThis' won't use 3 | # getMethod 4 | @class A 5 | 6 | @operation DoThis 7 | @end 8 | 9 | @method doThis 10 | @end 11 | 12 | @method setCallback a 13 | a giveCallback (doThis) 14 | a giveCallback (DoThis) 15 | @end 16 | @end 17 | 18 | var a = new A() 19 | var b = new Object() 20 | b setCallback (A DoThis) 21 | b setCallback (a doThis) 22 | # EOF 23 | -------------------------------------------------------------------------------- /Tests/oop-class-classattributes.sg: -------------------------------------------------------------------------------- 1 | @class A 2 | @shared a 3 | @shared b = 1 4 | @shared c = [1,2,3] 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/oop-class.sg: -------------------------------------------------------------------------------- 1 | @class Point 2 | 3 | @property x:double 4 | @property y:double 5 | 6 | @constructor px, py 7 | x = px 8 | y = py 9 | @end 10 | 11 | @end 12 | 13 | @class Shape 14 | 15 | @shared COUNT:int 16 | @property points:List 17 | 18 | @constructor 19 | points = [] 20 | @end 21 | 22 | @method addPoint point:Point 23 | return points append(point) 24 | @end 25 | 26 | @method addAnotherPoint point:Point 27 | return addPoint(point) 28 | @end 29 | 30 | @operation shapeCount 31 | return COUNT 32 | @end 33 | 34 | @operation otherShapeCount 35 | return shapeCount() 36 | @end 37 | 38 | 39 | @end 40 | 41 | @class RectangleShape: Shape 42 | 43 | @constructor 44 | super () 45 | @end 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Tests/oop-constructor.sg: -------------------------------------------------------------------------------- 1 | @class A 2 | @property a 3 | @property b 4 | @constructor pa, pb 5 | a = pa 6 | b = pb 7 | @end 8 | @end 9 | 10 | @class B: A 11 | @constructor pb 12 | super ("I am B", pb) 13 | @end 14 | @end 15 | -------------------------------------------------------------------------------- /Tests/oop-inheritance-classmethods.sg: -------------------------------------------------------------------------------- 1 | # The goal of this test is to exercise inheritence 2 | @class A 3 | @shared P = 'P' 4 | @operation o 5 | return P 6 | @end 7 | @operation a v 8 | P = P + v 9 | return P 10 | @end 11 | @end 12 | 13 | @class B: A 14 | @end 15 | 16 | @class C: B 17 | @shared P = 'C.P' 18 | @end 19 | 20 | print ('A.o', A o()) 21 | print ('B.o', B o()) 22 | print ('C.o', C o()) 23 | 24 | print ('A.a("x")', A a('x')) 25 | print ('B.a("y")', B a('y')) 26 | print ('C.a("z")', C a('z')) 27 | -------------------------------------------------------------------------------- /Tests/oop-inheritance.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Inheritance and use of 'super' 2 | @class A 3 | 4 | @method foo 5 | print ("Foo (def in A)") 6 | @end 7 | 8 | @end 9 | 10 | @class B : A 11 | 12 | @method foo 13 | super foo() 14 | print ("Foo (def in B)") 15 | @end 16 | 17 | @end 18 | 19 | @class C: B 20 | 21 | @method foo 22 | super foo() 23 | super super foo() 24 | print ("Foo (def in C)") 25 | @end 26 | 27 | @end 28 | 29 | @class D: C 30 | @end 31 | 32 | @main 33 | var a = new A() 34 | var b = new B() 35 | var c = new C() 36 | var d = new D() 37 | print "a foo()" 38 | a foo() 39 | print "b foo()" 40 | b foo() 41 | print "c foo()" 42 | c foo() 43 | print "d foo()" 44 | d foo() 45 | @end 46 | # EOF 47 | -------------------------------------------------------------------------------- /Tests/oop-module-1.sg: -------------------------------------------------------------------------------- 1 | @module A 2 | 3 | @function f1 4 | print "A1.f1" 5 | @end 6 | 7 | @function f2 8 | print "Al.f2" 9 | @end 10 | 11 | -------------------------------------------------------------------------------- /Tests/oop-module-2.sg: -------------------------------------------------------------------------------- 1 | @module A 2 | 3 | @function f1 4 | print "A2.f1" 5 | @end 6 | 7 | @function f3 8 | print "A2.f3" 9 | @end 10 | 11 | f1() 12 | f2() 13 | f3() 14 | -------------------------------------------------------------------------------- /Tests/oop-module-attributes.sg: -------------------------------------------------------------------------------- 1 | @shared attribute1:String 2 | @shared attribute2:String 3 | 4 | @function getAttribute1 5 | return attribute1 6 | @end 7 | 8 | @function init 9 | attribute1 = "Hello" 10 | attribute2 = "World" 11 | @end 12 | -------------------------------------------------------------------------------- /Tests/oop-module-import.sg: -------------------------------------------------------------------------------- 1 | @import A from testmodule 2 | @import testpackage.testmodule 3 | 4 | @class LocalA: A 5 | 6 | @method aliasForMethodA 7 | return methodA() 8 | @end 9 | 10 | @end 11 | 12 | @class LocalA2: testpackage.testmodule.A 13 | 14 | @method aliasForMethodA 15 | return methodA() 16 | @end 17 | 18 | @end 19 | 20 | var a = new LocalA() 21 | var a2 = new LocalA2() 22 | print (a1 aliasForMethodA()) 23 | print (a2 aliasForMethodA()) 24 | 25 | # EOF 26 | -------------------------------------------------------------------------------- /Tests/oop-module-multifile-a.sg: -------------------------------------------------------------------------------- 1 | @module multifile 2 | | Exercises modules spread over multiple files. To test it, to this: 3 | | > sugar -cljs -Loop-module-multifile-b.sg oop-module-multifile-a.sg 4 | @class MultiFileClass 5 | @method doSomething 6 | var m = MultiFileClassHelper () 7 | m foo () 8 | @end 9 | @end 10 | -------------------------------------------------------------------------------- /Tests/oop-module-multifile-b.sg: -------------------------------------------------------------------------------- 1 | @module multifile 2 | 3 | @class MultiFileClassHelper 4 | @method foo 5 | @end 6 | @end 7 | -------------------------------------------------------------------------------- /Tests/oop-module-shared.sg: -------------------------------------------------------------------------------- 1 | @module Shared 2 | 3 | @shared Count 4 | 5 | @function inc 6 | Count += 1 7 | @end 8 | 9 | @main 10 | print (Count) 11 | inc() 12 | print (Count) 13 | inc() 14 | print (Count) 15 | inc() 16 | @end 17 | -------------------------------------------------------------------------------- /Tests/pnuts-example.spnuts: -------------------------------------------------------------------------------- 1 | @target Pnuts 2 | @import java.awt.Frame 3 | @import java.awt.Button as Btn 4 | 5 | var f = new java awt Frame ("Hello, World") 6 | var b = new PTextArea() 7 | f add (b) 8 | f setVisible (True) 9 | -------------------------------------------------------------------------------- /Tests/syntax-access.sg: -------------------------------------------------------------------------------- 1 | var a = [1, 2, 3, 4, 5] 2 | a[0] 3 | something a[0] 4 | (something a)[0] 5 | -------------------------------------------------------------------------------- /Tests/syntax-accessor.sg: -------------------------------------------------------------------------------- 1 | @class C 2 | 3 | @property _p2 = 1 4 | 5 | @accessor p1 6 | return 1 7 | @end 8 | 9 | @accessor p2 10 | return _p2 11 | @end 12 | 13 | @mutator p2 14 | return _p2 15 | @end 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Tests/syntax-allocation.sg: -------------------------------------------------------------------------------- 1 | var a 2 | var a:int = 1 3 | var a, b 4 | var a=0, b=1 5 | var a=0, b:int=1 6 | var a:int=0, b:int=1 7 | var a:int=0, b:int=1, c=2 8 | -------------------------------------------------------------------------------- /Tests/syntax-annotation.sg: -------------------------------------------------------------------------------- 1 | @class Foo 2 | @method bar a 3 | @when a > 5 4 | @pre console log ("PRE") 5 | @post console log ("POST") 6 | print `a 7 | @end 8 | @end 9 | 10 | var f = new Foo() 11 | f bar 1 12 | f bar 5 13 | f bar 6 14 | -------------------------------------------------------------------------------- /Tests/syntax-arguments-defaults.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Default values for arguments 2 | # SYNTAX: ARG = VALUE 3 | # CONSTRAINT: Cannot be optional and have default value 4 | 5 | @function f1 a=1, b=True, f=({x|x + 1}) 6 | return 0 7 | @end 8 | 9 | @function f2 a:Int=1, b:Bool=True, f:Function={x|x + 1} 10 | return 0 11 | @end 12 | 13 | @function f3:Number a:Int=1, b:Bool=True, f:Function=({x|x + 1}) 14 | return 0 15 | @end 16 | 17 | @function f4:Number a:Int=1, b:Bool=True, f:Function=({x|x + 1}) 18 | return 0 19 | @end 20 | 21 | # EOF 22 | -------------------------------------------------------------------------------- /Tests/syntax-arguments-keywords.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Variable arguments list 2 | 3 | @function f1 a=... 4 | return 0 5 | @end 6 | 7 | @function f2 b, a=... 8 | return 0 9 | @end 10 | 11 | @function f3 b, c?, d..., e=... 12 | return 0 13 | @end 14 | 15 | # EOF 16 | -------------------------------------------------------------------------------- /Tests/syntax-arguments-optional.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Optional arguments 2 | # SYNTAX: Add '?' after the argument 3 | 4 | @function f a, b?, c?, d? 5 | return 0 6 | @end 7 | 8 | @function f a, b:Int?, c:Object?, d:String? 9 | return 0 10 | @end 11 | 12 | # EOF 13 | -------------------------------------------------------------------------------- /Tests/syntax-arguments-types.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Argument types (1.0) 2 | # SYNTAX: NAME (':' TYPE) ? 3 | 4 | @function f1:Number 5 | return 1 6 | @end 7 | 8 | @function f2:Number a:Number 9 | return 1 10 | @end 11 | 12 | @function f3:Number a:Number, b:Number 13 | return 1 14 | @end 15 | 16 | @function f4:Number a:Number, b:Number, c:Number 17 | return 1 18 | @end 19 | 20 | @class A 21 | @method g1:Number 22 | return 1 23 | @end 24 | 25 | @method g2:Number a:Number 26 | return 1 27 | @end 28 | 29 | @method g3:Number a:Number, b:Number 30 | return 1 31 | @end 32 | 33 | @method g4:Number a:Number, b:Number, c:Number 34 | return 1 35 | @end 36 | 37 | @operation o1:Number 38 | return 1 39 | @end 40 | 41 | @operation o2:Number a:Number 42 | return 1 43 | @end 44 | 45 | @operation o3:Number a:Number, b:Number 46 | return 1 47 | @end 48 | 49 | @operation o4:Number a:Number, b:Number, c:Number 50 | return 1 51 | @end 52 | 53 | @end 54 | 55 | # EOF 56 | -------------------------------------------------------------------------------- /Tests/syntax-arguments-variable.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Variable arguments list 2 | 3 | @function f1 a... 4 | return 0 5 | @end 6 | 7 | @function f2 b, a... 8 | return 0 9 | @end 10 | 11 | @function f3 b, c?, a... 12 | return 0 13 | @end 14 | 15 | # EOF 16 | -------------------------------------------------------------------------------- /Tests/syntax-arguments.sg: -------------------------------------------------------------------------------- 1 | @function f 2 | @end 3 | 4 | @function g a 5 | @end 6 | 7 | @function h a, b 8 | @end 9 | 10 | 11 | # Function with default value 12 | @function h a, b=0 13 | @end 14 | 15 | # Function with rest a list of rest arguments 16 | @function i a, b, rest... 17 | @end 18 | 19 | # Function with rest a list of rest arguments 20 | @function j a, b, options=... 21 | @end 22 | 23 | @function k a, b, rest..., options=... 24 | @end 25 | 26 | # Function with list of rest arguments and options 27 | @function l a, b, rest..., options=... 28 | @end 29 | 30 | # EOF 31 | -------------------------------------------------------------------------------- /Tests/syntax-assignment-conditional.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: 2 | # The A ?= B allows to assign B to A only if the left value is Undefined 3 | @function f a=Undefined 4 | a ?= 5 5 | return a 6 | @end 7 | 8 | @function g a={} 9 | a field ?= 1 10 | a other_field ?= 1 11 | a ?= 1 12 | a b c ?= 2 13 | return a 14 | @end 15 | 16 | console log ( f () , 5 ) 17 | console log ( f (1) , 1 ) 18 | console log ( f (0) , 0 ) 19 | console log ( g () , {field:1,other_field:1} ) 20 | console log ( g {field:10}, {field:10,other_field:1} ) 21 | console log ( g {other_field:10}, {field:1,other_field:10} ) 22 | console log ( g {field:-10,other_field:10}, {field:-10,other_field:10} ) 23 | -------------------------------------------------------------------------------- /Tests/syntax-assignment-multiple.sg: -------------------------------------------------------------------------------- 1 | # Multiple assignations 2 | # Meaning that 'd' is composed of three elements a,b,c 3 | var a, b, c = d 4 | var a:int, b:int, c:int = d 5 | 6 | # Meaning that we assign the d[0] to head and d[1:] to tail 7 | var head | tail = d 8 | 9 | # We assign d[0] to a, d[1] to b and d[2:] to tail 10 | var a:Int, b:Int | tail:Int = d 11 | 12 | # We assign an expression, making sure it is not repeated 13 | var a, b, c = [0,1,2,3] 14 | var a:int, b:int, c:int = [0,1,2,3,4] 15 | var head | tail = [0,1,2,3,4] 16 | 17 | # var {a,b,c} = d 18 | -------------------------------------------------------------------------------- /Tests/syntax-assignment.sg: -------------------------------------------------------------------------------- 1 | var a = 0 2 | 3 | a = 1 4 | a b = 1 5 | a[0] = 2 6 | a[1+10] = 2 7 | 8 | a += 1 9 | a b += 1 10 | a[0] += 2 11 | a[1+10] += 2 12 | 13 | a -= 1 14 | a b -= 1 15 | a[0] -= 2 16 | a[1+10] -= 2 17 | 18 | # Should this be allowed? 19 | a() b += 3 20 | -------------------------------------------------------------------------------- /Tests/syntax-closures.sg: -------------------------------------------------------------------------------- 1 | {|} 2 | {1} 3 | {foo(1)} 4 | {foo(1);foo(2)} 5 | {var a = 1} 6 | {var a = 1 ; var b = 2} 7 | {return 1} 8 | {print("Hello")} 9 | {print("Hello"); var a=10 ; print("a:", a)} 10 | -------------------------------------------------------------------------------- /Tests/syntax-comments.sg: -------------------------------------------------------------------------------- 1 | # Single line commment 2 | 3 | # Multiple 4 | # line 5 | # comment 6 | -------------------------------------------------------------------------------- /Tests/syntax-computation.sg: -------------------------------------------------------------------------------- 1 | -1 2 | 1 + 1 3 | 1 - 1 4 | 1 / 1 5 | 1 * 1 6 | 1 + 1 * 1 7 | (1 + 1) * 1 8 | 1 + 1 / 1 9 | (1 + 1) / 1 10 | 1 * 1 + 1 11 | 1 / 1 + 1 12 | 1 + 1 - 1 13 | -1 + 1 - 1 14 | -1 / 1 - 1 15 | -1 * 1 - 1 16 | 1 * 1 * 1 17 | 1 * 1 / 1 18 | 1 is 1 19 | 1 is not 1 20 | 3 * 1 is not 1 * 4 21 | ( 1 == 2 ) 22 | ( 1 != 2 ) 23 | ( 1 > 2 ) 24 | ( 1 < 2 ) 25 | ( 1 >= 2 ) 26 | ( 1 <= 2 ) 27 | 1 + 2 == 2 * 3 28 | 2 * 1 * 2 == 2 * 3 / 4 29 | 1 and 2 30 | 1 or 2 31 | 1 and 2 or 3 32 | 1 and 2 or 3 and 4 33 | not 1 34 | not 1 and 2 35 | not 1 and 2 or 3 36 | not 1 and 2 or 3 and 4 37 | pouet is that and 3 * 4 == 2 38 | 1 or 2 or 3 or 4 or 5 or 1 39 | 1 << 2 40 | 1 >> 3 41 | 1 || 2 42 | 1 && 2 43 | # 1 .? 2 44 | -------------------------------------------------------------------------------- /Tests/syntax-control.sg: -------------------------------------------------------------------------------- 1 | if 1 2 | print (True) 3 | end 4 | 5 | if 1 -> print (True) 6 | 7 | if 2 8 | print (True) 9 | else 10 | print (False) 11 | end 12 | 13 | 14 | if 1 -> print True 15 | else -> print False 16 | 17 | if 3 18 | print (True) 19 | if 4 20 | print (False) 21 | else 22 | print () 23 | end 24 | 25 | 26 | for x in 0..10 27 | print x 28 | end 29 | 30 | (0..10) :: {i|print i} 31 | 32 | 33 | var a = 0 34 | for i in a..(a+10) 35 | end 36 | 37 | for i in (a)..(a+10) 38 | end 39 | 40 | # Iterates from 0 to 10 41 | for i in (a)..(a+10) 42 | print (i) 43 | end 44 | 45 | # Iterates from 0 to 10, by step of 2 46 | for i in (a)..(a+10) step 2 47 | print (i) 48 | end 49 | 50 | a = 0 51 | while a < 10 52 | a = a + 1 53 | end 54 | -------------------------------------------------------------------------------- /Tests/syntax-declaration.sg: -------------------------------------------------------------------------------- 1 | var a 2 | var a = 1 3 | var a:Type 4 | var a:Type = 1 5 | var a, b 6 | var a, b = 1, 2 7 | var a:Type, b:Type = 1, 2 8 | -------------------------------------------------------------------------------- /Tests/syntax-decorator.sg: -------------------------------------------------------------------------------- 1 | @class A 2 | 3 | @shared image 4 | @(fleximage source="tiles.png") 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /Tests/syntax-docstrings.sg: -------------------------------------------------------------------------------- 1 | @function hello 2 | | This is the function documentation 3 | return 0 4 | @end 5 | 6 | @class A 7 | @method a 8 | | This is the documentation for the method 9 | return 0 10 | @end 11 | @operation b 12 | | This is the documentation for the operation 13 | return 0 14 | @end 15 | @end 16 | -------------------------------------------------------------------------------- /Tests/syntax-embed.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Embedding code 2 | # SYNTAX: @embed Language ... @end 3 | 4 | @class A 5 | @method f 6 | @embed JavaScript 7 | |var hello = {world:"Hello, World !"}; 8 | |alert("HELLO WORLD" + hello.world) 9 | @end 10 | @end 11 | @end 12 | 13 | @function hello 14 | @embed JavaScript 15 | |var hello = {world:"Hello, World !"}; 16 | |alert("HELLO WORLD" + hello.world) 17 | @end 18 | @end 19 | -------------------------------------------------------------------------------- /Tests/syntax-escape-variables.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Escape reserved keywords 2 | # SYNTAX: Prefix the keywords with '\' 3 | $("selector") \is ".visibile" 4 | var \if = 1 5 | var \target = pouet 6 | var \self = pouet 7 | # EOF 8 | -------------------------------------------------------------------------------- /Tests/syntax-exceptions.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: Declare, raise and intercept and exception 2 | 3 | # STEP 1: Declare the exception 4 | @exception MyException 5 | @end 6 | 7 | # STEP 2: Raise the exception in a function 8 | @function f 9 | raise new MyException() 10 | @end 11 | 12 | # STEP 3: Intercept the exception 13 | @function g 14 | var a = 0 15 | try 16 | f() 17 | catch e 18 | print ("Exception has happened", e) 19 | a = 1 20 | finally 21 | print ("There was an exception:", a) 22 | end 23 | @end 24 | 25 | g() 26 | 27 | # EOF 28 | -------------------------------------------------------------------------------- /Tests/syntax-for.sg: -------------------------------------------------------------------------------- 1 | for x in 0..10 2 | print x 3 | end 4 | 5 | (0..10) :: {i|print i} 6 | 7 | 8 | var a = 0 9 | for i in a..(a+10) 10 | end 11 | 12 | for i in (a)..(a+10) 13 | end 14 | 15 | # Iterates from 0 to 10 16 | for i in (a)..(a+10) 17 | print (i) 18 | end 19 | 20 | # Iterates from 0 to 10, by step of 2 21 | for i in (a)..(a+10) step 2 22 | print (i) 23 | end 24 | -------------------------------------------------------------------------------- /Tests/syntax-function.sg: -------------------------------------------------------------------------------- 1 | @function a 2 | return 1 3 | @end 4 | 5 | @function b a 6 | return 1 7 | @end 8 | 9 | 10 | @function c a, b 11 | return 1 12 | @end 13 | 14 | 15 | @function d a, b, c, d 16 | return 1 17 | @end 18 | 19 | @function d a:int, b:int, c:int, d:int 20 | return 1 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /Tests/syntax-group.sg: -------------------------------------------------------------------------------- 1 | @class WishEditor 2 | 3 | @shared Widget 4 | @property element 5 | @property coin 6 | 7 | 8 | @constructor selector 9 | element = $(selector) get (0) 10 | Widget = this 11 | bindHTML (element) 12 | bindCommands (this) 13 | @end 14 | 15 | 16 | @group Widget 17 | @method doCommand name 18 | @as dispatcher 19 | # FIX: getMethod(name) () 20 | return this[name]() 21 | @end 22 | 23 | @method bindHTML e 24 | @when e and e boundHTML is undefined 25 | a = 0 26 | @end 27 | 28 | @method show 29 | $(element) show() 30 | @end 31 | 32 | @method hide 33 | $(element) hide() 34 | @end 35 | @end 36 | 37 | @group Properties 38 | @method getUserName 39 | @as accessor 40 | return $(".input.name", element) get (0) value 41 | @end 42 | 43 | @method getUserWish 44 | @when accessor 45 | return $(".input.wish", element) get (0) value 46 | @end 47 | @end 48 | 49 | @group Commands 50 | 51 | @method startWish 52 | toggleSection "wish" 53 | @end 54 | 55 | @method makeWish 56 | toggleSection "review" 57 | @end 58 | 59 | @method modifyWish 60 | toggleSection "wish" 61 | @end 62 | 63 | @method confirmWish 64 | toggleSection "thanks" 65 | @end 66 | 67 | @method endWish 68 | hide () 69 | $(coin element) DraggableDestroy() 70 | @end 71 | 72 | @end 73 | 74 | 75 | @group Sections 76 | 77 | @method toggleSection name 78 | | Hides every section but the given one 79 | hideSections() 80 | showSection (name) 81 | @end 82 | 83 | @method hideSections 84 | | Hides all sections in this widget 85 | $(".section", element) :: {s|$(s) addClass "hidden"} 86 | @end 87 | 88 | 89 | @method showSection name 90 | | Shows the section with the given name (this does not ensure the existence of 91 | | the given section 92 | $(".section." + name, element) :: {s|$(s) removeClass "hidden"} 93 | @end 94 | 95 | @end 96 | 97 | @end 98 | 99 | -------------------------------------------------------------------------------- /Tests/syntax-identifiers.sg: -------------------------------------------------------------------------------- 1 | var newa = 1 2 | var new_a = 1 3 | var new_ab = 1 4 | -------------------------------------------------------------------------------- /Tests/syntax-if-expression.sg: -------------------------------------------------------------------------------- 1 | var a = ( 1 ? 2) 2 | var a = (1 ? 2 | 2 ? 3 | 4) 3 | var a = (1 ? 2 | 2 ? 3 | 3 ? 4 | 3) 4 | var b = {e| 1 ? 2} 5 | var b = {e| 1 ? 2} 6 | var b = {e|1} 7 | -------------------------------------------------------------------------------- /Tests/syntax-if-sequence.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: the ifs should be aggreated, but they appear as seperate 2 | # SOLUTION: Rewrite this as 'inArea2' as the inArea1 is ambiguous anyway 3 | @function inArea1 pos, area 4 | | This is a snippet that failed parsing at some point 5 | if (pos[0] < area x) -> return False 6 | if (pos[0] > (area x + area w)) -> return False 7 | if (pos[1] > area y) -> return False 8 | if (pos[1] > (area y + area y)) -> return False 9 | else -> return true 10 | @end 11 | 12 | @function inArea2 pos, area 13 | | This is a snippet that failed parsing at some point 14 | if (pos[0] < area x) 15 | return False 16 | if (pos[0] > (area x + area w)) 17 | return False 18 | if (pos[1] > area y) 19 | False 20 | if (pos[1] > (area y + area y)) 21 | False 22 | else 23 | return true 24 | end 25 | @end 26 | -------------------------------------------------------------------------------- /Tests/syntax-if-singleline.sg: -------------------------------------------------------------------------------- 1 | @function f 2 | 0..10 :: { e | (if 1 -> print "YAY") } 3 | @end 4 | -------------------------------------------------------------------------------- /Tests/syntax-if.sg: -------------------------------------------------------------------------------- 1 | if 1 2 | print 'One' 3 | end 4 | 5 | if 1 6 | print 'One' 7 | if 2 8 | print 'Two' 9 | end 10 | 11 | if 1 12 | print 'One' 13 | else 14 | print 'Two' 15 | end 16 | 17 | # Nested if 18 | if 1 19 | if 3 20 | print "Impossible" 21 | if 4 22 | print "Impossible" 23 | end 24 | else 25 | print 'Two' 26 | end 27 | 28 | # In closure 29 | var f = {a| 30 | if 1 31 | if 3 32 | print "Impossible" 33 | if 4 34 | print "Impossible" 35 | end 36 | else 37 | print 'Two' 38 | end 39 | } 40 | 41 | @function inArea pos, area 42 | | This is a snippet that failed parsing at some point 43 | if (pos[0] < area x) -> return false 44 | if (pos[0] > (area x + area w)) -> return false 45 | if (pos[1] > area y) -> return false 46 | if (pos[1] > (area y + area y)) -> return false 47 | else -> return true 48 | @end 49 | -------------------------------------------------------------------------------- /Tests/syntax-import.sg: -------------------------------------------------------------------------------- 1 | @target Pnuts 2 | 3 | @import Frame from java 4 | @import Button from java.awt as Btn 5 | @import Frame, Button from java.awt 6 | @import * from java.awt 7 | @import java.awt 8 | @import java.awt, java.lang.reflect 9 | 10 | @import Button from java.awt as Btn 11 | @import * from java.awt 12 | 13 | var f = new Frame ("Hello, World") 14 | f add (b) 15 | f setVisible (True) 16 | -------------------------------------------------------------------------------- /Tests/syntax-indent.sg: -------------------------------------------------------------------------------- 1 | @function a 2 | 3 | print "Hello" 4 | print "HELLo" 5 | print "pouet" 6 | @end 7 | -------------------------------------------------------------------------------- /Tests/syntax-instanciation.sg: -------------------------------------------------------------------------------- 1 | @main 2 | a = new A() 3 | @end 4 | -------------------------------------------------------------------------------- /Tests/syntax-invocation-byname.sg: -------------------------------------------------------------------------------- 1 | @function f a=1,b=2,c=3,d=4,e=5 2 | return [a,b,c,d,e] 3 | @end 4 | 5 | f(b=0) 6 | f(b=0,c=2) 7 | print "Expects: [1, 2, 3, 4, 5]" 8 | print ("1: ", f()) 9 | print "Expects: [1, 0, 3, 4, 5]" 10 | print ("2: ", f(b=0)) 11 | print "Expects: [1, 2, 3, 4, 4]" 12 | print ("3: ", f(e=4)) 13 | # Should do an error 14 | print "Expects: [1, 0, 3, 4, 5]" 15 | print ("4: ", f(f=6)) 16 | -------------------------------------------------------------------------------- /Tests/syntax-invocation-escaperef.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: Allows to not use the parens when invoking a single argument 2 | 3 | @function f a 4 | return a 5 | @end 6 | 7 | var a = 1 8 | f 'a == f (a) 9 | f '[1] == f ([1]) 10 | f '{a:1} == f {a:1} 11 | f 'a () == f (a) () 12 | 13 | # EOF 14 | -------------------------------------------------------------------------------- /Tests/syntax-invocation-noargs.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: You can use '!' as a substitute for () 2 | # DATE: 08-Feb-2008 3 | @function f 4 | return 1 5 | @end 6 | 7 | f ! == f () 8 | f != 2 9 | # EOF 10 | -------------------------------------------------------------------------------- /Tests/syntax-invocation.sg: -------------------------------------------------------------------------------- 1 | # Alternative: 2 | # We may do a! instead of a() 3 | # This may allow the distinction between invocation and activation 4 | 5 | var a 6 | a = None 7 | a () 8 | a = a b 9 | a = a () b 10 | 11 | a b() 12 | a() b() c() 13 | a() b c() 14 | 15 | a = a() b() c 16 | a = a() b c 17 | a b() c() 18 | a b c() 19 | 20 | a = a b() c 21 | a = a b c 22 | a = a[0] 23 | a = a["pouet"] 24 | 25 | a[0] pouet() 26 | 27 | # There is a problem here where the '[0]' is interepreted as a value 28 | a pouet[0]() 29 | a pouet[0] b() 30 | a pouet()[0] b() 31 | 32 | # Multi-line invocation 33 | a(1) 34 | a(1,2) 35 | a(1,2,3) 36 | 37 | a(1,2, 38 | 3 39 | ) 40 | 41 | a(1, 42 | 2 43 | 3 44 | ) 45 | 46 | a( 47 | 1 48 | 2 49 | 3 50 | ) 51 | -------------------------------------------------------------------------------- /Tests/syntax-iteration-filter.sg: -------------------------------------------------------------------------------- 1 | [0,1,2,3] ::? {_|_ > 0} = {_|_ * 10} 2 | -------------------------------------------------------------------------------- /Tests/syntax-iteration-map.sg: -------------------------------------------------------------------------------- 1 | [0,1,2,3] ::= {_|_ * 10} 2 | -------------------------------------------------------------------------------- /Tests/syntax-iteration.sg: -------------------------------------------------------------------------------- 1 | (0..10) :: {x|print (x)} 2 | -------------------------------------------------------------------------------- /Tests/syntax-map-implicit.sg: -------------------------------------------------------------------------------- 1 | let a = 1 2 | let b = 1 3 | let c = {a, b, c:0} 4 | -------------------------------------------------------------------------------- /Tests/syntax-mutator.sg: -------------------------------------------------------------------------------- 1 | @class C 2 | 3 | @property _f 4 | 5 | @mutator f v 6 | self _f = v 7 | @end 8 | 9 | @end 10 | -------------------------------------------------------------------------------- /Tests/syntax-names.sg: -------------------------------------------------------------------------------- 1 | var new_node = 0 2 | new_node value 3 | new_node setAttribute (attr nodeName, attr_value) 4 | 5 | -------------------------------------------------------------------------------- /Tests/syntax-operator-in.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: The 'in' operator tests if an element is in another element. 2 | 3 | print ("True:", (1 in [0,1,2])) 4 | print ("False:", (1 in [0])) 5 | print ("True:", ([0] in [[0]])) 6 | print ("True:", (1 in {a:1})) 7 | print ("True:", ("h" in "hello world")) 8 | print ("True:", ("lo" in "hello world")) 9 | 10 | # EOF 11 | -------------------------------------------------------------------------------- /Tests/syntax-operators-multiline.sg: -------------------------------------------------------------------------------- 1 | # PROBLEM: When we have long conditions for if, we'd like to span more than 2 | # one line 3 | # SYNTAX: Allow 4 | # if condition ; 5 | # (and|or) condition ; 6 | # (and|or) condition 7 | # NOTE: This only works for computation, before the operator 8 | 9 | @function f 10 | var averylongvariable = 1 11 | var anotherverylongvariable = 1 12 | 13 | if averylongvariable == 1 ; 14 | and anotherverylong variable ; 15 | or anotherverylong 16 | print "OK" 17 | end 18 | @end 19 | 20 | # END 21 | -------------------------------------------------------------------------------- /Tests/syntax-protocol.sg: -------------------------------------------------------------------------------- 1 | @module jQuery 2 | @as Interface 3 | 4 | @protocol jQueryEngine 5 | @group Core 6 | @abstract @method each Function 7 | @abstract @method eq Number 8 | @abstract @method get Number 9 | @abstract @method gt Number 10 | @abstract @method index Number 11 | @abstract @method length Number 12 | @abstract @method lt Number 13 | @abstract @method size Number 14 | @end 15 | @end 16 | 17 | # TODO: Variable arguments 18 | #@function jQuery:jQueryEngine selector:String (parent:String)? 19 | @abstract @function jQuery:JQueryEngine String 20 | 21 | # TODO: Multiple dispatch (with type support) 22 | #@abstract @function jQuery:jQueryEngine Function 23 | -------------------------------------------------------------------------------- /Tests/syntax-resolution.sg: -------------------------------------------------------------------------------- 1 | # Slot access resolution (the semantic depends on the target) 2 | a b 3 | a b c 4 | # Direct resolution (direct access to the property) 5 | a.b 6 | a.b.c 7 | # EOF 8 | -------------------------------------------------------------------------------- /Tests/syntax-rewrite.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: @rewrite allows functions/methods to be rewritten for a specific 2 | # target. 3 | # TODO: Support more targets 4 | @class List 5 | 6 | @constructor 7 | @rewrite(Python):[] 8 | @end 9 | 10 | @method push v 11 | @rewrite(Python):${self}.append(${v}) 12 | @end 13 | 14 | @method pop 15 | @rewrite(Python):${self}.pop() 16 | @end 17 | 18 | @method length 19 | @rewrite(Python):${self}.length 20 | @end 21 | 22 | @method swap a,b 23 | @rewrite(Python) 24 | |${?s} = ${self}[${a}] 25 | |${self}[${a}] = ${self}[${b}] 26 | |${self}[${b}] = ${?s} 27 | @end 28 | @end 29 | @end 30 | 31 | # EOF 32 | -------------------------------------------------------------------------------- /Tests/syntax-slice.sg: -------------------------------------------------------------------------------- 1 | something a[0:1] 2 | something a[0:2] 3 | something a[0:] 4 | something a[0:-1] 5 | -------------------------------------------------------------------------------- /Tests/syntax-specific.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Conditional compilations 2 | 3 | @specific ActionScript 4 | @shared console = Undefined 5 | @shared document = Undefined 6 | @end 7 | 8 | @specific TARGET -OTHERTARGET 9 | @function f 10 | return 0 11 | @end 12 | @specific +OTHERTARGET 13 | @function f 14 | return 1 15 | @end 16 | 17 | @class A 18 | @property a 19 | @constructor 20 | a = 10 21 | @end 22 | @end 23 | @end 24 | 25 | 26 | @function g 27 | var a = 1 28 | @specific TARGET 29 | a = 10 30 | @specific OTHERTARGET 31 | a = 20 32 | @end 33 | @end 34 | 35 | # EOF 36 | -------------------------------------------------------------------------------- /Tests/syntax-strings.sg: -------------------------------------------------------------------------------- 1 | var s 2 | s = "" 3 | s = '' 4 | s = "Hello" 5 | s = 'Hello' 6 | s = "'" 7 | s = '"' 8 | s = "\"" 9 | s = '\'' 10 | s = "\\" 11 | s = '\\' 12 | s = '"hello"' 13 | s = '"hello\"world"' 14 | s = "'(\\\\'|[^'])*'" 15 | s = '\'(\\\\\'|[^\'])*\'' 16 | s = '"(\\\\"|[^"])*"' 17 | s = "\"(\\\\\"|[^\"])*\"" 18 | -------------------------------------------------------------------------------- /Tests/syntax-time.sjs: -------------------------------------------------------------------------------- 1 | console log ( 2 | 10ms 3 | 10s 4 | 10h 5 | 10d 6 | 10w 7 | ) 8 | 9 | -------------------------------------------------------------------------------- /Tests/syntax-with-statement.sg: -------------------------------------------------------------------------------- 1 | var o = {a:{print 1},b:{print 2},c:{print 3}} 2 | with o 3 | a 4 | b 5 | end 6 | var j = 1 7 | -------------------------------------------------------------------------------- /Tests/test.pnuts: -------------------------------------------------------------------------------- 1 | package("pouet") 2 | class Point 3 | { 4 | Object x 5 | Object y 6 | Point(px,py){ 7 | x=px 8 | y=py 9 | } 10 | } 11 | 12 | class Shape 13 | { 14 | Object points 15 | Shape(){ 16 | __this__=this 17 | __this__.points = new java.util.ArrayList() 18 | } 19 | addPoint(point){ 20 | __this__=this 21 | return __this__.points.add(point) 22 | } 23 | addAnotherPoint(point){ 24 | __this__=this 25 | return __this__.addPoint(point) 26 | } 27 | } 28 | 29 | class RectangleShape extends pouet.Shape 30 | { 31 | RectangleShape(){ 32 | __this__=this 33 | } 34 | } 35 | 36 | s = new Shape() 37 | s.addPoint(new Point(10,20)) 38 | -------------------------------------------------------------------------------- /Tests/test.py: -------------------------------------------------------------------------------- 1 | class A: 2 | def __init__(self): 3 | pass 4 | def p(self): 5 | return 1 6 | 7 | class B(A): 8 | def __init__(self): 9 | A.__init__(self) 10 | def p(self): 11 | return super(B,self).p() + 1 12 | 13 | b = B() 14 | b.__class__ 15 | print b.__class__.__bases__ 16 | print b.p() 17 | -------------------------------------------------------------------------------- /Tests/testmodule.sg: -------------------------------------------------------------------------------- 1 | @module testmodule 2 | @class A 3 | @method methodA 4 | return "testmodule.A.methodA" 5 | @end 6 | @method methodB 7 | return "testmodule.A.methodB" 8 | @end 9 | @end 10 | -------------------------------------------------------------------------------- /Tests/testpackage/testmodule.sg: -------------------------------------------------------------------------------- 1 | @module testpackage.testmodule 2 | @class A 3 | @method methodA 4 | return "testpackage.testmodule.A.methodA" 5 | @end 6 | @method methodB 7 | return "testpackage.testmodule.A.methodB" 8 | @end 9 | @end 10 | -------------------------------------------------------------------------------- /Tests/todo-async.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Asynchronous invocation 2 | # SYNTAX: callable...arguments 3 | @function compute 4 | return 0 5 | @end 6 | 7 | # This function returns an iterator because it uses yield 8 | @function continuation 9 | var a = 0 10 | while True 11 | yield a 12 | a = a + 1 13 | end 14 | @end 15 | 16 | @function asyncTest 17 | 18 | # POSSIBLE SYNTAXES: 19 | # @invocation() (Io-like) 20 | # invocation@() 21 | # invocation->() (Narrative JS) 22 | # invocation...() 23 | # invocation^() 24 | # invocation%() 25 | # \invocation() 26 | # invocation()... 27 | # &invocation() 28 | # invocation&() 29 | # invocation()& 30 | # invocation?() 31 | 32 | # The function...params notation visually indicates that the computation 33 | # will take some time, and evokes the range 0..2 notation, implying that 34 | # the execution may be broken into sub-parts. The disadvantage is that this 35 | # notation may be a bit long 36 | var future = compute...() 37 | var future = compute..() 38 | 39 | # The use of \ indicates escaping, but may be useful for other language 40 | # features such as lazy arguments passing like f(\a, \b, \c) would mean 41 | # passing the expressions of a, b, c. 42 | # future := \compute() 43 | 44 | # The future value is lazily evaluated. When the future is passed, it is not 45 | # evaluated, but if it is used, it will be evaluated, and will then block 46 | # the process waiting for the value 47 | print (future) 48 | 49 | # 50 | var cont = continuation..() 51 | cont :: { e | print e } 52 | 53 | @end 54 | # EOF 55 | -------------------------------------------------------------------------------- /Tests/todo-for-type.sg: -------------------------------------------------------------------------------- 1 | for line:String in file readlines() 2 | line split "." [-1:1] 3 | end 4 | 5 | for line:List in file readlines() 6 | line length() 7 | end 8 | -------------------------------------------------------------------------------- /Tests/todo-methods-operators.sg: -------------------------------------------------------------------------------- 1 | # GOAL: Allow definition methods that will be used for specific operators 2 | @class 3 | 4 | @operator + value 5 | return self value + value 6 | @end 7 | 8 | @operator - value 9 | return self value + value 10 | @end 11 | 12 | 13 | @operator string value 14 | return ("My value is:" + value) 15 | @end 16 | 17 | @operator slice start, end 18 | @end 19 | 20 | @operator iterate start, end 21 | return Iterator(...) 22 | @end 23 | 24 | @end 25 | # EOF 26 | -------------------------------------------------------------------------------- /Tests/todo-oop-accessors-class.sg: -------------------------------------------------------------------------------- 1 | @class A 2 | 3 | @attribute value get=getValue set=setValue 4 | 5 | @function getValue 6 | return value 7 | @end 8 | 9 | @function setValue v 10 | value = v 11 | @end 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Tests/todo-oop-accessors-module.sg: -------------------------------------------------------------------------------- 1 | @shared valueString get = (getValue set={v| ensure(v length() > 0) ; value = v}) 2 | 3 | @function getValue 4 | return getValue 5 | @end 6 | -------------------------------------------------------------------------------- /Tests/todo-oop-module-init.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Module Constructor 2 | @shared a = 1 3 | @initialize 4 | a = 1 5 | @end 6 | # EOF 7 | -------------------------------------------------------------------------------- /Tests/todo-oop-singleton.sg: -------------------------------------------------------------------------------- 1 | @singleton AppState 2 | 3 | @property currentState 4 | 5 | # A Singleton constructor cannot have any arguments 6 | @constructor 7 | currentState = 0 8 | @end 9 | 10 | @group Transitions 11 | @method state1 12 | currentState = 1 13 | @end 14 | @method state2 15 | currentState = 2 16 | @end 17 | @end 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Tests/todo-syntax-assert.sg: -------------------------------------------------------------------------------- 1 | @function f 2 | assert f is not None 3 | @end 4 | -------------------------------------------------------------------------------- /Tests/todo-syntax-conditional-operation.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: 2 | # Avoid this kind of situation: 3 | # 4 | # > if on put -> on put { m | TradingShelf addToTradingShelf( item ) } 5 | # > if on remove -> on remove { m | TradingShelf removeFromTradingShelf( item ) } 6 | # > if on ask -> on ask { m | item tradingStatus ask() } 7 | # > if on send -> on send { m | item tradingStatus send() } 8 | 9 | on put ? { m | TradingShelf addToTradingShelf (item) } 10 | 11 | # And the variant where you directly send a message to 'on put' when it is defined 12 | 13 | on put ? doThat () 14 | 15 | # This is not to be confused with, which is an 'if' expression 16 | 17 | if on put -> doThat () 18 | 19 | # EOF 20 | -------------------------------------------------------------------------------- /Tests/todo-syntax-default.sg: -------------------------------------------------------------------------------- 1 | # FEATURE: Default value 2 | # SYNTAX: ( EXPRESSION | EXPRESSION ) 3 | @function f 4 | return Undefined 5 | @end 6 | 7 | @function g 8 | return (f()|True) 9 | @end 10 | -------------------------------------------------------------------------------- /Tests/todo-syntax-filter.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: An extension of the iteration into filter 2 | # DATE: 04-Feb-2008 3 | 4 | [1,2,3,4,5] :{x|x>0}: {x|print x} 5 | 6 | r = new RegExp "in\\-\\w+" 7 | "element in-field pouet" :{c|r exec(c)}: { 8 | } 9 | 10 | # EOF 11 | -------------------------------------------------------------------------------- /Tests/todo-syntax-in.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: Allow the 'in' operation 2 | var is_in = (1 in [1,2,4,5]) 3 | -------------------------------------------------------------------------------- /Tests/todo-syntax-invocations.sg: -------------------------------------------------------------------------------- 1 | 2 | @function f a=None 3 | return a 4 | @end 5 | 6 | var a = 1 7 | 8 | # Shorthand for f() 9 | f ! 10 | 11 | # Shorthand for f(a) 12 | f 'a 13 | -------------------------------------------------------------------------------- /Tests/todo-syntax-reference-module.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: It's often useful to reference the given module (or class) for 2 | # that matter. 3 | # SOLUTION: Use specific variables/functions to get a reference to the current 4 | # module or class. 5 | 6 | __module__ 7 | __class__ 8 | __function__ 9 | __context__ 10 | 11 | # However, we could add a specific syntax to denote context variables 12 | 13 | var m = @module 14 | var c = @class 15 | var f = @function 16 | var c = @context 17 | 18 | # Used within an expression would resolve to the curren module, and not be 19 | # identified as a declaration. But is seems a bit shady -- so maybe the 20 | # above globals are better. 21 | 22 | -------------------------------------------------------------------------------- /Tests/todo-syntax-select.sg: -------------------------------------------------------------------------------- 1 | # SYNTAX: select is like an 'if on a single expression that you run against a 2 | # set of (partial) predicate expressions. The preficate is the first line or the 3 | # left part of the '->' 4 | @main 5 | print "POUET" 6 | select 1 as a 7 | as 1 8 | print 'One' 9 | end 10 | end 11 | 12 | select 2 13 | like 1 14 | print 'Failed' 15 | like 2 16 | print 'Succeeded' 17 | end 18 | end 19 | 20 | select 2 21 | 1 -> print 'Failed' 22 | 2 -> print 'Succeeded' 23 | end 24 | 25 | select 2 as a 26 | (a==1) -> print 'Failed' 27 | (a==2) -> print 'Succeeded' 28 | end 29 | 30 | select 2 as a 31 | (a==1) -> print 'Failed' 32 | _ -> print 'Succeeded' 33 | end 34 | 35 | select name 36 | is "var" -> context values [value] = context ["currentValue"] 37 | is "in" -> iterated_values = context values [value] 38 | is "apply" -> apply_template = value 39 | end 40 | 41 | select 2 as a 42 | > 2 -> print 'Greater than two' 43 | < 1 -> print 'Lower than one' 44 | end 45 | 46 | @end 47 | # EOF 48 | -------------------------------------------------------------------------------- /Tests/todo-syntax-switch.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: 2 | # Otpimize 3 | 4 | @function f 5 | if input hasClass("UserModel") 6 | model = user 7 | if input hasClass("UserProfile") 8 | model = profile 9 | if input hasClass("UserAddress") 10 | model = address 11 | end 12 | @end 13 | -------------------------------------------------------------------------------- /Tests/todo-syntax-with.sg: -------------------------------------------------------------------------------- 1 | 2 | @function f 3 | var o = new Object() 4 | with o 5 | a = 10 6 | doThis() 7 | end 8 | @end 9 | -------------------------------------------------------------------------------- /Tests/todo-types-declaration.sg: -------------------------------------------------------------------------------- 1 | @type JSON as Object 2 | @type Text as String 3 | 4 | @function f o:JSON 5 | return o 6 | @end 7 | -------------------------------------------------------------------------------- /Tests/todo-types-translation.sg: -------------------------------------------------------------------------------- 1 | # DESC: This is to test the type translation system, where the calls 'append', 2 | # 'prepent', 'length', etc are defined in the LambdaFactory runtime interface, 3 | # and should be translated to the apporpriate basic types depending on the 4 | # target. 5 | @function f 6 | var l = [] 7 | l swap (0,1) 8 | print ("length:", l length()) 9 | @end 10 | 11 | @function g aList:List 12 | aList swap(0,1) 13 | @end 14 | 15 | g([]) 16 | -------------------------------------------------------------------------------- /Tests/types-declaration.sg: -------------------------------------------------------------------------------- 1 | # Variable types 2 | var fooint 3 | var spamany = 10 4 | 5 | @function foo aint, bString 6 | return 10 7 | @end 8 | -------------------------------------------------------------------------------- /Tests/types-dict.sg: -------------------------------------------------------------------------------- 1 | @function f 2 | return 'b' 3 | @end 4 | 5 | a = {} 6 | a = {a:1} 7 | a = {a:1,b:2,c:3} 8 | a = {a:1,b:2,c:3} 9 | a = { 10 | } 11 | a = { 12 | a:1 13 | } 14 | a = { 15 | a:1 16 | b:1 17 | } 18 | a = { 19 | a:1, b:1 20 | c:1 21 | } 22 | a = { a:1, b:1 23 | c:1 24 | } 25 | a = { a : 'a is a key' } 26 | a = { (f()) : 'f() returns "b" is a key' } 27 | -------------------------------------------------------------------------------- /Tests/types-list.sg: -------------------------------------------------------------------------------- 1 | a = [] 2 | a = [1] 3 | a = [1,2] 4 | a = [1,2,3] 5 | a = [] 6 | a = [ 7 | 1 8 | ] 9 | a = [ 10 | 1 11 | 2 12 | ] 13 | a = [ 14 | 1 15 | 2, 3 16 | ] 17 | a = [ 1, 2 18 | 3 19 | ] 20 | -------------------------------------------------------------------------------- /Tests/types-litterals.sg: -------------------------------------------------------------------------------- 1 | # Numbers 2 | a = 0 3 | a = (0) 4 | a = 0.0 5 | a = (0.0) 6 | 7 | # Strings 8 | a = "String" 9 | a = ("String") 10 | 11 | # Ranges 12 | a = 0..1 13 | a = (0+1)..(0+10) 14 | a = (a) 15 | a = (a)..(a+10) 16 | 17 | # Lists 18 | a = [] 19 | a = [1] 20 | a = [1, 2] 21 | a = [1, 2, 3] 22 | a = [[]] 23 | a = [[],[]] 24 | a = [[],[],[]] 25 | 26 | # Dicts 27 | a = {} 28 | a = { key :value} 29 | a = { key :value, key:value} 30 | a = { key:value, key:value, key:value} 31 | a = { (1):value, (2):value, (3):value} 32 | a = { (1+4):value, (2+10):value, (3+20):value} 33 | -------------------------------------------------------------------------------- /Tests/types-strings.sg: -------------------------------------------------------------------------------- 1 | var a = "pouet" 2 | var a = " pouet" 3 | var a = " pouet " 4 | var a = " pouet " 5 | var a = " pouet " 6 | var a = "\ pouet\\ " 7 | -------------------------------------------------------------------------------- /Tests/warning-oop-super-without-parent.sg: -------------------------------------------------------------------------------- 1 | @class A 2 | @constructor 3 | # This should fire up a warning 4 | super() 5 | @end 6 | @end 7 | -------------------------------------------------------------------------------- /Tests/warning-value-without-operation.sg: -------------------------------------------------------------------------------- 1 | # DESCRIPTION: Sugar should raise an error indicating that you have only values 2 | # as statements 3 | # DATE: 05-Mar-2008 4 | # -- 5 | # // 8< ---[pouet.js]--- 6 | # function _meta_(v,m){var ms=v['__meta__']||{};for(var k in m){ms[k]=m[k]};v['__meta__']=ms;return v} 7 | # var pouet={} 8 | # var __this__=pouet 9 | # pouet.init= _meta_(function(){ 10 | # var __this__=pouet; 11 | # $.get(_meta_(function(){ 12 | # },{arguments:[]})) 13 | # },{arguments:[]}) 14 | # pouet.init() 15 | $ get({ 16 | "/PowerSearch/Item/" 17 | { 18 | num : numResults 19 | from : startIndex 20 | results_field : resultType 21 | query : serverQuery 22 | } 23 | { response | 24 | $( appendTo ) append( response ) 25 | } 26 | }) 27 | # EOF 28 | -------------------------------------------------------------------------------- /bug-comments.sjs: -------------------------------------------------------------------------------- 1 | var a = { 2 | # Comment 3 | a: 1 4 | b: 2 #Comment 5 | # Comment 6 | c: 3 7 | c: 4 8 | c: 5 #Comment 9 | } 10 | -------------------------------------------------------------------------------- /bug-if-expression-priority.sjs: -------------------------------------------------------------------------------- 1 | @class A 2 | 3 | @method m 4 | return True 5 | @end 6 | 7 | @method n 8 | return False 9 | @end 10 | 11 | @method p0 a 12 | # This one is correct 13 | return if a > 0 -> m () | n () 14 | @end 15 | 16 | @method p1 a 17 | # BUG: The result of the expression is not returned 18 | # it is converted to an `if` statement. 19 | if a > 0 -> m () | n () 20 | @end 21 | 22 | @method p2 a 23 | # BUG: The else part of the expression has to be put in parens 24 | a > 0 ? m () | n () 25 | @end 26 | 27 | @method p3 a 28 | # This one is correct 29 | a > 0 ? m () | (n ()) 30 | @end 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /bug-implicit-args.sjs: -------------------------------------------------------------------------------- 1 | console log ("MA", matched ::= {[_ priority, _ attr "data-widget"]}) 2 | console log ("MA", matched ::= {_ + 1}) 3 | 4 | -------------------------------------------------------------------------------- /bug-iteation.sjs: -------------------------------------------------------------------------------- 1 | 2 | @function populateColumns tiles=uis tiles 3 | var types = filter (by_type, {return len(_1) > 1}) 4 | # We balance the tiles with multiple attributes 5 | for tui in by_type ["+"] 6 | var t = (tui getAttribute "data-type" split ",") :: {[_, len(types[_])]} 7 | end 8 | @end 9 | -------------------------------------------------------------------------------- /install-sugar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # == Sugar installation script 3 | # 4 | # This small script downloads the latest Sugar version and its dependencies 5 | # into a new directory name 'Sugar' (created in the current directory). 6 | # 7 | # It will set everything up and create you a command that you'll be able 8 | # to use to directly invoke Sugar. 9 | 10 | mkdir Sugar ; cd Sugar ; export SUGAR_ROOT=`pwd` 11 | 12 | git clone git://github.com/sebastien/lambdafactory.git lf-repo 13 | git clone git://github.com/sebastien/sugar.git sg-repo 14 | 15 | cd sg-repo/Dependencies ; ./make-dparser.sh ; cd ../.. 16 | 17 | echo '#!/bin/bash' > sugar 18 | echo "export PYTHONPATH=${SUGAR_ROOT}/lf-repo/Distribution:${SUGAR_ROOT}/sg-repo/Sources:${SUGAR_ROOT}/sg-repo/Dependencies/dparser" >> sugar 19 | echo "python2.5 ${SUGAR_ROOT}/sg-repo/Sources/sugar/main.py \$@" >> sugar 20 | chmod +x sugar 21 | 22 | cd .. ; echo "To run sugar: .${SUGAR_ROOT}/sugar" 23 | 24 | # EOF 25 | --------------------------------------------------------------------------------