pax_global_header00006660000000000000000000000064140561572010014513gustar00rootroot0000000000000052 comment=fa4ba476841b9ca4891848dfe96e42336f54f932 luaparse-0.3.1/000077500000000000000000000000001405615720100133305ustar00rootroot00000000000000luaparse-0.3.1/.editorconfig000066400000000000000000000005211405615720100160030ustar00rootroot00000000000000# EditorConfig helps developers define and maintain consistent # coding styles between different editors and IDEs # editorconfig.org root = true [*] end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [**.{js,json,md,html}] indent_style = space indent_size = 2 [Makefile] indent_style = tab luaparse-0.3.1/.gitattributes000066400000000000000000000000131405615720100162150ustar00rootroot00000000000000* text=autoluaparse-0.3.1/.github/000077500000000000000000000000001405615720100146705ustar00rootroot00000000000000luaparse-0.3.1/.github/workflows/000077500000000000000000000000001405615720100167255ustar00rootroot00000000000000luaparse-0.3.1/.github/workflows/ci.yml000066400000000000000000000121731405615720100200470ustar00rootroot00000000000000name: CI on: push: branches: [ master ] pull_request: branches: [ master ] jobs: lint: name: Lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Use Node.js 15.x uses: actions/setup-node@v2 with: node-version: 15.x - run: npm ci - run: make lint complexity-analysis run-tests-node: name: Test in Node.js needs: lint runs-on: ubuntu-latest strategy: matrix: version: [10.x, 12.x, 14.x, 15.x] steps: - uses: actions/checkout@v2 - name: Install Node.js ${{ matrix.version }} uses: actions/setup-node@v2 with: node-version: ${{ matrix.version }} - run: node test/runner.js --console run-tests-rhino: name: Test in Rhino needs: lint runs-on: ubuntu-latest strategy: matrix: version: [1.7.13] steps: - uses: actions/checkout@v2 - name: Download Rhino ${{ matrix.version }} run: | VERSION="${{ matrix.version }}" wget "https://github.com/mozilla/rhino/releases/download/Rhino${VERSION//./_}_Release/rhino-$VERSION.jar" -O /opt/rhino.jar - name: Run tests run: cd test; java -jar /opt/rhino.jar -opt -1 runner.js run-tests-ringojs: name: Test in RingoJS needs: lint runs-on: ubuntu-latest strategy: matrix: version: [2.0.0] steps: - uses: actions/checkout@v2 - name: Download and unpack RingoJS ${{ matrix.version }} run: | VERSION="${{ matrix.version }}" wget "https://github.com/ringo/ringojs/releases/download/v${VERSION}/ringojs-${VERSION}.zip" unzip "ringojs-${VERSION}.zip" -d /opt/ rm "ringojs-${VERSION}.zip" - name: Install RingoJS ${{ matrix.version }} run: | VERSION="${{ matrix.version }}" sed -i -e '/-jar/ i \ -Dringo.classpath="$RINGO_HOME/lib/**" \\' "/opt/ringojs-${VERSION}/bin/ringo" sudo ln -s "/opt/ringojs-${VERSION}/bin/ringo" /usr/local/bin/ringo sudo chmod +x /usr/local/bin/ringo - name: Run tests run: ringo -o -1 test/runner.js 2>&1 run-tests-quickjs: name: Test in QuickJS needs: lint runs-on: ubuntu-latest strategy: matrix: version: ['2020-09-06', '2020-11-08', '2021-03-27'] steps: - uses: actions/checkout@v2 - name: Install QuickJS ${{ matrix.version }} run: | wget "https://bellard.org/quickjs/binary_releases/quickjs-linux-x86_64-${{ matrix.version }}.zip" -O quickjs.zip unzip quickjs.zip qjs sudo install -Dm755 qjs /usr/local/bin/qjs - name: Run tests # XXX: The default QuickJS stack size limit is 256 KiB; # QuickJS likes to throw stack overflow errors when running the test suite at that limit, # so we increase it to 8 MiB. The issue is intermittent and non-deterministic; # it may or may not be an engine bug run: cd test; qjs --stack-size 8388608 --std runner.js run-tests-duktape: name: Test in Duktape needs: lint runs-on: ubuntu-latest strategy: matrix: version: [2.4.0, 2.5.0, 2.6.0] steps: - uses: actions/checkout@v2 - name: Build and install Duktape ${{ matrix.version }} run: | PACKAGE="duktape-${{ matrix.version }}" cd /opt wget "https://duktape.org/$PACKAGE.tar.xz" tar xf "$PACKAGE.tar.xz" make -C "$PACKAGE/" -f Makefile.cmdline DEFINES=-DDUK_CMDLINE_FILEIO sudo install -Dm755 "$PACKAGE/duk" /usr/local/bin/duk rm -rf "$PACKAGE.tar.xz" "$PACKAGE/" - name: Run tests run: cd test; duk runner.js check-coverage: name: Coverage analysis needs: [run-tests-node, run-tests-rhino, run-tests-ringojs, run-tests-quickjs, run-tests-duktape] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: npm ci - run: make coverage-analysis update-docs: name: Update documentation if: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/master' }} needs: check-coverage runs-on: ubuntu-latest steps: - name: Check out GitHub Pages uses: actions/checkout@v2 with: ref: refs/heads/gh-pages path: . - name: Check out luaparse uses: actions/checkout@v2 with: path: luaparse - name: Rebuild documentation run: | rm -rf coverage examples lib benchmarks sed -i -e 's/\.\.\///g' luaparse/docs/layout/head.html luaparse/docs/*.md make -C luaparse install docs mv luaparse/docs/* . mv luaparse/examples . mv luaparse/luaparse.js . mv luaparse/benchmarks . cp -rf luaparse/test . rm -rf *.md layout luaparse public - name: Upload updated documentation to GitHub Pages run: | git add . git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "GitHub Actions" git commit --message "Rebuild documentation" git push origin gh-pages luaparse-0.3.1/.github/workflows/release.yml000066400000000000000000000017641405615720100211000ustar00rootroot00000000000000name: Upload release on: release: types: [created] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: 12 - run: npm ci - run: npm test publish-npm: needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: 12 registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} publish-gpr: needs: build runs-on: ubuntu-latest permissions: contents: read packages: write steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: 12 registry-url: https://npm.pkg.github.com/ - run: npm ci - run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} luaparse-0.3.1/.gitignore000066400000000000000000000001321405615720100153140ustar00rootroot00000000000000node_modules docs/* !docs/*.md !docs/*.1 !docs/layout/ dist logs components npm-debug.log luaparse-0.3.1/.jshintrc000066400000000000000000000004651405615720100151620ustar00rootroot00000000000000{ "curly": false, "eqeqeq": true, "forin": true, "immed": true, "latedef": false, "newcap": true, "noarg": true, "noempty": true, "nonew": true, "regexp": true, "undef": true, "trailing": true, "sub": true, "boss": true, "eqnull": true, "laxcomma": true, "loopfunc": false } luaparse-0.3.1/LICENSE000066400000000000000000000020541405615720100143360ustar00rootroot00000000000000Copyright (c) Oskar Schöldström 2012-2014 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. luaparse-0.3.1/Makefile000066400000000000000000000045751405615720100150030ustar00rootroot00000000000000DOCS := docs/*.md PROCESSOR ?= "/opt/v8/tools/linux-tick-processor" LIB := ./node_modules BIN := $(LIB)/.bin all: build # Main tasks # ---------- build: $(BIN)/gulp build lint: $(BIN)/gulp lint .PHONY: build lint all # Install and internal updates # ---------------------------- install: npm install # This is required if mocha, expect or benchmark is updated. update: cp -v $(LIB)/spec/lib/* test/lib/ cp -v $(LIB)/benchmark/benchmark.js test/lib/ version-bump: $(BIN)/gulp version-bump git add luaparse.js .PHONY: install update version-bump # Tests # ----- test-node: node test/runner.js --console test: $(BIN)/testem ci testem-engines: $(BIN)/testem -l node,ringo,rhino,rhino1.7R5 # Scaffold all test files in the scaffolding dir. scaffold-tests: $(foreach file,\ $(notdir $(wildcard test/scaffolding/*)),\ $(MAKE) scaffold-test FILE=$(file);\ ) scaffold-test: ./scripts/scaffold-test --name=$(FILE) \ test/scaffolding/$(FILE) \ > test/spec/$(FILE).js .PHONY: test-node test testem-engines scaffold-tests scaffold-test # Documentation # ------------- docs: coverage docs-test docs-md docs-index: $(BIN)/marked README.md --gfm \ | cat docs/layout/head.html - docs/layout/foot.html \ > docs/index.html docs-md: docs-index $(patsubst %.md,%.html, $(wildcard docs/*.md)) %.html: %.md echo $< $(BIN)/marked $< --gfm \ | cat docs/layout/head.html - docs/layout/foot.html \ > $@ .PHONY: docs docs-test docs-index # Coverage # -------- coverage: rm -rf html-report docs/coverage $(BIN)/nyc --reporter=html --report-dir=docs/coverage node test/runner.js --console >/dev/null .PHONY: coverage # Benchmark # --------- benchmark: ./scripts/benchmark -v benchmarks/lib/ParseLua.lua profile: bash benchmarks/run.sh -v --processor $(PROCESSOR) --profile HEAD benchmark-previous: bash benchmarks/run.sh --js HEAD HEAD~1 .PHONY: benchmark profile benchmark-previous # Quality Assurance # ----------------- complexity-analysis: @echo "===================== Complexity analysis ============================" ./scripts/complexity 10 $(BIN)/cr -lws --maxcc 22 luaparse.js coverage-analysis: coverage $(BIN)/nyc check-coverage --statements 100 --branches 100 --functions 100 qa: $(MAKE) test lint complexity-analysis coverage-analysis clean: rm -f docs/*.html rm -rf lib-cov coverage html-report docs/coverage/ .PHONY: complexity-analysis coverage-analysis qa clean luaparse-0.3.1/README.md000066400000000000000000000232071405615720100146130ustar00rootroot00000000000000# luaparse A Lua parser written in JavaScript, originally written by Oskar Schöldström for his bachelor's thesis at Arcada. ## Installation Install through `npm install luaparse`. ## Usage CommonJS ```js var parser = require('luaparse'); var ast = parser.parse('i = 0'); console.log(JSON.stringify(ast)); ``` AMD ```js require(['luaparse'], function(parser) { var ast = parser.parse('i = 0'); console.log(JSON.stringify(ast)); }); ``` Browser ```html ``` ## Parser Interface Basic usage: ```js luaparse.parse(code, options); ``` The output of the parser is an Abstract Syntax Tree (AST) formatted in JSON. The available options are: - `wait: false` Explicitly tell the parser when the input ends. - `comments: true` Store comments as an array in the chunk object. - `scope: false` Track identifier scopes. - `locations: false` Store location information on each syntax node. - `ranges: false` Store the start and end character locations on each syntax node. - `onCreateNode: null` A callback which will be invoked when a syntax node has been completed. The node which has been created will be passed as the only parameter. - `onCreateScope: null` A callback which will be invoked when a new scope is created. - `onDestroyScope: null` A callback which will be invoked when the current scope is destroyed. - `onLocalDeclaration: null` A callback which will be invoked when a local variable is declared. The identifier will be passed as the only parameter. - `luaVersion: '5.1'` The version of Lua the parser will target; supported values are `'5.1'`, `'5.2'`, `'5.3'` and `'LuaJIT'`. - `extendedIdentifiers: false` Whether to allow code points ≥ U+0080 in identifiers, like LuaJIT does. **Note:** setting `luaVersion: 'LuaJIT'` currently does *not* enable this option; this may change in the future. - `encodingMode: 'none'` Defines the relation between code points ≥ U+0080 appearing in parser input and raw bytes in source code, and how Lua escape sequences in JavaScript strings should be interpreted. See the [Encoding modes](#encoding-modes) section below for more information. The default options are also exposed through `luaparse.defaultOptions` where they can be overriden globally. There is a second interface which might be preferable when using the `wait` option. ```js var parser = luaparse.parse({ wait: true }); parser.write('foo = "'); parser.write('bar'); var ast = parser.end('"'); ``` This would be identical to: ```js var ast = luaparse.parse('foo = "bar"'); ``` ### AST format If the following code is executed: ```js luaparse.parse('foo = "bar"'); ``` then the returned value will be: ```js { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "foo" } ], "init": [ { "type": "StringLiteral", "value": "bar", "raw": "\"bar\"" } ] } ], "comments": [] } ``` ### Encoding modes Unlike strings in JavaScript, Lua strings are not Unicode strings, but bytestrings (sequences of 8-bit values); likewise, implementations of Lua parse the source code as a sequence of octets. However, the input to this parser is a JavaScript string, i.e. a sequence of 16-bit code units (not necessarily well-formed UTF-16). This poses a problem of how those code units should be interpreted, particularly if they are outside the Basic Latin block ('ASCII'). The `encodingMode` option specifies how these issues should be handled. Possible values are as follows: - `'none'`: Source code characters all pass through as-is and string literals are not interpreted at all; the string literal nodes contain the value `null`. This is the default mode. - `'x-user-defined'`: Source code has been decoded with the WHATWG `x-user-defined` encoding; escapes of bytes in the range \[0x80, 0xff] are mapped to the Unicode range \[U+F780, U+F7FF]. - `'pseudo-latin1'`: Source code has been decoded with the IANA `iso-8859-1` encoding; escapes of bytes in the range \[0x80, 0xff] are mapped to Unicode range \[U+0080, U+00FF]. Note that this is **not** the same as how WHATWG standards define the `iso-8859-1` encoding, which is to say, as a synonym of `windows-1252`. ### Custom AST The default AST structure is somewhat inspired by the Mozilla Parser API but can easily be overriden to customize the structure or to inject custom logic. `luaparse.ast` is an object containing all functions used to create the AST, if you for example wanted to trigger an event on node creations you could use the following: ```js var luaparse = require('luaparse'), events = new (require('events').EventEmitter); Object.keys(luaparse.ast).forEach(function(type) { var original = luaparse.ast[type]; luaparse.ast[type] = function() { var node = original.apply(null, arguments); events.emit(node.type, node); return node; }; }); events.on('Identifier', function(node) { console.log(node); }); luaparse.parse('i = "foo"'); ``` _this is only an example to illustrate what is possible and this particular example might not suit your needs as the end location of the node has not been determined yet. If you desire events you should use the `onCreateNode` callback instead)._ ### Lexer The lexer used by luaparse can be used independently of the recursive descent parser. The lex function is exposed as `luaparse.lex()` and it will return the next token up until `EOF` is reached. Each token consists of: - `type` expressed as an enum flag which can be matched with `luaparse.tokenTypes`. - `value` - `line`, `lineStart` - `range` can be used to slice out raw values, eg. `foo = "bar"` will return a `StringLiteral` token with the value `bar`. Slicing out the range on the other hand will return `"bar"`. ```js var parser = luaparse.parse('foo = "bar"', { wait: true }); parser.lex(); // { type: 8, value: "foo", line: 1, lineStart: 0, range: [0, 3] } parser.lex(); // { type: 32, value: "=", line: 1, lineStart: 0, range: [4, 5]} parser.lex(); // { type: 2, value: "bar", line: 1, lineStart: 0, range: [6, 11] } parser.lex(); // { type: 1, value: "", line: 1, lineStart: 0, range: [11 11] } parser.lex(); // { type: 1, value: "", line: 1, lineStart: 0, range: [11 11] } ``` ## Examples Have a look in the [examples directory](https://github.com/fstirlitz/luaparse/tree/master/examples) of the repository for some code examples or check them out [live](https://fstirlitz.github.io/luaparse/examples.html). ## luaparse(1) The `luaparse` executable can be used in your shell by installing `luaparse` globally using npm: ```bash $ npm install -g luaparse $ luaparse --help Usage: luaparse [option]... [file|code]... Options: -c|--code [code] parse code snippet -f|--file [file] parse from file -b|--beautify output an indenteted AST --[no]-comments store comments. defaults to true --[no]-scope store variable scope. defaults to false --[no]-locations store location data on syntax nodes. defaults to false --[no]-ranges store start and end character locations. defaults to false -q|--quiet suppress output -h|--help -v|--version --verbose Examples: luaparse --no-comments -c "locale foo = \"bar\"" luaparse foo.lua bar.lua ``` Example usage ```bash $ luaparse "i = 0" {"type":"Chunk","body":[{"type":"AssignmentStatement","variables":[{"type":"Identifier","name":"i"}],"init":[{"type":"NumericLiteral","value":0,"raw":"0"}]}],"comments":[]} ``` ## Support Has been tested in at least IE6+, Firefox 3+, Safari 4+, Chrome 10+, Opera 10+, Node 0.4.0+, RingoJS 0.8-0.9, Rhino 1.7R4-1.7R5, Nashorn 1.8.0. ## Quality Assurance _TL;DR simply run `make qa`. This will run all quality assurance scripts but assumes you have it set up correctly._ Begin by cloning the repository and installing the development dependencies with `npm install`. The luaparse test suite uses [testem](https://github.com/airportyh/testem) as a test runner, and because of this it's very easy to run the tests using different javascript engines or even on locally installed browsers. ### Test runners - `make test` uses node. - `make testem-engines` uses node, ringo and rhino 1.7R5. This requires that you have the engines installed. - `make test-node` uses a custom command line reporter to make the output easier on the eyes while practicing TDD. - By installing `testem` globally you can also run the tests in a locally installed browser. ### Other quality assurance measures - You can check the function complexity using [complexity-report](https://github.com/philbooth/complexityReport.js) using `make complexity-analysis` - Running `make coverage` will generate the [coverage report](https://fstirlitz.github.io/luaparse/coverage.html). To simply check that all code has coverage you can run `make coverage-analysis`. - `make lint`, `make benchmark`, `make profile`. ### Documentation By running `make docs` all [documentation](https://fstirlitz.github.io/luaparse/) will be generated. ## Projects using/extending luaparse - [luamin](http://mths.be/luamin), a Lua minifier written by Mathias Bynens. - [Ace](https://github.com/ajaxorg/ace), an online code editor. ## Acknowledgements * Initial tests are scaffolded from [yueliang][yueliang] and then manually checked for error. * Much of the code is based on [LuaMinify][luaminify], the [Lua][lua] source and [Esprima][esprima]. All awesome projects. ## License MIT [luaminify]: https://github.com/stravant/LuaMinify [yueliang]: http://yueliang.luaforge.net/ [lua]: https://www.lua.org [esprima]: http://esprima.org [wtf8]: https://simonsapin.github.io/wtf-8/ luaparse-0.3.1/benchmarks/000077500000000000000000000000001405615720100154455ustar00rootroot00000000000000luaparse-0.3.1/benchmarks/lib/000077500000000000000000000000001405615720100162135ustar00rootroot00000000000000luaparse-0.3.1/benchmarks/lib/ParseLua.lua000066400000000000000000000753101405615720100204400ustar00rootroot00000000000000-- LuaMinify (Mark Langen) https://github.com/stravant/LuaMinify -- -- ParseLua.lua -- -- The main lua parser and lexer. -- LexLua returns a Lua token stream, with tokens that preserve -- all whitespace formatting information. -- ParseLua returns an AST, internally relying on LexLua. -- function lookupify(tb) for _, v in pairs(tb) do tb[v] = true end return tb end function CountTable(tb) local c = 0 for _ in pairs(tb) do c = c + 1 end return c end function PrintTable(tb, atIndent) if tb.Print then return tb.Print() end atIndent = atIndent or 0 local useNewlines = (CountTable(tb) > 1) local baseIndent = string.rep(' ', atIndent+1) local out = "{"..(useNewlines and '\n' or '') for k, v in pairs(tb) do if type(v) ~= 'function' then out = out..(useNewlines and baseIndent or '') if type(k) == 'number' then --nothing to do elseif type(k) == 'string' and k:match("^[A-Za-z_][A-Za-z0-9_]*$") then out = out..k.." = " elseif type(k) == 'string' then out = out.."[\""..k.."\"] = " else out = out.."["..tostring(k).."] = " end if type(v) == 'string' then out = out.."\""..v.."\"" elseif type(v) == 'number' then out = out..v elseif type(v) == 'table' then out = out..PrintTable(v, atIndent+(useNewlines and 1 or 0)) else out = out..tostring(v) end if next(tb, k) then out = out.."," end if useNewlines then out = out..'\n' end end end out = out..(useNewlines and string.rep(' ', atIndent) or '').."}" return out end local WhiteChars = lookupify{' ', '\n', '\t', '\r'} local EscapeLookup = {['\r'] = '\\r', ['\n'] = '\\n', ['\t'] = '\\t', ['"'] = '\\"', ["'"] = "\\'"} local LowerChars = lookupify{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'} local UpperChars = lookupify{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'} local Digits = lookupify{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} local HexDigits = lookupify{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f'} local Symbols = lookupify{'+', '-', '*', '/', '^', '%', ',', '{', '}', '[', ']', '(', ')', ';', '#'} local Keywords = lookupify{ 'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'goto', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while', }; function LexLua(src) --token dump local tokens = {} local st, err = pcall(function() --line / char / pointer tracking local p = 1 local line = 1 local char = 1 --get / peek functions local function get() local c = src:sub(p,p) if c == '\n' then char = 1 line = line + 1 else char = char + 1 end p = p + 1 return c end local function peek(n) n = n or 0 return src:sub(p+n,p+n) end local function consume(chars) local c = peek() for i = 1, #chars do if c == chars:sub(i,i) then return get() end end end --shared stuff local function generateError(err) return error(">> :"..line..":"..char..": "..err, 0) end local function tryGetLongString() local start = p if peek() == '[' then local equalsCount = 0 while peek(equalsCount+1) == '=' do equalsCount = equalsCount + 1 end if peek(equalsCount+1) == '[' then --start parsing the string. Strip the starting bit for _ = 0, equalsCount+1 do get() end --get the contents local contentStart = p while true do --check for eof if peek() == '' then generateError("Expected `]"..string.rep('=', equalsCount).."]` near .", 3) end --check for the end local foundEnd = true if peek() == ']' then for i = 1, equalsCount do if peek(i) ~= '=' then foundEnd = false end end if peek(equalsCount+1) ~= ']' then foundEnd = false end else foundEnd = false end -- if foundEnd then break else get() end end --get the interior string local contentString = src:sub(contentStart, p-1) --found the end. Get rid of the trailing bit for i = 0, equalsCount+1 do get() end --get the exterior string local longString = src:sub(start, p-1) --return the stuff return contentString, longString else return nil end else return nil end end --main token emitting loop while true do --get leading whitespace. The leading whitespace will include any comments --preceding the token. This prevents the parser needing to deal with comments --separately. local leadingWhite = '' while true do local c = peek() if WhiteChars[c] then --whitespace leadingWhite = leadingWhite..get() elseif c == '-' and peek(1) == '-' then --comment get();get() leadingWhite = leadingWhite..'--' local _, wholeText = tryGetLongString() if wholeText then leadingWhite = leadingWhite..wholeText else while peek() ~= '\n' and peek() ~= '' do leadingWhite = leadingWhite..get() end end else break end end --get the initial char local thisLine = line local thisChar = char local errorAt = ":"..line..":"..char..":> " local c = peek() --symbol to emit local toEmit = nil --branch on type if c == '' then --eof toEmit = {Type = 'Eof'} elseif UpperChars[c] or LowerChars[c] or c == '_' then --ident or keyword local start = p repeat get() c = peek() until not (UpperChars[c] or LowerChars[c] or Digits[c] or c == '_') local dat = src:sub(start, p-1) if Keywords[dat] then toEmit = {Type = 'Keyword', Data = dat} else toEmit = {Type = 'Ident', Data = dat} end elseif Digits[c] or (peek() == '.' and Digits[peek(1)]) then --number const local start = p if c == '0' and peek(1) == 'x' then get();get() while HexDigits[peek()] do get() end if consume('Pp') then consume('+-') while Digits[peek()] do get() end end else while Digits[peek()] do get() end if consume('.') then while Digits[peek()] do get() end end if consume('Ee') then consume('+-') while Digits[peek()] do get() end end end toEmit = {Type = 'Number', Data = src:sub(start, p-1)} elseif c == '\'' or c == '\"' then local start = p --string const local delim = get() local contentStart = p while true do local c = get() if c == '\\' then get() --get the escape char elseif c == delim then break elseif c == '' then generateError("Unfinished string near ") end end local content = src:sub(contentStart, p-2) local constant = src:sub(start, p-1) toEmit = {Type = 'String', Data = constant, Constant = content} elseif c == '[' then local content, wholetext = tryGetLongString() if wholetext then toEmit = {Type = 'String', Data = wholetext, Constant = content} else get() toEmit = {Type = 'Symbol', Data = '['} end elseif consume('>=<') then if consume('=') then toEmit = {Type = 'Symbol', Data = c..'='} else toEmit = {Type = 'Symbol', Data = c} end elseif consume('~') then if consume('=') then toEmit = {Type = 'Symbol', Data = '~='} else generateError("Unexpected symbol `~` in source.", 2) end elseif consume('.') then if consume('.') then if consume('.') then toEmit = {Type = 'Symbol', Data = '...'} else toEmit = {Type = 'Symbol', Data = '..'} end else toEmit = {Type = 'Symbol', Data = '.'} end elseif consume(':') then if consume(':') then toEmit = {Type = 'Symbol', Data = '::'} else toEmit = {Type = 'Symbol', Data = ':'} end elseif Symbols[c] then get() toEmit = {Type = 'Symbol', Data = c} else local contents, all = tryGetLongString() if contents then toEmit = {Type = 'String', Data = all, Constant = contents} else generateError("Unexpected Symbol `"..c.."` in source.", 2) end end --add the emitted symbol, after adding some common data toEmit.LeadingWhite = leadingWhite toEmit.Line = thisLine toEmit.Char = thisChar toEmit.Print = function() return "<"..(toEmit.Type..string.rep(' ', 7-#toEmit.Type)).." "..(toEmit.Data or '').." >" end tokens[#tokens+1] = toEmit --halt after eof has been emitted if toEmit.Type == 'Eof' then break end end end) if not st then return false, err end --public interface: local tok = {} local savedP = {} local p = 1 --getters function tok:Peek(n) n = n or 0 return tokens[math.min(#tokens, p+n)] end function tok:Get() local t = tokens[p] p = math.min(p + 1, #tokens) return t end function tok:Is(t) return tok:Peek().Type == t end --save / restore points in the stream function tok:Save() savedP[#savedP+1] = p end function tok:Commit() savedP[#savedP] = nil end function tok:Restore() p = savedP[#savedP] savedP[#savedP] = nil end --either return a symbol if there is one, or return true if the requested --symbol was gotten. function tok:ConsumeSymbol(symb) local t = self:Peek() if t.Type == 'Symbol' then if symb then if t.Data == symb then self:Get() return true else return nil end else self:Get() return t end else return nil end end function tok:ConsumeKeyword(kw) local t = self:Peek() if t.Type == 'Keyword' and t.Data == kw then self:Get() return true else return nil end end function tok:IsKeyword(kw) local t = tok:Peek() return t.Type == 'Keyword' and t.Data == kw end function tok:IsSymbol(s) local t = tok:Peek() return t.Type == 'Symbol' and t.Data == s end function tok:IsEof() return tok:Peek().Type == 'Eof' end return true, tok end function ParseLua(src) local st, tok = LexLua(src) if not st then return false, tok end -- local function GenerateError(msg) local err = ">> :"..tok:Peek().Line..":"..tok:Peek().Char..": "..msg.."\n" --find the line local lineNum = 0 for line in src:gmatch("[^\n]*\n?") do if line:sub(-1,-1) == '\n' then line = line:sub(1,-2) end lineNum = lineNum+1 if lineNum == tok:Peek().Line then err = err..">> `"..line:gsub('\t',' ').."`\n" for i = 1, tok:Peek().Char do local c = line:sub(i,i) if c == '\t' then err = err..' ' else err = err..' ' end end err = err.." ^---" break end end return err end -- local VarUid = 0 local GlobalVarGetMap = {} local VarDigits = {'_', 'a', 'b', 'c', 'd'} local function CreateScope(parent) local scope = {} scope.Parent = parent scope.LocalList = {} scope.LocalMap = {} function scope:RenameVars() for _, var in pairs(scope.LocalList) do local id; VarUid = 0 repeat VarUid = VarUid + 1 local varToUse = VarUid id = '' while varToUse > 0 do local d = varToUse % #VarDigits varToUse = (varToUse - d) / #VarDigits id = id..VarDigits[d+1] end until not GlobalVarGetMap[id] and not parent:GetLocal(id) and not scope.LocalMap[id] var.Name = id scope.LocalMap[id] = var end end function scope:GetLocal(name) --first, try to get my variable local my = scope.LocalMap[name] if my then return my end --next, try parent if scope.Parent then local par = scope.Parent:GetLocal(name) if par then return par end end return nil end function scope:CreateLocal(name) --create my own var local my = {} my.Scope = scope my.Name = name my.CanRename = true -- scope.LocalList[#scope.LocalList+1] = my scope.LocalMap[name] = my -- return my end scope.Print = function() return "" end return scope end local ParseExpr; local ParseStatementList; local function ParseFunctionArgsAndBody(scope) local funcScope = CreateScope(scope) if not tok:ConsumeSymbol('(') then return false, GenerateError("`(` expected.") end --arg list local argList = {} local isVarArg = false while not tok:ConsumeSymbol(')') do if tok:Is('Ident') then local arg = funcScope:CreateLocal(tok:Get().Data) argList[#argList+1] = arg if not tok:ConsumeSymbol(',') then if tok:ConsumeSymbol(')') then break else return false, GenerateError("`)` expected.") end end elseif tok:ConsumeSymbol('...') then isVarArg = true if not tok:ConsumeSymbol(')') then return false, GenerateError("`...` must be the last argument of a function.") end break else return false, GenerateError("Argument name or `...` expected") end end --body local st, body = ParseStatementList(funcScope) if not st then return false, body end --end if not tok:ConsumeKeyword('end') then return false, GenerateError("`end` expected after function body") end local nodeFunc = {} nodeFunc.AstType = 'Function' nodeFunc.Scope = funcScope nodeFunc.Arguments = argList nodeFunc.Body = body nodeFunc.VarArg = isVarArg -- return true, nodeFunc end local function ParsePrimaryExpr(scope) if tok:ConsumeSymbol('(') then local st, ex = ParseExpr(scope) if not st then return false, ex end if not tok:ConsumeSymbol(')') then return false, GenerateError("`)` Expected.") end --save the information about parenthesized expressions somewhere ex.ParenCount = (ex.ParenCount or 0) + 1 return true, ex elseif tok:Is('Ident') then local id = tok:Get() local var = scope:GetLocal(id.Data) if not var then GlobalVarGetMap[id.Data] = true end -- local nodePrimExp = {} nodePrimExp.AstType = 'VarExpr' nodePrimExp.Name = id.Data nodePrimExp.Local = var -- return true, nodePrimExp else return false, GenerateError("primary expression expected") end end local function ParseSuffixedExpr(scope, onlyDotColon) --base primary expression local st, prim = ParsePrimaryExpr(scope) if not st then return false, prim end -- while true do if tok:IsSymbol('.') or tok:IsSymbol(':') then local symb = tok:Get().Data if not tok:Is('Ident') then return false, GenerateError(" expected.") end local id = tok:Get() local nodeIndex = {} nodeIndex.AstType = 'MemberExpr' nodeIndex.Base = prim nodeIndex.Indexer = symb nodeIndex.Ident = id -- prim = nodeIndex elseif not onlyDotColon and tok:ConsumeSymbol('[') then local st, ex = ParseExpr(scope) if not st then return false, ex end if not tok:ConsumeSymbol(']') then return false, GenerateError("`]` expected.") end local nodeIndex = {} nodeIndex.AstType = 'IndexExpr' nodeIndex.Base = prim nodeIndex.Index = ex -- prim = nodeIndex elseif not onlyDotColon and tok:ConsumeSymbol('(') then local args = {} while not tok:ConsumeSymbol(')') do local st, ex = ParseExpr(scope) if not st then return false, ex end args[#args+1] = ex if not tok:ConsumeSymbol(',') then if tok:ConsumeSymbol(')') then break else return false, GenerateError("`)` Expected.") end end end local nodeCall = {} nodeCall.AstType = 'CallExpr' nodeCall.Base = prim nodeCall.Arguments = args -- prim = nodeCall elseif not onlyDotColon and tok:Is('String') then --string call local nodeCall = {} nodeCall.AstType = 'StringCallExpr' nodeCall.Base = prim nodeCall.Arguments = {tok:Get()} -- prim = nodeCall elseif not onlyDotColon and tok:IsSymbol('{') then --table call local st, ex = ParseExpr(scope) if not st then return false, ex end local nodeCall = {} nodeCall.AstType = 'TableCallExpr' nodeCall.Base = prim nodeCall.Arguments = {ex} -- prim = nodeCall else break end end return true, prim end local function ParseSimpleExpr(scope) if tok:Is('Number') then local nodeNum = {} nodeNum.AstType = 'NumberExpr' nodeNum.Value = tok:Get() return true, nodeNum elseif tok:Is('String') then local nodeStr = {} nodeStr.AstType = 'StringExpr' nodeStr.Value = tok:Get() return true, nodeStr elseif tok:ConsumeKeyword('nil') then local nodeNil = {} nodeNil.AstType = 'NilExpr' return true, nodeNil elseif tok:IsKeyword('false') or tok:IsKeyword('true') then local nodeBoolean = {} nodeBoolean.AstType = 'BooleanExpr' nodeBoolean.Value = (tok:Get().Data == 'true') return true, nodeBoolean elseif tok:ConsumeSymbol('...') then local nodeDots = {} nodeDots.AstType = 'DotsExpr' return true, nodeDots elseif tok:ConsumeSymbol('{') then local v = {} v.AstType = 'ConstructorExpr' v.EntryList = {} -- while true do if tok:IsSymbol('[') then --key tok:Get() local st, key = ParseExpr(scope) if not st then return false, GenerateError("Key Expression Expected") end if not tok:ConsumeSymbol(']') then return false, GenerateError("`]` Expected") end if not tok:ConsumeSymbol('=') then return false, GenerateError("`=` Expected") end local st, value = ParseExpr(scope) if not st then return false, GenerateError("Value Expression Expected") end v.EntryList[#v.EntryList+1] = { Type = 'Key'; Key = key; Value = value; } elseif tok:Is('Ident') then --value or key local lookahead = tok:Peek(1) if lookahead.Type == 'Symbol' and lookahead.Data == '=' then --we are a key local key = tok:Get() if not tok:ConsumeSymbol('=') then return false, GenerateError("`=` Expected") end local st, value = ParseExpr(scope) if not st then return false, GenerateError("Value Expression Expected") end v.EntryList[#v.EntryList+1] = { Type = 'KeyString'; Key = key.Data; Value = value; } else --we are a value local st, value = ParseExpr(scope) if not st then return false, GenerateError("Value Exected") end v.EntryList[#v.EntryList+1] = { Type = 'Value'; Value = value; } end elseif tok:ConsumeSymbol('}') then break else --value local st, value = ParseExpr(scope) v.EntryList[#v.EntryList+1] = { Type = 'Value'; Value = value; } if not st then return false, GenerateError("Value Expected") end end if tok:ConsumeSymbol(';') or tok:ConsumeSymbol(',') then --all is good elseif tok:ConsumeSymbol('}') then break else return false, GenerateError("`}` or table entry Expected") end end return true, v elseif tok:ConsumeKeyword('function') then local st, func = ParseFunctionArgsAndBody(scope) if not st then return false, func end -- func.IsLocal = true return true, func else return ParseSuffixedExpr(scope) end end local unops = lookupify{'-', 'not', '#'} local unopprio = 8 local priority = { ['+'] = {6,6}; ['-'] = {6,6}; ['%'] = {7,7}; ['/'] = {7,7}; ['*'] = {7,7}; ['^'] = {10,9}; ['..'] = {5,4}; ['=='] = {3,3}; ['<'] = {3,3}; ['<='] = {3,3}; ['~='] = {3,3}; ['>'] = {3,3}; ['>='] = {3,3}; ['and'] = {2,2}; ['or'] = {1,1}; } local function ParseSubExpr(scope, level) --base item, possibly with unop prefix local st, exp if unops[tok:Peek().Data] then local op = tok:Get().Data st, exp = ParseSubExpr(scope, unopprio) if not st then return false, exp end local nodeEx = {} nodeEx.AstType = 'UnopExpr' nodeEx.Rhs = exp nodeEx.Op = op exp = nodeEx else st, exp = ParseSimpleExpr(scope) if not st then return false, exp end end --next items in chain while true do local prio = priority[tok:Peek().Data] if prio and prio[1] > level then local op = tok:Get().Data local st, rhs = ParseSubExpr(scope, prio[2]) if not st then return false, rhs end local nodeEx = {} nodeEx.AstType = 'BinopExpr' nodeEx.Lhs = exp nodeEx.Op = op nodeEx.Rhs = rhs -- exp = nodeEx else break end end return true, exp end ParseExpr = function(scope) return ParseSubExpr(scope, 0) end local function ParseStatement(scope) local stat = nil if tok:ConsumeKeyword('if') then --setup local nodeIfStat = {} nodeIfStat.AstType = 'IfStatement' nodeIfStat.Clauses = {} --clauses repeat local st, nodeCond = ParseExpr(scope) if not st then return false, nodeCond end if not tok:ConsumeKeyword('then') then return false, GenerateError("`then` expected.") end local st, nodeBody = ParseStatementList(scope) if not st then return false, nodeBody end nodeIfStat.Clauses[#nodeIfStat.Clauses+1] = { Condition = nodeCond; Body = nodeBody; } until not tok:ConsumeKeyword('elseif') --else clause if tok:ConsumeKeyword('else') then local st, nodeBody = ParseStatementList(scope) if not st then return false, nodeBody end nodeIfStat.Clauses[#nodeIfStat.Clauses+1] = { Body = nodeBody; } end --end if not tok:ConsumeKeyword('end') then return false, GenerateError("`end` expected.") end stat = nodeIfStat elseif tok:ConsumeKeyword('while') then --setup local nodeWhileStat = {} nodeWhileStat.AstType = 'WhileStatement' --condition local st, nodeCond = ParseExpr(scope) if not st then return false, nodeCond end --do if not tok:ConsumeKeyword('do') then return false, GenerateError("`do` expected.") end --body local st, nodeBody = ParseStatementList(scope) if not st then return false, nodeBody end --end if not tok:ConsumeKeyword('end') then return false, GenerateError("`end` expected.") end --return nodeWhileStat.Condition = nodeCond nodeWhileStat.Body = nodeBody stat = nodeWhileStat elseif tok:ConsumeKeyword('do') then --do block local st, nodeBlock = ParseStatementList(scope) if not st then return false, nodeBlock end if not tok:ConsumeKeyword('end') then return false, GenerateError("`end` expected.") end local nodeDoStat = {} nodeDoStat.AstType = 'DoStatement' nodeDoStat.Body = nodeBlock stat = nodeDoStat elseif tok:ConsumeKeyword('for') then --for block if not tok:Is('Ident') then return false, GenerateError(" expected.") end local baseVarName = tok:Get() if tok:ConsumeSymbol('=') then --numeric for local forScope = CreateScope(scope) local forVar = forScope:CreateLocal(baseVarName.Data) -- local st, startEx = ParseExpr(scope) if not st then return false, startEx end if not tok:ConsumeSymbol(',') then return false, GenerateError("`,` Expected") end local st, endEx = ParseExpr(scope) if not st then return false, endEx end local st, stepEx; if tok:ConsumeSymbol(',') then st, stepEx = ParseExpr(scope) if not st then return false, stepEx end end if not tok:ConsumeKeyword('do') then return false, GenerateError("`do` expected") end -- local st, body = ParseStatementList(forScope) if not st then return false, body end if not tok:ConsumeKeyword('end') then return false, GenerateError("`end` expected") end -- local nodeFor = {} nodeFor.AstType = 'NumericForStatement' nodeFor.Scope = forScope nodeFor.Variable = forVar nodeFor.Start = startEx nodeFor.End = endEx nodeFor.Step = stepEx nodeFor.Body = body stat = nodeFor else --generic for local forScope = CreateScope(scope) -- local varList = {forScope:CreateLocal(baseVarName.Data)} while tok:ConsumeSymbol(',') do if not tok:Is('Ident') then return false, GenerateError("for variable expected.") end varList[#varList+1] = forScope:CreateLocal(tok:Get().Data) end if not tok:ConsumeKeyword('in') then return false, GenerateError("`in` expected.") end local generators = {} local st, firstGenerator = ParseExpr(scope) if not st then return false, firstGenerator end generators[#generators+1] = firstGenerator while tok:ConsumeSymbol(',') do local st, gen = ParseExpr(scope) if not st then return false, gen end generators[#generators+1] = gen end if not tok:ConsumeKeyword('do') then return false, GenerateError("`do` expected.") end local st, body = ParseStatementList(forScope) if not st then return false, body end if not tok:ConsumeKeyword('end') then return false, GenerateError("`end` expected.") end -- local nodeFor = {} nodeFor.AstType = 'GenericForStatement' nodeFor.Scope = forScope nodeFor.VariableList = varList nodeFor.Generators = generators nodeFor.Body = body stat = nodeFor end elseif tok:ConsumeKeyword('repeat') then local st, body = ParseStatementList(scope) if not st then return false, body end -- if not tok:ConsumeKeyword('until') then return false, GenerateError("`until` expected.") end -- local st, cond = ParseExpr(scope) if not st then return false, cond end -- local nodeRepeat = {} nodeRepeat.AstType = 'RepeatStatement' nodeRepeat.Condition = cond nodeRepeat.Body = body stat = nodeRepeat elseif tok:ConsumeKeyword('function') then if not tok:Is('Ident') then return false, GenerateError("Function name expected") end local st, name = ParseSuffixedExpr(scope, true) --true => only dots and colons if not st then return false, name end -- local st, func = ParseFunctionArgsAndBody(scope) if not st then return false, func end -- func.IsLocal = false func.Name = name stat = func elseif tok:ConsumeKeyword('local') then if tok:Is('Ident') then local varList = {tok:Get().Data} while tok:ConsumeSymbol(',') do if not tok:Is('Ident') then return false, GenerateError("local var name expected") end varList[#varList+1] = tok:Get().Data end local initList = {} if tok:ConsumeSymbol('=') then repeat local st, ex = ParseExpr(scope) if not st then return false, ex end initList[#initList+1] = ex until not tok:ConsumeSymbol(',') end --now patch var list --we can't do this before getting the init list, because the init list does not --have the locals themselves in scope. for i, v in pairs(varList) do varList[i] = scope:CreateLocal(v) end local nodeLocal = {} nodeLocal.AstType = 'LocalStatement' nodeLocal.LocalList = varList nodeLocal.InitList = initList -- stat = nodeLocal elseif tok:ConsumeKeyword('function') then if not tok:Is('Ident') then return false, GenerateError("Function name expected") end local name = tok:Get().Data local localVar = scope:CreateLocal(name) -- local st, func = ParseFunctionArgsAndBody(scope) if not st then return false, func end -- func.Name = localVar func.IsLocal = true stat = func else return false, GenerateError("local var or function def expected") end elseif tok:ConsumeSymbol('::') then if not tok:Is('Ident') then return false, GenerateError('Label name expected') end local label = tok:Get().Data if not tok:ConsumeSymbol('::') then return false, GenerateError("`::` expected") end local nodeLabel = {} nodeLabel.AstType = 'LabelStatement' nodeLabel.Label = label stat = nodeLabel elseif tok:ConsumeKeyword('return') then local exList = {} if not tok:IsKeyword('end') then local st, firstEx = ParseExpr(scope) if st then exList[1] = firstEx while tok:ConsumeSymbol(',') do local st, ex = ParseExpr(scope) if not st then return false, ex end exList[#exList+1] = ex end end end local nodeReturn = {} nodeReturn.AstType = 'ReturnStatement' nodeReturn.Arguments = exList stat = nodeReturn elseif tok:ConsumeKeyword('break') then local nodeBreak = {} nodeBreak.AstType = 'BreakStatement' stat = nodeBreak elseif tok:IsKeyword('goto') then if not tok:Is('Ident') then return false, GenerateError("Label expected") end local label = tok:Get().Data local nodeGoto = {} nodeGoto.AstType = 'GotoStatement' nodeGoto.Label = label stat = nodeGoto else --statementParseExpr local st, suffixed = ParseSuffixedExpr(scope) if not st then return false, suffixed end --assignment or call? if tok:IsSymbol(',') or tok:IsSymbol('=') then --check that it was not parenthesized, making it not an lvalue if (suffixed.ParenCount or 0) > 0 then return false, GenerateError("Can not assign to parenthesized expression, is not an lvalue") end --more processing needed local lhs = {suffixed} while tok:ConsumeSymbol(',') do local st, lhsPart = ParseSuffixedExpr(scope) if not st then return false, lhsPart end lhs[#lhs+1] = lhsPart end --equals if not tok:ConsumeSymbol('=') then return false, GenerateError("`=` Expected.") end --rhs local rhs = {} local st, firstRhs = ParseExpr(scope) if not st then return false, firstRhs end rhs[1] = firstRhs while tok:ConsumeSymbol(',') do local st, rhsPart = ParseExpr(scope) if not st then return false, rhsPart end rhs[#rhs+1] = rhsPart end --done local nodeAssign = {} nodeAssign.AstType = 'AssignmentStatement' nodeAssign.Lhs = lhs nodeAssign.Rhs = rhs stat = nodeAssign elseif suffixed.AstType == 'CallExpr' or suffixed.AstType == 'TableCallExpr' or suffixed.AstType == 'StringCallExpr' then --it's a call statement local nodeCall = {} nodeCall.AstType = 'CallStatement' nodeCall.Expression = suffixed stat = nodeCall else return false, GenerateError("Assignment Statement Expected") end end stat.HasSemicolon = tok:ConsumeSymbol(';') return true, stat end local statListCloseKeywords = lookupify{'end', 'else', 'elseif', 'until'} ParseStatementList = function(scope) local nodeStatlist = {} nodeStatlist.Scope = CreateScope(scope) nodeStatlist.AstType = 'Statlist' -- local stats = {} -- while not statListCloseKeywords[tok:Peek().Data] and not tok:IsEof() do local st, nodeStatement = ParseStatement(nodeStatlist.Scope) if not st then return false, nodeStatement end stats[#stats+1] = nodeStatement end -- nodeStatlist.Body = stats return true, nodeStatlist end local function mainfunc() local topScope = CreateScope() return ParseStatementList(topScope) end local st, main = mainfunc() --print("Last Token: "..PrintTable(tok:Peek())) return st, main end luaparse-0.3.1/benchmarks/lib/transform.lua000066400000000000000000001106641405615720100207410ustar00rootroot00000000000000-- MoonScript http://moonscript.org -- https://github.com/leafo/moonscript local types = require("moonscript.types") local util = require("moonscript.util") local data = require("moonscript.data") local reversed = util.reversed local ntype, mtype, build, smart_node, is_slice, value_is_singular = types.ntype, types.mtype, types.build, types.smart_node, types.is_slice, types.value_is_singular local insert = table.insert local NameProxy, LocalName do local _table_0 = require("moonscript.transform.names") NameProxy, LocalName = _table_0.NameProxy, _table_0.LocalName end local destructure = require("moonscript.transform.destructure") local implicitly_return local Run do local _parent_0 = nil local _base_0 = { call = function(self, state) return self.fn(state) end } _base_0.__index = _base_0 if _parent_0 then setmetatable(_base_0, _parent_0.__base) end local _class_0 = setmetatable({ __init = function(self, fn) self.fn = fn self[1] = "run" end, __base = _base_0, __name = "Run", __parent = _parent_0 }, { __index = function(cls, name) local val = rawget(_base_0, name) if val == nil and _parent_0 then return _parent_0[name] else return val end end, __call = function(cls, ...) local _self_0 = setmetatable({}, _base_0) cls.__init(_self_0, ...) return _self_0 end }) _base_0.__class = _class_0 if _parent_0 and _parent_0.__inherited then _parent_0.__inherited(_parent_0, _class_0) end Run = _class_0 end local apply_to_last apply_to_last = function(stms, fn) local last_exp_id = 0 for i = #stms, 1, -1 do local stm = stms[i] if stm and mtype(stm) ~= Run then last_exp_id = i break end end return (function() local _accum_0 = { } local _len_0 = 0 for i, stm in ipairs(stms) do local _value_0 if i == last_exp_id then _value_0 = fn(stm) else _value_0 = stm end if _value_0 ~= nil then _len_0 = _len_0 + 1 _accum_0[_len_0] = _value_0 end end return _accum_0 end)() end local is_singular is_singular = function(body) if #body ~= 1 then return false end if "group" == ntype(body) then return is_singular(body[2]) else return true end end local find_assigns find_assigns = function(body, out) if out == nil then out = { } end local _list_0 = body for _index_0 = 1, #_list_0 do local thing = _list_0[_index_0] local _exp_0 = thing[1] if "group" == _exp_0 then find_assigns(thing[2], out) elseif "assign" == _exp_0 then table.insert(out, thing[2]) end end return out end local hoist_declarations hoist_declarations = function(body) local assigns = { } local _list_0 = find_assigns(body) for _index_0 = 1, #_list_0 do local names = _list_0[_index_0] local _list_1 = names for _index_1 = 1, #_list_1 do local name = _list_1[_index_1] if type(name) == "string" then table.insert(assigns, name) end end end local idx = 1 while mtype(body[idx]) == Run do idx = idx + 1 end return table.insert(body, idx, { "declare", assigns }) end local expand_elseif_assign expand_elseif_assign = function(ifstm) for i = 4, #ifstm do local case = ifstm[i] if ntype(case) == "elseif" and ntype(case[2]) == "assign" then local split = { unpack(ifstm, 1, i - 1) } insert(split, { "else", { { "if", case[2], case[3], unpack(ifstm, i + 1) } } }) return split end end return ifstm end local constructor_name = "new" local with_continue_listener with_continue_listener = function(body) local continue_name = nil return { Run(function(self) return self:listen("continue", function() if not (continue_name) then continue_name = NameProxy("continue") self:put_name(continue_name) end return continue_name end) end), build.group(body), Run(function(self) if not (continue_name) then return end self:put_name(continue_name, nil) return self:splice(function(lines) return { { "assign", { continue_name }, { "false" } }, { "repeat", "true", { lines, { "assign", { continue_name }, { "true" } } } }, { "if", { "not", continue_name }, { { "break" } } } } end) end) } end local Transformer do local _parent_0 = nil local _base_0 = { transform = function(self, scope, node, ...) if self.seen_nodes[node] then return node end self.seen_nodes[node] = true while true do local transformer = self.transformers[ntype(node)] local res if transformer then res = transformer(scope, node, ...) or node else res = node end if res == node then return node end node = res end return node end, bind = function(self, scope) return function(...) return self:transform(scope, ...) end end, __call = function(self, ...) return self:transform(...) end, can_transform = function(self, node) return self.transformers[ntype(node)] ~= nil end } _base_0.__index = _base_0 if _parent_0 then setmetatable(_base_0, _parent_0.__base) end local _class_0 = setmetatable({ __init = function(self, transformers) self.transformers = transformers self.seen_nodes = setmetatable({ }, { __mode = "k" }) end, __base = _base_0, __name = "Transformer", __parent = _parent_0 }, { __index = function(cls, name) local val = rawget(_base_0, name) if val == nil and _parent_0 then return _parent_0[name] else return val end end, __call = function(cls, ...) local _self_0 = setmetatable({}, _base_0) cls.__init(_self_0, ...) return _self_0 end }) _base_0.__class = _class_0 if _parent_0 and _parent_0.__inherited then _parent_0.__inherited(_parent_0, _class_0) end Transformer = _class_0 end local construct_comprehension construct_comprehension = function(inner, clauses) local current_stms = inner for _, clause in reversed(clauses) do local t = clause[1] if t == "for" then local names, iter _, names, iter = unpack(clause) current_stms = { "foreach", names, { iter }, current_stms } elseif t == "when" then local cond _, cond = unpack(clause) current_stms = { "if", cond, current_stms } else current_stms = error("Unknown comprehension clause: " .. t) end current_stms = { current_stms } end return current_stms[1] end local Statement = Transformer({ root_stms = function(self, body) return apply_to_last(body, implicitly_return(self)) end, assign = function(self, node) local names, values = unpack(node, 2) local transformed if #values == 1 then local value = values[1] local t = ntype(value) if t == "decorated" then value = self.transform.statement(value) t = ntype(value) end if types.cascading[t] then local ret ret = function(stm) if types.is_value(stm) then return { "assign", names, { stm } } else return stm end end transformed = build.group({ { "declare", names }, self.transform.statement(value, ret, node) }) end end node = transformed or node if destructure.has_destructure(names) then return destructure.split_assign(node) end return node end, continue = function(self, node) local continue_name = self:send("continue") if not (continue_name) then error("continue must be inside of a loop") end return build.group({ build.assign_one(continue_name, "true"), { "break" } }) end, export = function(self, node) if #node > 2 then if node[2] == "class" then local cls = smart_node(node[3]) return build.group({ { "export", { cls.name } }, cls }) else return build.group({ node, build.assign({ names = node[2], values = node[3] }) }) end else return nil end end, update = function(self, node) local _, name, op, exp = unpack(node) local op_final = op:match("^(.+)=$") if not op_final then error("Unknown op: " .. op) end if not (value_is_singular(exp)) then exp = { "parens", exp } end return build.assign_one(name, { "exp", name, op_final, exp }) end, import = function(self, node) local _, names, source = unpack(node) local stubs = (function() local _accum_0 = { } local _len_0 = 0 local _list_0 = names for _index_0 = 1, #_list_0 do local name = _list_0[_index_0] local _value_0 if type(name) == "table" then _value_0 = name else _value_0 = { "dot", name } end if _value_0 ~= nil then _len_0 = _len_0 + 1 _accum_0[_len_0] = _value_0 end end return _accum_0 end)() local real_names = (function() local _accum_0 = { } local _len_0 = 0 local _list_0 = names for _index_0 = 1, #_list_0 do local name = _list_0[_index_0] local _value_0 = type(name) == "table" and name[2] or name if _value_0 ~= nil then _len_0 = _len_0 + 1 _accum_0[_len_0] = _value_0 end end return _accum_0 end)() if type(source) == "string" then return build.assign({ names = real_names, values = (function() local _accum_0 = { } local _len_0 = 0 local _list_0 = stubs for _index_0 = 1, #_list_0 do local stub = _list_0[_index_0] _len_0 = _len_0 + 1 _accum_0[_len_0] = build.chain({ base = source, stub }) end return _accum_0 end)() }) else local source_name = NameProxy("table") return build.group({ { "declare", real_names }, build["do"]({ build.assign_one(source_name, source), build.assign({ names = real_names, values = (function() local _accum_0 = { } local _len_0 = 0 local _list_0 = stubs for _index_0 = 1, #_list_0 do local stub = _list_0[_index_0] _len_0 = _len_0 + 1 _accum_0[_len_0] = build.chain({ base = source_name, stub }) end return _accum_0 end)() }) }) }) end end, comprehension = function(self, node, action) local _, exp, clauses = unpack(node) action = action or function(exp) return { exp } end return construct_comprehension(action(exp), clauses) end, ["do"] = function(self, node, ret) if ret then node[2] = apply_to_last(node[2], ret) end return node end, decorated = function(self, node) local stm, dec = unpack(node, 2) local wrapped local _exp_0 = dec[1] if "if" == _exp_0 then local cond, fail = unpack(dec, 2) if fail then fail = { "else", { fail } } end wrapped = { "if", cond, { stm }, fail } elseif "unless" == _exp_0 then wrapped = { "unless", dec[2], { stm } } elseif "comprehension" == _exp_0 then wrapped = { "comprehension", stm, dec[2] } else wrapped = error("Unknown decorator " .. dec[1]) end if ntype(stm) == "assign" then wrapped = build.group({ build.declare({ names = (function() local _accum_0 = { } local _len_0 = 0 local _list_0 = stm[2] for _index_0 = 1, #_list_0 do local name = _list_0[_index_0] if type(name) == "string" then _len_0 = _len_0 + 1 _accum_0[_len_0] = name end end return _accum_0 end)() }), wrapped }) end return wrapped end, unless = function(self, node) return { "if", { "not", { "parens", node[2] } }, unpack(node, 3) } end, ["if"] = function(self, node, ret) if ntype(node[2]) == "assign" then local _, assign, body = unpack(node) if destructure.has_destructure(assign[2]) then local name = NameProxy("des") body = { destructure.build_assign(assign[2][1], name), build.group(node[3]) } return build["do"]({ build.assign_one(name, assign[3][1]), { "if", name, body, unpack(node, 4) } }) else local name = assign[2][1] return build["do"]({ assign, { "if", name, unpack(node, 3) } }) end end node = expand_elseif_assign(node) if ret then smart_node(node) node['then'] = apply_to_last(node['then'], ret) for i = 4, #node do local case = node[i] local body_idx = #node[i] case[body_idx] = apply_to_last(case[body_idx], ret) end end return node end, with = function(self, node, ret) local _, exp, block = unpack(node) local scope_name = NameProxy("with") local named_assign if ntype(exp) == "assign" then local names, values = unpack(exp, 2) local assign_name = names[1] exp = values[1] values[1] = scope_name named_assign = { "assign", names, values } end return build["do"]({ Run(function(self) return self:set("scope_var", scope_name) end), build.assign_one(scope_name, exp), build.group({ named_assign }), build.group(block), (function() if ret then return ret(scope_name) end end)() }) end, foreach = function(self, node) smart_node(node) local source = unpack(node.iter) local destructures = { } node.names = (function() local _accum_0 = { } local _len_0 = 0 for i, name in ipairs(node.names) do local _value_0 if ntype(name) == "table" then do local _with_0 = NameProxy("des") local proxy = _with_0 insert(destructures, destructure.build_assign(name, proxy)) _value_0 = _with_0 end else _value_0 = name end if _value_0 ~= nil then _len_0 = _len_0 + 1 _accum_0[_len_0] = _value_0 end end return _accum_0 end)() if next(destructures) then insert(destructures, build.group(node.body)) node.body = destructures end if ntype(source) == "unpack" then local list = source[2] local index_name = NameProxy("index") local list_name = NameProxy("list") local slice_var = nil local bounds if is_slice(list) then local slice = list[#list] table.remove(list) table.remove(slice, 1) if slice[2] and slice[2] ~= "" then local max_tmp_name = NameProxy("max") slice_var = build.assign_one(max_tmp_name, slice[2]) slice[2] = { "exp", max_tmp_name, "<", 0, "and", { "length", list_name }, "+", max_tmp_name, "or", max_tmp_name } else slice[2] = { "length", list_name } end bounds = slice else bounds = { 1, { "length", list_name } } end return build.group({ build.assign_one(list_name, list), slice_var, build["for"]({ name = index_name, bounds = bounds, body = { { "assign", node.names, { list_name:index(index_name) } }, build.group(node.body) } }) }) end node.body = with_continue_listener(node.body) end, ["while"] = function(self, node) smart_node(node) node.body = with_continue_listener(node.body) end, ["for"] = function(self, node) smart_node(node) node.body = with_continue_listener(node.body) end, switch = function(self, node, ret) local _, exp, conds = unpack(node) local exp_name = NameProxy("exp") local convert_cond convert_cond = function(cond) local t, case_exps, body = unpack(cond) local out = { } insert(out, t == "case" and "elseif" or "else") if t ~= "else" then local cond_exp = { } for i, case in ipairs(case_exps) do if i == 1 then insert(cond_exp, "exp") else insert(cond_exp, "or") end if not (value_is_singular(case)) then case = { "parens", case } end insert(cond_exp, { "exp", case, "==", exp_name }) end insert(out, cond_exp) else body = case_exps end if ret then body = apply_to_last(body, ret) end insert(out, body) return out end local first = true local if_stm = { "if" } local _list_0 = conds for _index_0 = 1, #_list_0 do local cond = _list_0[_index_0] local if_cond = convert_cond(cond) if first then first = false insert(if_stm, if_cond[2]) insert(if_stm, if_cond[3]) else insert(if_stm, if_cond) end end return build.group({ build.assign_one(exp_name, exp), if_stm }) end, class = function(self, node, ret, parent_assign) local _, name, parent_val, body = unpack(node) local statements = { } local properties = { } local _list_0 = body for _index_0 = 1, #_list_0 do local item = _list_0[_index_0] local _exp_0 = item[1] if "stm" == _exp_0 then insert(statements, item[2]) elseif "props" == _exp_0 then local _list_1 = item for _index_1 = 2, #_list_1 do local tuple = _list_1[_index_1] if ntype(tuple[1]) == "self" then insert(statements, build.assign_one(unpack(tuple))) else insert(properties, tuple) end end end end local constructor = nil properties = (function() local _accum_0 = { } local _len_0 = 0 local _list_1 = properties for _index_0 = 1, #_list_1 do local tuple = _list_1[_index_0] local key = tuple[1] local _value_0 if key[1] == "key_literal" and key[2] == constructor_name then constructor = tuple[2] _value_0 = nil else _value_0 = tuple end if _value_0 ~= nil then _len_0 = _len_0 + 1 _accum_0[_len_0] = _value_0 end end return _accum_0 end)() local parent_cls_name = NameProxy("parent") local base_name = NameProxy("base") local self_name = NameProxy("self") local cls_name = NameProxy("class") if not constructor then constructor = build.fndef({ args = { { "..." } }, arrow = "fat", body = { build["if"]({ cond = parent_cls_name, ["then"] = { build.chain({ base = "super", { "call", { "..." } } }) } }) } }) else smart_node(constructor) constructor.arrow = "fat" end local real_name = name or parent_assign and parent_assign[2][1] local _exp_0 = ntype(real_name) if "chain" == _exp_0 then local last = real_name[#real_name] local _exp_1 = ntype(last) if "dot" == _exp_1 then real_name = { "string", '"', last[2] } elseif "index" == _exp_1 then real_name = last[2] else real_name = "nil" end elseif "nil" == _exp_0 then real_name = "nil" else real_name = { "string", '"', real_name } end local cls = build.table({ { "__init", constructor }, { "__base", base_name }, { "__name", real_name }, { "__parent", parent_cls_name } }) local class_lookup = build["if"]({ cond = { "exp", "val", "==", "nil", "and", parent_cls_name }, ["then"] = { parent_cls_name:index("name") } }) insert(class_lookup, { "else", { "val" } }) local cls_mt = build.table({ { "__index", build.fndef({ args = { { "cls" }, { "name" } }, body = { build.assign_one(LocalName("val"), build.chain({ base = "rawget", { "call", { base_name, "name" } } })), class_lookup } }) }, { "__call", build.fndef({ args = { { "cls" }, { "..." } }, body = { build.assign_one(self_name, build.chain({ base = "setmetatable", { "call", { "{}", base_name } } })), build.chain({ base = "cls.__init", { "call", { self_name, "..." } } }), self_name } }) } }) cls = build.chain({ base = "setmetatable", { "call", { cls, cls_mt } } }) local value = nil do local _with_0 = build local out_body = { Run(function(self) if name then self:put_name(name) end return self:set("super", function(block, chain) if chain then local slice = (function() local _accum_0 = { } local _len_0 = 0 local _list_1 = chain for _index_0 = 3, #_list_1 do local item = _list_1[_index_0] _len_0 = _len_0 + 1 _accum_0[_len_0] = item end return _accum_0 end)() local new_chain = { "chain", parent_cls_name } local head = slice[1] if head == nil then return parent_cls_name end local _exp_1 = head[1] if "call" == _exp_1 then local calling_name = block:get("current_block") slice[1] = { "call", { "self", unpack(head[2]) } } if ntype(calling_name) == "key_literal" then insert(new_chain, { "dot", calling_name[2] }) else insert(new_chain, { "index", calling_name }) end elseif "colon" == _exp_1 then local call = head[3] insert(new_chain, { "dot", head[2] }) slice[1] = { "call", { "self", unpack(call[2]) } } end local _list_1 = slice for _index_0 = 1, #_list_1 do local item = _list_1[_index_0] insert(new_chain, item) end return new_chain else return parent_cls_name end end) end), _with_0.assign_one(parent_cls_name, parent_val == "" and "nil" or parent_val), _with_0.assign_one(base_name, { "table", properties }), _with_0.assign_one(base_name:chain("__index"), base_name), _with_0["if"]({ cond = parent_cls_name, ["then"] = { _with_0.chain({ base = "setmetatable", { "call", { base_name, _with_0.chain({ base = parent_cls_name, { "dot", "__base" } }) } } }) } }), _with_0.assign_one(cls_name, cls), _with_0.assign_one(base_name:chain("__class"), cls_name), _with_0.group((function() if #statements > 0 then return { _with_0.assign_one(LocalName("self"), cls_name), _with_0.group(statements) } end end)()), _with_0["if"]({ cond = { "exp", parent_cls_name, "and", parent_cls_name:chain("__inherited") }, ["then"] = { parent_cls_name:chain("__inherited", { "call", { parent_cls_name, cls_name } }) } }), _with_0.group((function() if name then return { _with_0.assign_one(name, cls_name) } end end)()), (function() if ret then return ret(cls_name) end end)() } hoist_declarations(out_body) value = _with_0.group({ _with_0.group((function() if ntype(name) == "value" then return { _with_0.declare({ names = { name } }) } end end)()), _with_0["do"](out_body) }) end return value end }) local Accumulator do local _parent_0 = nil local _base_0 = { body_idx = { ["for"] = 4, ["while"] = 3, foreach = 4 }, convert = function(self, node) local index = self.body_idx[ntype(node)] node[index] = self:mutate_body(node[index]) return self:wrap(node) end, wrap = function(self, node) return build.block_exp({ build.assign_one(self.accum_name, build.table()), build.assign_one(self.len_name, 0), node, self.accum_name }) end, mutate_body = function(self, body, skip_nil) if skip_nil == nil then skip_nil = true end local val if not skip_nil and is_singular(body) then do local _with_0 = body[1] body = { } val = _with_0 end else body = apply_to_last(body, function(n) if types.is_value(n) then return build.assign_one(self.value_name, n) else return build.group({ { "declare", { self.value_name } }, n }) end end) val = self.value_name end local update = { { "update", self.len_name, "+=", 1 }, build.assign_one(self.accum_name:index(self.len_name), val) } if skip_nil then table.insert(body, build["if"]({ cond = { "exp", self.value_name, "!=", "nil" }, ["then"] = update })) else table.insert(body, build.group(update)) end return body end } _base_0.__index = _base_0 if _parent_0 then setmetatable(_base_0, _parent_0.__base) end local _class_0 = setmetatable({ __init = function(self) self.accum_name = NameProxy("accum") self.value_name = NameProxy("value") self.len_name = NameProxy("len") end, __base = _base_0, __name = "Accumulator", __parent = _parent_0 }, { __index = function(cls, name) local val = rawget(_base_0, name) if val == nil and _parent_0 then return _parent_0[name] else return val end end, __call = function(cls, ...) local _self_0 = setmetatable({}, _base_0) cls.__init(_self_0, ...) return _self_0 end }) _base_0.__class = _class_0 if _parent_0 and _parent_0.__inherited then _parent_0.__inherited(_parent_0, _class_0) end Accumulator = _class_0 end local default_accumulator default_accumulator = function(self, node) return Accumulator():convert(node) end implicitly_return = function(scope) local is_top = true local fn fn = function(stm) local t = ntype(stm) if t == "decorated" then stm = scope.transform.statement(stm) t = ntype(stm) end if types.cascading[t] then is_top = false return scope.transform.statement(stm, fn) elseif types.manual_return[t] or not types.is_value(stm) then if is_top and t == "return" and stm[2] == "" then return nil else return stm end else if t == "comprehension" and not types.comprehension_has_value(stm) then return stm else return { "return", stm } end end end return fn end local Value = Transformer({ ["for"] = default_accumulator, ["while"] = default_accumulator, foreach = default_accumulator, ["do"] = function(self, node) return build.block_exp(node[2]) end, decorated = function(self, node) return self.transform.statement(node) end, class = function(self, node) return build.block_exp({ node }) end, string = function(self, node) local delim = node[2] local convert_part convert_part = function(part) if type(part) == "string" or part == nil then return { "string", delim, part or "" } else return build.chain({ base = "tostring", { "call", { part[2] } } }) end end if #node <= 3 then return (function() if type(node[3]) == "string" then return node else return convert_part(node[3]) end end)() end local e = { "exp", convert_part(node[3]) } for i = 4, #node do insert(e, "..") insert(e, convert_part(node[i])) end return e end, comprehension = function(self, node) local a = Accumulator() node = self.transform.statement(node, function(exp) return a:mutate_body({ exp }, false) end) return a:wrap(node) end, tblcomprehension = function(self, node) local _, explist, clauses = unpack(node) local key_exp, value_exp = unpack(explist) local accum = NameProxy("tbl") local inner if value_exp then local dest = build.chain({ base = accum, { "index", key_exp } }) inner = { build.assign_one(dest, value_exp) } else local key_name, val_name = NameProxy("key"), NameProxy("val") local dest = build.chain({ base = accum, { "index", key_name } }) inner = { build.assign({ names = { key_name, val_name }, values = { key_exp } }), build.assign_one(dest, val_name) } end return build.block_exp({ build.assign_one(accum, build.table()), construct_comprehension(inner, clauses), accum }) end, fndef = function(self, node) smart_node(node) node.body = apply_to_last(node.body, implicitly_return(self)) node.body = { Run(function(self) return self:listen("varargs", function() end) end), unpack(node.body) } return node end, ["if"] = function(self, node) return build.block_exp({ node }) end, unless = function(self, node) return build.block_exp({ node }) end, with = function(self, node) return build.block_exp({ node }) end, switch = function(self, node) return build.block_exp({ node }) end, chain = function(self, node) local stub = node[#node] for i = 3, #node do local part = node[i] if ntype(part) == "dot" and data.lua_keywords[part[2]] then node[i] = { "index", { "string", '"', part[2] } } end end if ntype(node[2]) == "string" then node[2] = { "parens", node[2] } elseif type(stub) == "table" and stub[1] == "colon_stub" then table.remove(node, #node) local base_name = NameProxy("base") local fn_name = NameProxy("fn") local is_super = node[2] == "super" return self.transform.value(build.block_exp({ build.assign({ names = { base_name }, values = { node } }), build.assign({ names = { fn_name }, values = { build.chain({ base = base_name, { "dot", stub[2] } }) } }), build.fndef({ args = { { "..." } }, body = { build.chain({ base = fn_name, { "call", { is_super and "self" or base_name, "..." } } }) } }) })) end end, block_exp = function(self, node) local _, body = unpack(node) local fn = nil local arg_list = { } fn = smart_node(build.fndef({ body = { Run(function(self) return self:listen("varargs", function() insert(arg_list, "...") insert(fn.args, { "..." }) return self:unlisten("varargs") end) end), unpack(body) } })) return build.chain({ base = { "parens", fn }, { "call", arg_list } }) end }) return { Statement = Statement, Value = Value, Run = Run } luaparse-0.3.1/benchmarks/run.sh000077500000000000000000000113341405615720100166120ustar00rootroot00000000000000DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) REMOTE="$DIR/.." # Clone local copy to get access to HEAD DEST="$DIR/bench-luaparse" GIT_FLAGS="--git-dir=$DEST/.git --work-tree=$DEST/" # Variables D8=$(which d8 2>/dev/null) processor="/opt/v8/tools/linux-tick-processor" [[ "$D8" ]] && processor="$(realpath $(dirname $(readlink $D8))/../../tools/)/linux-tick-processor" minTime=0 samples=5 js=0 profile=0 verbose=0 usage() { echo -n "$0 [COMMIT]... Benchmark luaparse at the the specified commit stages. While running the profiling tool you have to make sure your specified tick-processor matches the V8-version used in the running node-version. Examples: $0 --js HEAD~1 HEAD $0 --js --samples 1000 HEAD $0 -v --profile d2f038 Options: --js Benchmark js scripts --profile Profile luaparse.js with d8 -m, --minTime Specify the min time. Defaults to 10 (node specific) -s, --samples Specify the samples. Defaults to 10 -p, --processor Specify the path to the tick-processor. Defaults to $processor -v, --verbose Display verbose messages -h, --help Display this help and exit " } # Helpers out() { printf '%b\n' "$@"; } err() { out "\033[1;31m✖\033[0m $@"; } >&2 success() { (($verbose)) && out " \033[1;32m✔\033[0m $@"; } log() { (($verbose)) && out "$@"; } die() { err "$@"; exit 1; } >&2 confirm() { read -p "$1 [Y/n] " -n 1; echo [[ $REPLY =~ ^[Yy]$ ]]; } g() { log "Running git $GIT_FLAGS $@" git $GIT_FLAGS "$@" > /dev/null 2>&1 } runNodeBenchmark() { local file=$1 local commit=$2 echo "Commit $commit:" $REMOTE/scripts/benchmark -v \ --luaparse="$file" --samples="$samples" --minTime="$minTime" \ "benchmarks/lib/ParseLua.lua" echo } # Profile luaparse together with D8. profileCommit() { local commit=$1 local output="logs/$commit" local benchmark="scripts/benchmark benchmarks/lib/ParseLua.lua" # This relies on the commit having the required files. [[ ! -f "scripts/benchmark" ]] && die "The commit is outdated for profiling." [[ ! -f "benchmarks/lib/ParseLua.lua" ]] && die "The commit is outdated for profiling." [[ ! -f $processor ]] && die "tick-processor not found at $processor" [[ -d "$output" ]] && rm -rf $output && success "Deleted old: $output" mkdir -p $output success "Created log directory: $output" node --prof $benchmark > /dev/null $processor > $output/ticks success "Created $output/ticks ($(wc -c < $output/ticks) bytes)" mv v8.log $output/v8.log success "Created $output/v8.log ($(wc -c < $output/v8.log) bytes)" for fn in inlining bailout gc; do node --trace_$fn --code_comments $benchmark > $output/$fn success "Created $output/$fn ($(wc -c < $output/$fn) bytes)" done } # Main benchmark loop benchmark() { local commit=$(git rev-parse $1) commit=${commit:0:6} g checkout $commit if [[ $? -ne 0 ]]; then err "Could not checkout $commit" else success "Checked out $commit" if ((js)); then log "Benchmarking commit $commit" runNodeBenchmark "$DEST/index" "$commit" [[ $? -ne 0 ]] && die "Benchmark failed" fi if ((profile)); then profileCommit $commit fi fi } # Initialize main() { # Clone a copy where we can benchmark [[ ! -d $DEST/.git ]] && git clone $REMOTE $DEST > /dev/null 2>&1 for commit in "$@"; do benchmark "$commit" done # Clean up rm -rf $DEST } # Parse options # Iterate over options breaking -ab into -a -b when needed and --foo=bar into # --foo bar optstring=h unset options while (($#)); do case $1 in # If option is of type -ab -[!-]?*) # Loop over each character starting with the second for ((i=1; i < ${#1}; i++)); do c=${1:i:1} # Add current char to options options+=("-$c") # If option takes a required argument, and it's not the last char make # the rest of the string its argument if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then options+=("${1:i+1}") break fi done ;; # If option is of type --foo=bar --?*=*) options+=("${1%%=*}" "${1#*=}") ;; # add --endopts for -- --) options+=(--endopts) ;; # Otherwise, nothing special *) options+=("$1") ;; esac shift done set -- "${options[@]}" unset options # Print help if no arguments were passed. [[ $# -eq 0 ]] && set -- "--help" # Read the options while [[ $1 = -?* ]]; do case $1 in -h|--help) usage >&2; exit ;; --js) js=1 ;; --profile) profile=1 ;; -s|--samples) shift; samples=$1 ;; -m|--minTime) shift; minTime=$1 ;; -p|--processor) shift; processor=$1 ;; -v|--verbose) verbose=1 ;; --endopts) shift; break ;; *) die "invalid option: $1" ;; esac shift done main "$@" luaparse-0.3.1/bin/000077500000000000000000000000001405615720100141005ustar00rootroot00000000000000luaparse-0.3.1/bin/luaparse000077500000000000000000000070621405615720100156470ustar00rootroot00000000000000#!/usr/bin/env node /*jshint node:true*/ /*globals console:true */ 'use strict'; var fs = require('fs') , util = require('util') , luaparse = require('../luaparse') , args = process.argv.splice(2) , stdin = process.stdin , isTTY = stdin.isTTY , beautify = false , quiet = false , verbose = false , input = '' , options = {} , snippets = []; function usage() { console.log([ "Usage: luaparse [option]... [file|code]..." , "\nOptions:" , " -c|--code [code] parse code snippet" , " -f|--file [file] parse from file" , " -b|--beautify output an indenteted AST" , " --[no]-comments store comments. defaults to true" , " --[no]-scope store variable scope. defaults to false" , " --[no]-locations store location data on syntax nodes. defaults to false" , " --[no]-ranges store start and end character locations. defaults to false" , " -q|--quiet suppress output" , " -h|--help" , " -v|--version" , " --verbose" , "\nExamples:" , " luaparse --no-comments -c \"locale foo = \\\"bar\\\"\"" , " luaparse foo.lua bar.lua" ].join("\n")); } if (isTTY && !args.length) { usage(); process.exit(0); } for (var i = 0, l = args.length; i < l; i++) { var arg = args[i], match, flag, bool, snippet; if (match = /^(?:-|--)(?:(no)-)?(\w+)$/.exec(arg)) { bool = 'no' !== match[1]; flag = match[2]; switch (flag) { case 'b': case 'beautify': beautify = true; continue; case 'q': case 'quiet': quiet = true; continue; case 'verbose': verbose = true; continue; case 'c': case 'code': snippets.push({ name: args[++i], code: args[i] }); continue; case 'f': case 'file': snippets.push({ name: args[++i], code: fs.readFileSync(args[i], 'utf-8') }); continue; case 'comments': case 'scope': case 'locations': case 'ranges': options[flag] = bool; continue; case 'L': case 'luaversion': options.luaVersion = args[++i]; continue; case 'X': case 'extendedidentifiers': options.extendedIdentifiers = bool; continue; case 'v': case 'version': console.log("luaparse v%s", luaparse.version); process.exit(0); break; case 'h': case 'help': usage(); process.exit(0); break; default: if (!quiet) console.log("Unknown option: %s", match[0]); process.exit(2); } } // Default to autodetecting code or file. snippet = fs.existsSync(arg) ? { name: arg, code: fs.readFileSync(arg, 'utf-8') } : { name: arg, code: arg }; snippets.push(snippet); } function done() { var success = true; snippets.forEach(function(snippet) { var message, ast; try { ast = luaparse.parse(snippet.code, options); message = beautify ? JSON.stringify(ast, null, ' ') : JSON.stringify(ast); } catch(e) { if (!(e instanceof luaparse.SyntaxError)) throw e; message = util.format("%s: %s", snippet.name, e.message); if (verbose) console.log(e.stack); success = false; } if (!quiet) console.log(message); }); if (!success) process.exit(1); } if (stdin.isTTY) done(); else { // @TODO doesn't work in node 0.9.4-0.9.11 because `end` is never emitted. stdin.setEncoding('utf8'); stdin.on('data', function(chunk) { input += chunk; }); stdin.on('end', function() { snippets.unshift({ code: input }); done(); }); stdin.resume(); } /* vim: set sw=2 ts=2 et tw=80 ft=javascript : */ luaparse-0.3.1/component.json000066400000000000000000000004021405615720100162210ustar00rootroot00000000000000{ "name": "luaparse", "repository": "fstirlitz/luaparse", "description": "A Lua parser in JavaScript", "version": "0.2.1", "keywords": ["ast", "lua", "parser", "parsing"], "main": "luaparse.js", "scripts": ["luaparse.js"], "license": "MIT" } luaparse-0.3.1/docs/000077500000000000000000000000001405615720100142605ustar00rootroot00000000000000luaparse-0.3.1/docs/coverage.md000066400000000000000000000002331405615720100163730ustar00rootroot00000000000000Coverage is reported using [nyc](https://github.com/istanbuljs/nyc). luaparse-0.3.1/docs/examples.md000066400000000000000000000001271405615720100164200ustar00rootroot00000000000000* [Code parser](../examples/treeview.html) * [Code statistics](../examples/stats.html) luaparse-0.3.1/docs/layout/000077500000000000000000000000001405615720100155755ustar00rootroot00000000000000luaparse-0.3.1/docs/layout/foot.html000066400000000000000000000005521405615720100174340ustar00rootroot00000000000000 luaparse-0.3.1/docs/layout/head.html000066400000000000000000000025261405615720100173710ustar00rootroot00000000000000 Luaparse

Luaparse

A Lua parser written in JavaScript, originally written by Oskar Schöldström for his bachelor's thesis at Arcada.

luaparse-0.3.1/docs/luaparse.1000066400000000000000000000034571405615720100161670ustar00rootroot00000000000000.TH luaparse "1" "June 7, 2013" "" "luaparse manual" .SH NAME luaparse - Lua parser .SH SYNOPSIS .B luaparse [-v|--version] [-h|--help] [-b|--beautify] [-q|--quiet] [--verbose] .RS [--[no]-comments] [--[no]-scope] [--[no]-locations] [--[no]-ranges] .br [-c|--code .I snippet ] .br [-f|--file .I script.lua ] .br [ .I code ] [ .I snippet ] .RE .SH DESCRIPTION .B luaparse is a parser producing JSON formatted Abstract Syntax Tree representations .br of Lua programs. .SH OPTIONS .B .IP "-v, --version" print luaparse's version .IP "-h, --help" prints usage instructions .B .IP "-c, --code [code]" parse Lua program from code snippet provided as an argument .B .IP "-f, --file [file.lua]" parse Lua program from file .B .IP "-b, --beautify" output an indented AST .B .IP "--[no]-comments" store comments while parsing. defaults to true .B .IP "--[no]-scope" store variable scope tracking while parsing. defaults to false .B .IP "--[no]-locations" store location information on each syntax nodes. defaults to false .B .IP "--[no]-ranges" store the start and end character locations on each syntax node. defaults to false .B .IP "-q, --quiet" suppress output .B .IP "--verbose" output additional information .SH EXAMPLES .B .IP "luaparse 'i = 2^2^3^4' 'i = 2^(2^(3^4))'" Output the AST of both code snippets separated by a newline. .B .IP "luaparse foo.lua" Output the AST of the Lua code in the file. .B .IP "luaparse --scope -b -c 'locale foo = 1'" Output the indented AST of the code snippet and track variable scopes. .SH BUGS luaparse's bug tracker is located at .SH DOCUMENTATION See the website for documentation .SH AUTHOR Originally written by Oskar Schöldström . Currently maintained by felix luaparse-0.3.1/examples/000077500000000000000000000000001405615720100151465ustar00rootroot00000000000000luaparse-0.3.1/examples/js/000077500000000000000000000000001405615720100155625ustar00rootroot00000000000000luaparse-0.3.1/examples/js/walker.js000066400000000000000000000021101405615720100173770ustar00rootroot00000000000000/*globals exports:true, window:true */ (function(exports) { var hasOwn = Object.prototype.hasOwnProperty , isArray = Array.isArray || function (arr) { return Object.prototype.toString.call(arr) === '[object Array]'; } , objectKeys = Object.keys || function (obj) { var keys = []; for (var key in obj) if (hasOwn.call(obj, key)) keys.push(key); return keys; } , forEach = function(keys, fn) { if (keys.forEach) return keys.forEach(fn); for (var i = 0, l = keys.length; i < l; i++) fn.call(keys, keys[i], i, keys); }; exports.walker = function walk(node, fn) { if (typeof node !== 'object') return false; if (fn(node) === false) return; forEach(objectKeys(node), function(key) { var child = node[key]; if (child == null || typeof child !== 'object') return; if (typeof child.type === 'string') return walk(child, fn); if (isArray(child)) { forEach(child, function(sub) { walk(sub, fn); }); } }); }; }(typeof exports !== 'undefined' ? exports : window)); luaparse-0.3.1/examples/stats.html000066400000000000000000000056271405615720100172040ustar00rootroot00000000000000 Luaparse
luaparse-0.3.1/examples/treeview.html000066400000000000000000000064671405615720100177030ustar00rootroot00000000000000 Luaparse
function Foo:bar (...) local baz = "Hazzaah" end
luaparse-0.3.1/gulpfile.js000066400000000000000000000063331405615720100155020ustar00rootroot00000000000000/* globals require: true */ var gulp = require('gulp') , header = require('gulp-header') , uglify = require('gulp-uglify') , rename = require('gulp-rename') , jshint = require('gulp-jshint') , filelog = require('gulp-filelog') , addsrc = require('gulp-add-src') , pkg = require('./package.json') , banner = [ '/*!' , ' * @license' , ' * <%= pkg.name %> <%= pkg.version %> <%= pkg.homepage %>' , ' * Copyright 2012-<%= new Date().getFullYear() %> <%= pkg.author %>' , ' * MIT license' , ' */' , '' ].join('\n'); var striphtml = (function () { /* globals Buffer: true */ 'use strict'; var PluginError = require('plugin-error') , through = require('through2'); function removeHTML(src, patterns) { var lines = src.split('\n') , scriptSection = false , commentingSection = false; lines.forEach(function (line, i) { var starts = (/ luaparse-0.3.1/test/index.html000066400000000000000000000043311405615720100163050ustar00rootroot00000000000000 Spec Unit Tests
luaparse-0.3.1/test/lib/000077500000000000000000000000001405615720100150555ustar00rootroot00000000000000luaparse-0.3.1/test/lib/benchmark.js000066400000000000000000003362361405615720100173620ustar00rootroot00000000000000/*! * Benchmark.js v1.0.0 * Copyright 2010-2012 Mathias Bynens * Based on JSLitmus.js, copyright Robert Kieffer * Modified by John-David Dalton * Available under MIT license */ ;(function(window, undefined) { 'use strict'; /** Used to assign each benchmark an incrimented id */ var counter = 0; /** Detect DOM document object */ var doc = isHostType(window, 'document') && document; /** Detect free variable `define` */ var freeDefine = typeof define == 'function' && typeof define.amd == 'object' && define.amd && define; /** Detect free variable `exports` */ var freeExports = typeof exports == 'object' && exports && (typeof global == 'object' && global && global == global.global && (window = global), exports); /** Detect free variable `require` */ var freeRequire = typeof require == 'function' && require; /** Used to crawl all properties regardless of enumerability */ var getAllKeys = Object.getOwnPropertyNames; /** Used to get property descriptors */ var getDescriptor = Object.getOwnPropertyDescriptor; /** Used in case an object doesn't have its own method */ var hasOwnProperty = {}.hasOwnProperty; /** Used to check if an object is extensible */ var isExtensible = Object.isExtensible || function() { return true; }; /** Used to access Wade Simmons' Node microtime module */ var microtimeObject = req('microtime'); /** Used to access the browser's high resolution timer */ var perfObject = isHostType(window, 'performance') && performance; /** Used to call the browser's high resolution timer */ var perfName = perfObject && ( perfObject.now && 'now' || perfObject.webkitNow && 'webkitNow' ); /** Used to access Node's high resolution timer */ var processObject = isHostType(window, 'process') && process; /** Used to check if an own property is enumerable */ var propertyIsEnumerable = {}.propertyIsEnumerable; /** Used to set property descriptors */ var setDescriptor = Object.defineProperty; /** Used to resolve a value's internal [[Class]] */ var toString = {}.toString; /** Used to prevent a `removeChild` memory leak in IE < 9 */ var trash = doc && doc.createElement('div'); /** Used to integrity check compiled tests */ var uid = 'uid' + (+new Date); /** Used to avoid infinite recursion when methods call each other */ var calledBy = {}; /** Used to avoid hz of Infinity */ var divisors = { '1': 4096, '2': 512, '3': 64, '4': 8, '5': 0 }; /** * T-Distribution two-tailed critical values for 95% confidence * http://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm */ var tTable = { '1': 12.706,'2': 4.303, '3': 3.182, '4': 2.776, '5': 2.571, '6': 2.447, '7': 2.365, '8': 2.306, '9': 2.262, '10': 2.228, '11': 2.201, '12': 2.179, '13': 2.16, '14': 2.145, '15': 2.131, '16': 2.12, '17': 2.11, '18': 2.101, '19': 2.093, '20': 2.086, '21': 2.08, '22': 2.074, '23': 2.069, '24': 2.064, '25': 2.06, '26': 2.056, '27': 2.052, '28': 2.048, '29': 2.045, '30': 2.042, 'infinity': 1.96 }; /** * Critical Mann-Whitney U-values for 95% confidence * http://www.saburchill.com/IBbiology/stats/003.html */ var uTable = { '5': [0, 1, 2], '6': [1, 2, 3, 5], '7': [1, 3, 5, 6, 8], '8': [2, 4, 6, 8, 10, 13], '9': [2, 4, 7, 10, 12, 15, 17], '10': [3, 5, 8, 11, 14, 17, 20, 23], '11': [3, 6, 9, 13, 16, 19, 23, 26, 30], '12': [4, 7, 11, 14, 18, 22, 26, 29, 33, 37], '13': [4, 8, 12, 16, 20, 24, 28, 33, 37, 41, 45], '14': [5, 9, 13, 17, 22, 26, 31, 36, 40, 45, 50, 55], '15': [5, 10, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64], '16': [6, 11, 15, 21, 26, 31, 37, 42, 47, 53, 59, 64, 70, 75], '17': [6, 11, 17, 22, 28, 34, 39, 45, 51, 57, 63, 67, 75, 81, 87], '18': [7, 12, 18, 24, 30, 36, 42, 48, 55, 61, 67, 74, 80, 86, 93, 99], '19': [7, 13, 19, 25, 32, 38, 45, 52, 58, 65, 72, 78, 85, 92, 99, 106, 113], '20': [8, 14, 20, 27, 34, 41, 48, 55, 62, 69, 76, 83, 90, 98, 105, 112, 119, 127], '21': [8, 15, 22, 29, 36, 43, 50, 58, 65, 73, 80, 88, 96, 103, 111, 119, 126, 134, 142], '22': [9, 16, 23, 30, 38, 45, 53, 61, 69, 77, 85, 93, 101, 109, 117, 125, 133, 141, 150, 158], '23': [9, 17, 24, 32, 40, 48, 56, 64, 73, 81, 89, 98, 106, 115, 123, 132, 140, 149, 157, 166, 175], '24': [10, 17, 25, 33, 42, 50, 59, 67, 76, 85, 94, 102, 111, 120, 129, 138, 147, 156, 165, 174, 183, 192], '25': [10, 18, 27, 35, 44, 53, 62, 71, 80, 89, 98, 107, 117, 126, 135, 145, 154, 163, 173, 182, 192, 201, 211], '26': [11, 19, 28, 37, 46, 55, 64, 74, 83, 93, 102, 112, 122, 132, 141, 151, 161, 171, 181, 191, 200, 210, 220, 230], '27': [11, 20, 29, 38, 48, 57, 67, 77, 87, 97, 107, 118, 125, 138, 147, 158, 168, 178, 188, 199, 209, 219, 230, 240, 250], '28': [12, 21, 30, 40, 50, 60, 70, 80, 90, 101, 111, 122, 132, 143, 154, 164, 175, 186, 196, 207, 218, 228, 239, 250, 261, 272], '29': [13, 22, 32, 42, 52, 62, 73, 83, 94, 105, 116, 127, 138, 149, 160, 171, 182, 193, 204, 215, 226, 238, 249, 260, 271, 282, 294], '30': [13, 23, 33, 43, 54, 65, 76, 87, 98, 109, 120, 131, 143, 154, 166, 177, 189, 200, 212, 223, 235, 247, 258, 270, 282, 293, 305, 317] }; /** * An object used to flag environments/features. * * @static * @memberOf Benchmark * @type Object */ var support = {}; (function() { /** * Detect Adobe AIR. * * @memberOf Benchmark.support * @type Boolean */ support.air = isClassOf(window.runtime, 'ScriptBridgingProxyObject'); /** * Detect if `arguments` objects have the correct internal [[Class]] value. * * @memberOf Benchmark.support * @type Boolean */ support.argumentsClass = isClassOf(arguments, 'Arguments'); /** * Detect if in a browser environment. * * @memberOf Benchmark.support * @type Boolean */ support.browser = doc && isHostType(window, 'navigator'); /** * Detect if strings support accessing characters by index. * * @memberOf Benchmark.support * @type Boolean */ support.charByIndex = // IE 8 supports indexes on string literals but not string objects ('x'[0] + Object('x')[0]) == 'xx'; /** * Detect if strings have indexes as own properties. * * @memberOf Benchmark.support * @type Boolean */ support.charByOwnIndex = // Rhino, RingoJS, IE 8, and Opera < 10.52 support indexes on // strings but don't detect them as own properties support.charByIndex && hasKey('x', '0'); /** * Detect if Java is enabled/exposed. * * @memberOf Benchmark.support * @type Boolean */ support.java = isClassOf(window.java, 'JavaPackage'); /** * Detect if the Timers API exists. * * @memberOf Benchmark.support * @type Boolean */ support.timeout = isHostType(window, 'setTimeout') && isHostType(window, 'clearTimeout'); /** * Detect if functions support decompilation. * * @name decompilation * @memberOf Benchmark.support * @type Boolean */ try { // Safari 2.x removes commas in object literals // from Function#toString results // http://webk.it/11609 // Firefox 3.6 and Opera 9.25 strip grouping // parentheses from Function#toString results // http://bugzil.la/559438 support.decompilation = Function( 'return (' + (function(x) { return { 'x': '' + (1 + x) + '', 'y': 0 }; }) + ')' )()(0).x === '1'; } catch(e) { support.decompilation = false; } /** * Detect ES5+ property descriptor API. * * @name descriptors * @memberOf Benchmark.support * @type Boolean */ try { var o = {}; support.descriptors = (setDescriptor(o, o, o), 'value' in getDescriptor(o, o)); } catch(e) { support.descriptors = false; } /** * Detect ES5+ Object.getOwnPropertyNames(). * * @name getAllKeys * @memberOf Benchmark.support * @type Boolean */ try { support.getAllKeys = /\bvalueOf\b/.test(getAllKeys(Object.prototype)); } catch(e) { support.getAllKeys = false; } /** * Detect if own properties are iterated before inherited properties (all but IE < 9). * * @name iteratesOwnLast * @memberOf Benchmark.support * @type Boolean */ support.iteratesOwnFirst = (function() { var props = []; function ctor() { this.x = 1; } ctor.prototype = { 'y': 1 }; for (var prop in new ctor) { props.push(prop); } return props[0] == 'x'; }()); /** * Detect if a node's [[Class]] is resolvable (all but IE < 9) * and that the JS engine errors when attempting to coerce an object to a * string without a `toString` property value of `typeof` "function". * * @name nodeClass * @memberOf Benchmark.support * @type Boolean */ try { support.nodeClass = ({ 'toString': 0 } + '', toString.call(doc || 0) != '[object Object]'); } catch(e) { support.nodeClass = true; } }()); /** * Timer object used by `clock()` and `Deferred#resolve`. * * @private * @type Object */ var timer = { /** * The timer namespace object or constructor. * * @private * @memberOf timer * @type Function|Object */ 'ns': Date, /** * Starts the deferred timer. * * @private * @memberOf timer * @param {Object} deferred The deferred instance. */ 'start': null, // lazy defined in `clock()` /** * Stops the deferred timer. * * @private * @memberOf timer * @param {Object} deferred The deferred instance. */ 'stop': null // lazy defined in `clock()` }; /** Shortcut for inverse results */ var noArgumentsClass = !support.argumentsClass, noCharByIndex = !support.charByIndex, noCharByOwnIndex = !support.charByOwnIndex; /** Math shortcuts */ var abs = Math.abs, floor = Math.floor, max = Math.max, min = Math.min, pow = Math.pow, sqrt = Math.sqrt; /*--------------------------------------------------------------------------*/ /** * The Benchmark constructor. * * @constructor * @param {String} name A name to identify the benchmark. * @param {Function|String} fn The test to benchmark. * @param {Object} [options={}] Options object. * @example * * // basic usage (the `new` operator is optional) * var bench = new Benchmark(fn); * * // or using a name first * var bench = new Benchmark('foo', fn); * * // or with options * var bench = new Benchmark('foo', fn, { * * // displayed by Benchmark#toString if `name` is not available * 'id': 'xyz', * * // called when the benchmark starts running * 'onStart': onStart, * * // called after each run cycle * 'onCycle': onCycle, * * // called when aborted * 'onAbort': onAbort, * * // called when a test errors * 'onError': onError, * * // called when reset * 'onReset': onReset, * * // called when the benchmark completes running * 'onComplete': onComplete, * * // compiled/called before the test loop * 'setup': setup, * * // compiled/called after the test loop * 'teardown': teardown * }); * * // or name and options * var bench = new Benchmark('foo', { * * // a flag to indicate the benchmark is deferred * 'defer': true, * * // benchmark test function * 'fn': function(deferred) { * // call resolve() when the deferred test is finished * deferred.resolve(); * } * }); * * // or options only * var bench = new Benchmark({ * * // benchmark name * 'name': 'foo', * * // benchmark test as a string * 'fn': '[1,2,3,4].sort()' * }); * * // a test's `this` binding is set to the benchmark instance * var bench = new Benchmark('foo', function() { * 'My name is '.concat(this.name); // My name is foo * }); */ function Benchmark(name, fn, options) { var me = this; // allow instance creation without the `new` operator if (me == null || me.constructor != Benchmark) { return new Benchmark(name, fn, options); } // juggle arguments if (isClassOf(name, 'Object')) { // 1 argument (options) options = name; } else if (isClassOf(name, 'Function')) { // 2 arguments (fn, options) options = fn; fn = name; } else if (isClassOf(fn, 'Object')) { // 2 arguments (name, options) options = fn; fn = null; me.name = name; } else { // 3 arguments (name, fn [, options]) me.name = name; } setOptions(me, options); me.id || (me.id = ++counter); me.fn == null && (me.fn = fn); me.stats = deepClone(me.stats); me.times = deepClone(me.times); } /** * The Deferred constructor. * * @constructor * @memberOf Benchmark * @param {Object} clone The cloned benchmark instance. */ function Deferred(clone) { var me = this; if (me == null || me.constructor != Deferred) { return new Deferred(clone); } me.benchmark = clone; clock(me); } /** * The Event constructor. * * @constructor * @memberOf Benchmark * @param {String|Object} type The event type. */ function Event(type) { var me = this; return (me == null || me.constructor != Event) ? new Event(type) : (type instanceof Event) ? type : extend(me, { 'timeStamp': +new Date }, typeof type == 'string' ? { 'type': type } : type); } /** * The Suite constructor. * * @constructor * @memberOf Benchmark * @param {String} name A name to identify the suite. * @param {Object} [options={}] Options object. * @example * * // basic usage (the `new` operator is optional) * var suite = new Benchmark.Suite; * * // or using a name first * var suite = new Benchmark.Suite('foo'); * * // or with options * var suite = new Benchmark.Suite('foo', { * * // called when the suite starts running * 'onStart': onStart, * * // called between running benchmarks * 'onCycle': onCycle, * * // called when aborted * 'onAbort': onAbort, * * // called when a test errors * 'onError': onError, * * // called when reset * 'onReset': onReset, * * // called when the suite completes running * 'onComplete': onComplete * }); */ function Suite(name, options) { var me = this; // allow instance creation without the `new` operator if (me == null || me.constructor != Suite) { return new Suite(name, options); } // juggle arguments if (isClassOf(name, 'Object')) { // 1 argument (options) options = name; } else { // 2 arguments (name [, options]) me.name = name; } setOptions(me, options); } /*--------------------------------------------------------------------------*/ /** * Note: Some array methods have been implemented in plain JavaScript to avoid * bugs in IE, Opera, Rhino, and Mobile Safari. * * IE compatibility mode and IE < 9 have buggy Array `shift()` and `splice()` * functions that fail to remove the last element, `object[0]`, of * array-like-objects even though the `length` property is set to `0`. * The `shift()` method is buggy in IE 8 compatibility mode, while `splice()` * is buggy regardless of mode in IE < 9 and buggy in compatibility mode in IE 9. * * In Opera < 9.50 and some older/beta Mobile Safari versions using `unshift()` * generically to augment the `arguments` object will pave the value at index 0 * without incrimenting the other values's indexes. * https://github.com/documentcloud/underscore/issues/9 * * Rhino and environments it powers, like RingoJS, may have * buggy Array `concat()`, `reverse()`, `shift()`, `slice()`, `splice()` and * `unshift()` functions that make sparse arrays non-sparse by assigning the * undefined indexes a value of undefined. * https://github.com/mozilla/rhino/commit/702abfed3f8ca043b2636efd31c14ba7552603dd */ /** * Creates an array containing the elements of the host array followed by the * elements of each argument in order. * * @memberOf Benchmark.Suite * @returns {Array} The new array. */ function concat() { var value, j = -1, length = arguments.length, result = slice.call(this), index = result.length; while (++j < length) { value = arguments[j]; if (isClassOf(value, 'Array')) { for (var k = 0, l = value.length; k < l; k++, index++) { if (k in value) { result[index] = value[k]; } } } else { result[index++] = value; } } return result; } /** * Utility function used by `shift()`, `splice()`, and `unshift()`. * * @private * @param {Number} start The index to start inserting elements. * @param {Number} deleteCount The number of elements to delete from the insert point. * @param {Array} elements The elements to insert. * @returns {Array} An array of deleted elements. */ function insert(start, deleteCount, elements) { // `result` should have its length set to the `deleteCount` // see https://bugs.ecmascript.org/show_bug.cgi?id=332 var deleteEnd = start + deleteCount, elementCount = elements ? elements.length : 0, index = start - 1, length = start + elementCount, object = this, result = Array(deleteCount), tail = slice.call(object, deleteEnd); // delete elements from the array while (++index < deleteEnd) { if (index in object) { result[index - start] = object[index]; delete object[index]; } } // insert elements index = start - 1; while (++index < length) { object[index] = elements[index - start]; } // append tail elements start = index--; length = max(0, (object.length >>> 0) - deleteCount + elementCount); while (++index < length) { if ((index - start) in tail) { object[index] = tail[index - start]; } else if (index in object) { delete object[index]; } } // delete excess elements deleteCount = deleteCount > elementCount ? deleteCount - elementCount : 0; while (deleteCount--) { index = length + deleteCount; if (index in object) { delete object[index]; } } object.length = length; return result; } /** * Rearrange the host array's elements in reverse order. * * @memberOf Benchmark.Suite * @returns {Array} The reversed array. */ function reverse() { var upperIndex, value, index = -1, object = Object(this), length = object.length >>> 0, middle = floor(length / 2); if (length > 1) { while (++index < middle) { upperIndex = length - index - 1; value = upperIndex in object ? object[upperIndex] : uid; if (index in object) { object[upperIndex] = object[index]; } else { delete object[upperIndex]; } if (value != uid) { object[index] = value; } else { delete object[index]; } } } return object; } /** * Removes the first element of the host array and returns it. * * @memberOf Benchmark.Suite * @returns {Mixed} The first element of the array. */ function shift() { return insert.call(this, 0, 1)[0]; } /** * Creates an array of the host array's elements from the start index up to, * but not including, the end index. * * @memberOf Benchmark.Suite * @param {Number} start The starting index. * @param {Number} end The end index. * @returns {Array} The new array. */ function slice(start, end) { var index = -1, object = Object(this), length = object.length >>> 0, result = []; start = toInteger(start); start = start < 0 ? max(length + start, 0) : min(start, length); start--; end = end == null ? length : toInteger(end); end = end < 0 ? max(length + end, 0) : min(end, length); while ((++index, ++start) < end) { if (start in object) { result[index] = object[start]; } } return result; } /** * Allows removing a range of elements and/or inserting elements into the * host array. * * @memberOf Benchmark.Suite * @param {Number} start The start index. * @param {Number} deleteCount The number of elements to delete. * @param {Mixed} [val1, val2, ...] values to insert at the `start` index. * @returns {Array} An array of removed elements. */ function splice(start, deleteCount) { var object = Object(this), length = object.length >>> 0; start = toInteger(start); start = start < 0 ? max(length + start, 0) : min(start, length); // support the de-facto SpiderMonkey extension // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice#Parameters // https://bugs.ecmascript.org/show_bug.cgi?id=429 deleteCount = arguments.length == 1 ? length - start : min(max(toInteger(deleteCount), 0), length - start); return insert.call(object, start, deleteCount, slice.call(arguments, 2)); } /** * Converts the specified `value` to an integer. * * @private * @param {Mixed} value The value to convert. * @returns {Number} The resulting integer. */ function toInteger(value) { value = +value; return value === 0 || !isFinite(value) ? value || 0 : value - (value % 1); } /** * Appends arguments to the host array. * * @memberOf Benchmark.Suite * @returns {Number} The new length. */ function unshift() { var object = Object(this); insert.call(object, 0, 0, arguments); return object.length; } /*--------------------------------------------------------------------------*/ /** * A generic `Function#bind` like method. * * @private * @param {Function} fn The function to be bound to `thisArg`. * @param {Mixed} thisArg The `this` binding for the given function. * @returns {Function} The bound function. */ function bind(fn, thisArg) { return function() { fn.apply(thisArg, arguments); }; } /** * Creates a function from the given arguments string and body. * * @private * @param {String} args The comma separated function arguments. * @param {String} body The function body. * @returns {Function} The new function. */ function createFunction() { // lazy define createFunction = function(args, body) { var result, anchor = freeDefine ? define.amd : Benchmark, prop = uid + 'createFunction'; runScript((freeDefine ? 'define.amd.' : 'Benchmark.') + prop + '=function(' + args + '){' + body + '}'); result = anchor[prop]; delete anchor[prop]; return result; }; // fix JaegerMonkey bug // http://bugzil.la/639720 createFunction = support.browser && (createFunction('', 'return"' + uid + '"') || noop)() == uid ? createFunction : Function; return createFunction.apply(null, arguments); } /** * Delay the execution of a function based on the benchmark's `delay` property. * * @private * @param {Object} bench The benchmark instance. * @param {Object} fn The function to execute. */ function delay(bench, fn) { bench._timerId = setTimeout(fn, bench.delay * 1e3); } /** * Destroys the given element. * * @private * @param {Element} element The element to destroy. */ function destroyElement(element) { trash.appendChild(element); trash.innerHTML = ''; } /** * Iterates over an object's properties, executing the `callback` for each. * Callbacks may terminate the loop by explicitly returning `false`. * * @private * @param {Object} object The object to iterate over. * @param {Function} callback The function executed per own property. * @param {Object} options The options object. * @returns {Object} Returns the object iterated over. */ function forProps() { var forShadowed, skipSeen, forArgs = true, shadowed = ['constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']; (function(enumFlag, key) { // must use a non-native constructor to catch the Safari 2 issue function Klass() { this.valueOf = 0; }; Klass.prototype.valueOf = 0; // check various for-in bugs for (key in new Klass) { enumFlag += key == 'valueOf' ? 1 : 0; } // check if `arguments` objects have non-enumerable indexes for (key in arguments) { key == '0' && (forArgs = false); } // Safari 2 iterates over shadowed properties twice // http://replay.waybackmachine.org/20090428222941/http://tobielangel.com/2007/1/29/for-in-loop-broken-in-safari/ skipSeen = enumFlag == 2; // IE < 9 incorrectly makes an object's properties non-enumerable if they have // the same name as other non-enumerable properties in its prototype chain. forShadowed = !enumFlag; }(0)); // lazy define forProps = function(object, callback, options) { options || (options = {}); var result = object; object = Object(object); var ctor, key, keys, skipCtor, done = !result, which = options.which, allFlag = which == 'all', index = -1, iteratee = object, length = object.length, ownFlag = allFlag || which == 'own', seen = {}, skipProto = isClassOf(object, 'Function'), thisArg = options.bind; if (thisArg !== undefined) { callback = bind(callback, thisArg); } // iterate all properties if (allFlag && support.getAllKeys) { for (index = 0, keys = getAllKeys(object), length = keys.length; index < length; index++) { key = keys[index]; if (callback(object[key], key, object) === false) { break; } } } // else iterate only enumerable properties else { for (key in object) { // Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1 // (if the prototype or a property on the prototype has been set) // incorrectly set a function's `prototype` property [[Enumerable]] value // to `true`. Because of this we standardize on skipping the `prototype` // property of functions regardless of their [[Enumerable]] value. if ((done = !(skipProto && key == 'prototype') && !(skipSeen && (hasKey(seen, key) || !(seen[key] = true))) && (!ownFlag || ownFlag && hasKey(object, key)) && callback(object[key], key, object) === false)) { break; } } // in IE < 9 strings don't support accessing characters by index if (!done && (forArgs && isArguments(object) || ((noCharByIndex || noCharByOwnIndex) && isClassOf(object, 'String') && (iteratee = noCharByIndex ? object.split('') : object)))) { while (++index < length) { if ((done = callback(iteratee[index], String(index), object) === false)) { break; } } } if (!done && forShadowed) { // Because IE < 9 can't set the `[[Enumerable]]` attribute of an existing // property and the `constructor` property of a prototype defaults to // non-enumerable, we manually skip the `constructor` property when we // think we are iterating over a `prototype` object. ctor = object.constructor; skipCtor = ctor && ctor.prototype && ctor.prototype.constructor === ctor; for (index = 0; index < 7; index++) { key = shadowed[index]; if (!(skipCtor && key == 'constructor') && hasKey(object, key) && callback(object[key], key, object) === false) { break; } } } } return result; }; return forProps.apply(null, arguments); } /** * Gets the name of the first argument from a function's source. * * @private * @param {Function} fn The function. * @returns {String} The argument name. */ function getFirstArgument(fn) { return (!hasKey(fn, 'toString') && (/^[\s(]*function[^(]*\(([^\s,)]+)/.exec(fn) || 0)[1]) || ''; } /** * Computes the arithmetic mean of a sample. * * @private * @param {Array} sample The sample. * @returns {Number} The mean. */ function getMean(sample) { return reduce(sample, function(sum, x) { return sum + x; }) / sample.length || 0; } /** * Gets the source code of a function. * * @private * @param {Function} fn The function. * @param {String} altSource A string used when a function's source code is unretrievable. * @returns {String} The function's source code. */ function getSource(fn, altSource) { var result = altSource; if (isStringable(fn)) { result = String(fn); } else if (support.decompilation) { // escape the `{` for Firefox 1 result = (/^[^{]+\{([\s\S]*)}\s*$/.exec(fn) || 0)[1]; } // trim string result = (result || '').replace(/^\s+|\s+$/g, ''); // detect strings containing only the "use strict" directive return /^(?:\/\*+[\w|\W]*?\*\/|\/\/.*?[\n\r\u2028\u2029]|\s)*(["'])use strict\1;?$/.test(result) ? '' : result; } /** * Checks if a value is an `arguments` object. * * @private * @param {Mixed} value The value to check. * @returns {Boolean} Returns `true` if the value is an `arguments` object, else `false`. */ function isArguments() { // lazy define isArguments = function(value) { return toString.call(value) == '[object Arguments]'; }; if (noArgumentsClass) { isArguments = function(value) { return hasKey(value, 'callee') && !(propertyIsEnumerable && propertyIsEnumerable.call(value, 'callee')); }; } return isArguments(arguments[0]); } /** * Checks if an object is of the specified class. * * @private * @param {Mixed} value The value to check. * @param {String} name The name of the class. * @returns {Boolean} Returns `true` if the value is of the specified class, else `false`. */ function isClassOf(value, name) { return value != null && toString.call(value) == '[object ' + name + ']'; } /** * Host objects can return type values that are different from their actual * data type. The objects we are concerned with usually return non-primitive * types of object, function, or unknown. * * @private * @param {Mixed} object The owner of the property. * @param {String} property The property to check. * @returns {Boolean} Returns `true` if the property value is a non-primitive, else `false`. */ function isHostType(object, property) { var type = object != null ? typeof object[property] : 'number'; return !/^(?:boolean|number|string|undefined)$/.test(type) && (type == 'object' ? !!object[property] : true); } /** * Checks if a given `value` is an object created by the `Object` constructor * assuming objects created by the `Object` constructor have no inherited * enumerable properties and that there are no `Object.prototype` extensions. * * @private * @param {Mixed} value The value to check. * @returns {Boolean} Returns `true` if the `value` is a plain `Object` object, else `false`. */ function isPlainObject(value) { // avoid non-objects and false positives for `arguments` objects in IE < 9 var result = false; if (!(value && typeof value == 'object') || (noArgumentsClass && isArguments(value))) { return result; } // IE < 9 presents DOM nodes as `Object` objects except they have `toString` // methods that are `typeof` "string" and still can coerce nodes to strings. // Also check that the constructor is `Object` (i.e. `Object instanceof Object`) var ctor = value.constructor; if ((support.nodeClass || !(typeof value.toString != 'function' && typeof (value + '') == 'string')) && (!isClassOf(ctor, 'Function') || ctor instanceof ctor)) { // In most environments an object's own properties are iterated before // its inherited properties. If the last iterated property is an object's // own property then there are no inherited enumerable properties. if (support.iteratesOwnFirst) { forProps(value, function(subValue, subKey) { result = subKey; }); return result === false || hasKey(value, result); } // IE < 9 iterates inherited properties before own properties. If the first // iterated property is an object's own property then there are no inherited // enumerable properties. forProps(value, function(subValue, subKey) { result = !hasKey(value, subKey); return false; }); return result === false; } return result; } /** * Checks if a value can be safely coerced to a string. * * @private * @param {Mixed} value The value to check. * @returns {Boolean} Returns `true` if the value can be coerced, else `false`. */ function isStringable(value) { return hasKey(value, 'toString') || isClassOf(value, 'String'); } /** * Wraps a function and passes `this` to the original function as the * first argument. * * @private * @param {Function} fn The function to be wrapped. * @returns {Function} The new function. */ function methodize(fn) { return function() { var args = [this]; args.push.apply(args, arguments); return fn.apply(null, args); }; } /** * A no-operation function. * * @private */ function noop() { // no operation performed } /** * A wrapper around require() to suppress `module missing` errors. * * @private * @param {String} id The module id. * @returns {Mixed} The exported module or `null`. */ function req(id) { try { var result = freeExports && freeRequire(id); } catch(e) { } return result || null; } /** * Runs a snippet of JavaScript via script injection. * * @private * @param {String} code The code to run. */ function runScript(code) { var anchor = freeDefine ? define.amd : Benchmark, script = doc.createElement('script'), sibling = doc.getElementsByTagName('script')[0], parent = sibling.parentNode, prop = uid + 'runScript', prefix = '(' + (freeDefine ? 'define.amd.' : 'Benchmark.') + prop + '||function(){})();'; // Firefox 2.0.0.2 cannot use script injection as intended because it executes // asynchronously, but that's OK because script injection is only used to avoid // the previously commented JaegerMonkey bug. try { // remove the inserted script *before* running the code to avoid differences // in the expected script element count/order of the document. script.appendChild(doc.createTextNode(prefix + code)); anchor[prop] = function() { destroyElement(script); }; } catch(e) { parent = parent.cloneNode(false); sibling = null; script.text = code; } parent.insertBefore(script, sibling); delete anchor[prop]; } /** * A helper function for setting options/event handlers. * * @private * @param {Object} bench The benchmark instance. * @param {Object} [options={}] Options object. */ function setOptions(bench, options) { options = extend({}, bench.constructor.options, options); bench.options = forOwn(options, function(value, key) { if (value != null) { // add event listeners if (/^on[A-Z]/.test(key)) { forEach(key.split(' '), function(key) { bench.on(key.slice(2).toLowerCase(), value); }); } else if (!hasKey(bench, key)) { bench[key] = deepClone(value); } } }); } /*--------------------------------------------------------------------------*/ /** * Handles cycling/completing the deferred benchmark. * * @memberOf Benchmark.Deferred */ function resolve() { var me = this, clone = me.benchmark, bench = clone._original; if (bench.aborted) { // cycle() -> clone cycle/complete event -> compute()'s invoked bench.run() cycle/complete me.teardown(); clone.running = false; cycle(me); } else if (++me.cycles < clone.count) { // continue the test loop if (support.timeout) { // use setTimeout to avoid a call stack overflow if called recursively setTimeout(function() { clone.compiled.call(me, timer); }, 0); } else { clone.compiled.call(me, timer); } } else { timer.stop(me); me.teardown(); delay(clone, function() { cycle(me); }); } } /*--------------------------------------------------------------------------*/ /** * A deep clone utility. * * @static * @memberOf Benchmark * @param {Mixed} value The value to clone. * @returns {Mixed} The cloned value. */ function deepClone(value) { var accessor, circular, clone, ctor, descriptor, extensible, key, length, markerKey, parent, result, source, subIndex, data = { 'value': value }, index = 0, marked = [], queue = { 'length': 0 }, unmarked = []; /** * An easily detectable decorator for cloned values. */ function Marker(object) { this.raw = object; } /** * The callback used by `forProps()`. */ function forPropsCallback(subValue, subKey) { // exit early to avoid cloning the marker if (subValue && subValue.constructor == Marker) { return; } // add objects to the queue if (subValue === Object(subValue)) { queue[queue.length++] = { 'key': subKey, 'parent': clone, 'source': value }; } // assign non-objects else { try { // will throw an error in strict mode if the property is read-only clone[subKey] = subValue; } catch(e) { } } } /** * Gets an available marker key for the given object. */ function getMarkerKey(object) { // avoid collisions with existing keys var result = uid; while (object[result] && object[result].constructor != Marker) { result += 1; } return result; } do { key = data.key; parent = data.parent; source = data.source; clone = value = source ? source[key] : data.value; accessor = circular = descriptor = false; // create a basic clone to filter out functions, DOM elements, and // other non `Object` objects if (value === Object(value)) { // use custom deep clone function if available if (isClassOf(value.deepClone, 'Function')) { clone = value.deepClone(); } else { ctor = value.constructor; switch (toString.call(value)) { case '[object Array]': clone = new ctor(value.length); break; case '[object Boolean]': clone = new ctor(value == true); break; case '[object Date]': clone = new ctor(+value); break; case '[object Object]': isPlainObject(value) && (clone = {}); break; case '[object Number]': case '[object String]': clone = new ctor(value); break; case '[object RegExp]': clone = ctor(value.source, (value.global ? 'g' : '') + (value.ignoreCase ? 'i' : '') + (value.multiline ? 'm' : '')); } } // continue clone if `value` doesn't have an accessor descriptor // http://es5.github.io/#x8.10.1 if (clone && clone != value && !(descriptor = source && support.descriptors && getDescriptor(source, key), accessor = descriptor && (descriptor.get || descriptor.set))) { // use an existing clone (circular reference) if ((extensible = isExtensible(value))) { markerKey = getMarkerKey(value); if (value[markerKey]) { circular = clone = value[markerKey].raw; } } else { // for frozen/sealed objects for (subIndex = 0, length = unmarked.length; subIndex < length; subIndex++) { data = unmarked[subIndex]; if (data.object === value) { circular = clone = data.clone; break; } } } if (!circular) { // mark object to allow quickly detecting circular references and tie it to its clone if (extensible) { value[markerKey] = new Marker(clone); marked.push({ 'key': markerKey, 'object': value }); } else { // for frozen/sealed objects unmarked.push({ 'clone': clone, 'object': value }); } // iterate over object properties forProps(value, forPropsCallback, { 'which': 'all' }); } } } if (parent) { // for custom property descriptors if (accessor || (descriptor && !(descriptor.configurable && descriptor.enumerable && descriptor.writable))) { if ('value' in descriptor) { descriptor.value = clone; } setDescriptor(parent, key, descriptor); } // for default property descriptors else { parent[key] = clone; } } else { result = clone; } } while ((data = queue[index++])); // remove markers for (index = 0, length = marked.length; index < length; index++) { data = marked[index]; delete data.object[data.key]; } return result; } /** * An iteration utility for arrays and objects. * Callbacks may terminate the loop by explicitly returning `false`. * * @static * @memberOf Benchmark * @param {Array|Object} object The object to iterate over. * @param {Function} callback The function called per iteration. * @param {Mixed} thisArg The `this` binding for the callback. * @returns {Array|Object} Returns the object iterated over. */ function each(object, callback, thisArg) { var result = object; object = Object(object); var fn = callback, index = -1, length = object.length, isSnapshot = !!(object.snapshotItem && (length = object.snapshotLength)), isSplittable = (noCharByIndex || noCharByOwnIndex) && isClassOf(object, 'String'), isConvertable = isSnapshot || isSplittable || 'item' in object, origObject = object; // in Opera < 10.5 `hasKey(object, 'length')` returns `false` for NodeLists if (length === length >>> 0) { if (isConvertable) { // the third argument of the callback is the original non-array object callback = function(value, index) { return fn.call(this, value, index, origObject); }; // in IE < 9 strings don't support accessing characters by index if (isSplittable) { object = object.split(''); } else { object = []; while (++index < length) { // in Safari 2 `index in object` is always `false` for NodeLists object[index] = isSnapshot ? result.snapshotItem(index) : result[index]; } } } forEach(object, callback, thisArg); } else { forOwn(object, callback, thisArg); } return result; } /** * Copies enumerable properties from the source(s) object to the destination object. * * @static * @memberOf Benchmark * @param {Object} destination The destination object. * @param {Object} [source={}] The source object. * @returns {Object} The destination object. */ function extend(destination, source) { // Chrome < 14 incorrectly sets `destination` to `undefined` when we `delete arguments[0]` // http://code.google.com/p/v8/issues/detail?id=839 var result = destination; delete arguments[0]; forEach(arguments, function(source) { forProps(source, function(value, key) { result[key] = value; }); }); return result; } /** * A generic `Array#filter` like method. * * @static * @memberOf Benchmark * @param {Array} array The array to iterate over. * @param {Function|String} callback The function/alias called per iteration. * @param {Mixed} thisArg The `this` binding for the callback. * @returns {Array} A new array of values that passed callback filter. * @example * * // get odd numbers * Benchmark.filter([1, 2, 3, 4, 5], function(n) { * return n % 2; * }); // -> [1, 3, 5]; * * // get fastest benchmarks * Benchmark.filter(benches, 'fastest'); * * // get slowest benchmarks * Benchmark.filter(benches, 'slowest'); * * // get benchmarks that completed without erroring * Benchmark.filter(benches, 'successful'); */ function filter(array, callback, thisArg) { var result; if (callback == 'successful') { // callback to exclude those that are errored, unrun, or have hz of Infinity callback = function(bench) { return bench.cycles && isFinite(bench.hz); }; } else if (callback == 'fastest' || callback == 'slowest') { // get successful, sort by period + margin of error, and filter fastest/slowest result = filter(array, 'successful').sort(function(a, b) { a = a.stats; b = b.stats; return (a.mean + a.moe > b.mean + b.moe ? 1 : -1) * (callback == 'fastest' ? 1 : -1); }); result = filter(result, function(bench) { return result[0].compare(bench) == 0; }); } return result || reduce(array, function(result, value, index) { return callback.call(thisArg, value, index, array) ? (result.push(value), result) : result; }, []); } /** * A generic `Array#forEach` like method. * Callbacks may terminate the loop by explicitly returning `false`. * * @static * @memberOf Benchmark * @param {Array} array The array to iterate over. * @param {Function} callback The function called per iteration. * @param {Mixed} thisArg The `this` binding for the callback. * @returns {Array} Returns the array iterated over. */ function forEach(array, callback, thisArg) { var index = -1, length = (array = Object(array)).length >>> 0; if (thisArg !== undefined) { callback = bind(callback, thisArg); } while (++index < length) { if (index in array && callback(array[index], index, array) === false) { break; } } return array; } /** * Iterates over an object's own properties, executing the `callback` for each. * Callbacks may terminate the loop by explicitly returning `false`. * * @static * @memberOf Benchmark * @param {Object} object The object to iterate over. * @param {Function} callback The function executed per own property. * @param {Mixed} thisArg The `this` binding for the callback. * @returns {Object} Returns the object iterated over. */ function forOwn(object, callback, thisArg) { return forProps(object, callback, { 'bind': thisArg, 'which': 'own' }); } /** * Converts a number to a more readable comma-separated string representation. * * @static * @memberOf Benchmark * @param {Number} number The number to convert. * @returns {String} The more readable string representation. */ function formatNumber(number) { number = String(number).split('.'); return number[0].replace(/(?=(?:\d{3})+$)(?!\b)/g, ',') + (number[1] ? '.' + number[1] : ''); } /** * Checks if an object has the specified key as a direct property. * * @static * @memberOf Benchmark * @param {Object} object The object to check. * @param {String} key The key to check for. * @returns {Boolean} Returns `true` if key is a direct property, else `false`. */ function hasKey() { // lazy define for worst case fallback (not as accurate) hasKey = function(object, key) { var parent = object != null && (object.constructor || Object).prototype; return !!parent && key in Object(object) && !(key in parent && object[key] === parent[key]); }; // for modern browsers if (isClassOf(hasOwnProperty, 'Function')) { hasKey = function(object, key) { return object != null && hasOwnProperty.call(object, key); }; } // for Safari 2 else if ({}.__proto__ == Object.prototype) { hasKey = function(object, key) { var result = false; if (object != null) { object = Object(object); object.__proto__ = [object.__proto__, object.__proto__ = null, result = key in object][0]; } return result; }; } return hasKey.apply(this, arguments); } /** * A generic `Array#indexOf` like method. * * @static * @memberOf Benchmark * @param {Array} array The array to iterate over. * @param {Mixed} value The value to search for. * @param {Number} [fromIndex=0] The index to start searching from. * @returns {Number} The index of the matched value or `-1`. */ function indexOf(array, value, fromIndex) { var index = toInteger(fromIndex), length = (array = Object(array)).length >>> 0; index = (index < 0 ? max(0, length + index) : index) - 1; while (++index < length) { if (index in array && value === array[index]) { return index; } } return -1; } /** * Modify a string by replacing named tokens with matching object property values. * * @static * @memberOf Benchmark * @param {String} string The string to modify. * @param {Object} object The template object. * @returns {String} The modified string. */ function interpolate(string, object) { forOwn(object, function(value, key) { // escape regexp special characters in `key` string = string.replace(RegExp('#\\{' + key.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1') + '\\}', 'g'), value); }); return string; } /** * Invokes a method on all items in an array. * * @static * @memberOf Benchmark * @param {Array} benches Array of benchmarks to iterate over. * @param {String|Object} name The name of the method to invoke OR options object. * @param {Mixed} [arg1, arg2, ...] Arguments to invoke the method with. * @returns {Array} A new array of values returned from each method invoked. * @example * * // invoke `reset` on all benchmarks * Benchmark.invoke(benches, 'reset'); * * // invoke `emit` with arguments * Benchmark.invoke(benches, 'emit', 'complete', listener); * * // invoke `run(true)`, treat benchmarks as a queue, and register invoke callbacks * Benchmark.invoke(benches, { * * // invoke the `run` method * 'name': 'run', * * // pass a single argument * 'args': true, * * // treat as queue, removing benchmarks from front of `benches` until empty * 'queued': true, * * // called before any benchmarks have been invoked. * 'onStart': onStart, * * // called between invoking benchmarks * 'onCycle': onCycle, * * // called after all benchmarks have been invoked. * 'onComplete': onComplete * }); */ function invoke(benches, name) { var args, bench, queued, index = -1, eventProps = { 'currentTarget': benches }, options = { 'onStart': noop, 'onCycle': noop, 'onComplete': noop }, result = map(benches, function(bench) { return bench; }); /** * Invokes the method of the current object and if synchronous, fetches the next. */ function execute() { var listeners, async = isAsync(bench); if (async) { // use `getNext` as the first listener bench.on('complete', getNext); listeners = bench.events.complete; listeners.splice(0, 0, listeners.pop()); } // execute method result[index] = isClassOf(bench && bench[name], 'Function') ? bench[name].apply(bench, args) : undefined; // if synchronous return true until finished return !async && getNext(); } /** * Fetches the next bench or executes `onComplete` callback. */ function getNext(event) { var cycleEvent, last = bench, async = isAsync(last); if (async) { last.off('complete', getNext); last.emit('complete'); } // emit "cycle" event eventProps.type = 'cycle'; eventProps.target = last; cycleEvent = Event(eventProps); options.onCycle.call(benches, cycleEvent); // choose next benchmark if not exiting early if (!cycleEvent.aborted && raiseIndex() !== false) { bench = queued ? benches[0] : result[index]; if (isAsync(bench)) { delay(bench, execute); } else if (async) { // resume execution if previously asynchronous but now synchronous while (execute()) { } } else { // continue synchronous execution return true; } } else { // emit "complete" event eventProps.type = 'complete'; options.onComplete.call(benches, Event(eventProps)); } // When used as a listener `event.aborted = true` will cancel the rest of // the "complete" listeners because they were already called above and when // used as part of `getNext` the `return false` will exit the execution while-loop. if (event) { event.aborted = true; } else { return false; } } /** * Checks if invoking `Benchmark#run` with asynchronous cycles. */ function isAsync(object) { // avoid using `instanceof` here because of IE memory leak issues with host objects var async = args[0] && args[0].async; return Object(object).constructor == Benchmark && name == 'run' && ((async == null ? object.options.async : async) && support.timeout || object.defer); } /** * Raises `index` to the next defined index or returns `false`. */ function raiseIndex() { var length = result.length; if (queued) { // if queued remove the previous bench and subsequent skipped non-entries do { ++index > 0 && shift.call(benches); } while ((length = benches.length) && !('0' in benches)); } else { while (++index < length && !(index in result)) { } } // if we reached the last index then return `false` return (queued ? length : index < length) ? index : (index = false); } // juggle arguments if (isClassOf(name, 'String')) { // 2 arguments (array, name) args = slice.call(arguments, 2); } else { // 2 arguments (array, options) options = extend(options, name); name = options.name; args = isClassOf(args = 'args' in options ? options.args : [], 'Array') ? args : [args]; queued = options.queued; } // start iterating over the array if (raiseIndex() !== false) { // emit "start" event bench = result[index]; eventProps.type = 'start'; eventProps.target = bench; options.onStart.call(benches, Event(eventProps)); // end early if the suite was aborted in an "onStart" listener if (benches.aborted && benches.constructor == Suite && name == 'run') { // emit "cycle" event eventProps.type = 'cycle'; options.onCycle.call(benches, Event(eventProps)); // emit "complete" event eventProps.type = 'complete'; options.onComplete.call(benches, Event(eventProps)); } // else start else { if (isAsync(bench)) { delay(bench, execute); } else { while (execute()) { } } } } return result; } /** * Creates a string of joined array values or object key-value pairs. * * @static * @memberOf Benchmark * @param {Array|Object} object The object to operate on. * @param {String} [separator1=','] The separator used between key-value pairs. * @param {String} [separator2=': '] The separator used between keys and values. * @returns {String} The joined result. */ function join(object, separator1, separator2) { var result = [], length = (object = Object(object)).length, arrayLike = length === length >>> 0; separator2 || (separator2 = ': '); each(object, function(value, key) { result.push(arrayLike ? value : key + separator2 + value); }); return result.join(separator1 || ','); } /** * A generic `Array#map` like method. * * @static * @memberOf Benchmark * @param {Array} array The array to iterate over. * @param {Function} callback The function called per iteration. * @param {Mixed} thisArg The `this` binding for the callback. * @returns {Array} A new array of values returned by the callback. */ function map(array, callback, thisArg) { return reduce(array, function(result, value, index) { result[index] = callback.call(thisArg, value, index, array); return result; }, Array(Object(array).length >>> 0)); } /** * Retrieves the value of a specified property from all items in an array. * * @static * @memberOf Benchmark * @param {Array} array The array to iterate over. * @param {String} property The property to pluck. * @returns {Array} A new array of property values. */ function pluck(array, property) { return map(array, function(object) { return object == null ? undefined : object[property]; }); } /** * A generic `Array#reduce` like method. * * @static * @memberOf Benchmark * @param {Array} array The array to iterate over. * @param {Function} callback The function called per iteration. * @param {Mixed} accumulator Initial value of the accumulator. * @returns {Mixed} The accumulator. */ function reduce(array, callback, accumulator) { var noaccum = arguments.length < 3; forEach(array, function(value, index) { accumulator = noaccum ? (noaccum = false, value) : callback(accumulator, value, index, array); }); return accumulator; } /*--------------------------------------------------------------------------*/ /** * Aborts all benchmarks in the suite. * * @name abort * @memberOf Benchmark.Suite * @returns {Object} The suite instance. */ function abortSuite() { var event, me = this, resetting = calledBy.resetSuite; if (me.running) { event = Event('abort'); me.emit(event); if (!event.cancelled || resetting) { // avoid infinite recursion calledBy.abortSuite = true; me.reset(); delete calledBy.abortSuite; if (!resetting) { me.aborted = true; invoke(me, 'abort'); } } } return me; } /** * Adds a test to the benchmark suite. * * @memberOf Benchmark.Suite * @param {String} name A name to identify the benchmark. * @param {Function|String} fn The test to benchmark. * @param {Object} [options={}] Options object. * @returns {Object} The benchmark instance. * @example * * // basic usage * suite.add(fn); * * // or using a name first * suite.add('foo', fn); * * // or with options * suite.add('foo', fn, { * 'onCycle': onCycle, * 'onComplete': onComplete * }); * * // or name and options * suite.add('foo', { * 'fn': fn, * 'onCycle': onCycle, * 'onComplete': onComplete * }); * * // or options only * suite.add({ * 'name': 'foo', * 'fn': fn, * 'onCycle': onCycle, * 'onComplete': onComplete * }); */ function add(name, fn, options) { var me = this, bench = Benchmark(name, fn, options), event = Event({ 'type': 'add', 'target': bench }); if (me.emit(event), !event.cancelled) { me.push(bench); } return me; } /** * Creates a new suite with cloned benchmarks. * * @name clone * @memberOf Benchmark.Suite * @param {Object} options Options object to overwrite cloned options. * @returns {Object} The new suite instance. */ function cloneSuite(options) { var me = this, result = new me.constructor(extend({}, me.options, options)); // copy own properties forOwn(me, function(value, key) { if (!hasKey(result, key)) { result[key] = value && isClassOf(value.clone, 'Function') ? value.clone() : deepClone(value); } }); return result; } /** * An `Array#filter` like method. * * @name filter * @memberOf Benchmark.Suite * @param {Function|String} callback The function/alias called per iteration. * @returns {Object} A new suite of benchmarks that passed callback filter. */ function filterSuite(callback) { var me = this, result = new me.constructor; result.push.apply(result, filter(me, callback)); return result; } /** * Resets all benchmarks in the suite. * * @name reset * @memberOf Benchmark.Suite * @returns {Object} The suite instance. */ function resetSuite() { var event, me = this, aborting = calledBy.abortSuite; if (me.running && !aborting) { // no worries, `resetSuite()` is called within `abortSuite()` calledBy.resetSuite = true; me.abort(); delete calledBy.resetSuite; } // reset if the state has changed else if ((me.aborted || me.running) && (me.emit(event = Event('reset')), !event.cancelled)) { me.running = false; if (!aborting) { invoke(me, 'reset'); } } return me; } /** * Runs the suite. * * @name run * @memberOf Benchmark.Suite * @param {Object} [options={}] Options object. * @returns {Object} The suite instance. * @example * * // basic usage * suite.run(); * * // or with options * suite.run({ 'async': true, 'queued': true }); */ function runSuite(options) { var me = this; me.reset(); me.running = true; options || (options = {}); invoke(me, { 'name': 'run', 'args': options, 'queued': options.queued, 'onStart': function(event) { me.emit(event); }, 'onCycle': function(event) { var bench = event.target; if (bench.error) { me.emit({ 'type': 'error', 'target': bench }); } me.emit(event); event.aborted = me.aborted; }, 'onComplete': function(event) { me.running = false; me.emit(event); } }); return me; } /*--------------------------------------------------------------------------*/ /** * Executes all registered listeners of the specified event type. * * @memberOf Benchmark, Benchmark.Suite * @param {String|Object} type The event type or object. * @returns {Mixed} Returns the return value of the last listener executed. */ function emit(type) { var listeners, me = this, event = Event(type), events = me.events, args = (arguments[0] = event, arguments); event.currentTarget || (event.currentTarget = me); event.target || (event.target = me); delete event.result; if (events && (listeners = hasKey(events, event.type) && events[event.type])) { forEach(listeners.slice(), function(listener) { if ((event.result = listener.apply(me, args)) === false) { event.cancelled = true; } return !event.aborted; }); } return event.result; } /** * Returns an array of event listeners for a given type that can be manipulated * to add or remove listeners. * * @memberOf Benchmark, Benchmark.Suite * @param {String} type The event type. * @returns {Array} The listeners array. */ function listeners(type) { var me = this, events = me.events || (me.events = {}); return hasKey(events, type) ? events[type] : (events[type] = []); } /** * Unregisters a listener for the specified event type(s), * or unregisters all listeners for the specified event type(s), * or unregisters all listeners for all event types. * * @memberOf Benchmark, Benchmark.Suite * @param {String} [type] The event type. * @param {Function} [listener] The function to unregister. * @returns {Object} The benchmark instance. * @example * * // unregister a listener for an event type * bench.off('cycle', listener); * * // unregister a listener for multiple event types * bench.off('start cycle', listener); * * // unregister all listeners for an event type * bench.off('cycle'); * * // unregister all listeners for multiple event types * bench.off('start cycle complete'); * * // unregister all listeners for all event types * bench.off(); */ function off(type, listener) { var me = this, events = me.events; events && each(type ? type.split(' ') : events, function(listeners, type) { var index; if (typeof listeners == 'string') { type = listeners; listeners = hasKey(events, type) && events[type]; } if (listeners) { if (listener) { index = indexOf(listeners, listener); if (index > -1) { listeners.splice(index, 1); } } else { listeners.length = 0; } } }); return me; } /** * Registers a listener for the specified event type(s). * * @memberOf Benchmark, Benchmark.Suite * @param {String} type The event type. * @param {Function} listener The function to register. * @returns {Object} The benchmark instance. * @example * * // register a listener for an event type * bench.on('cycle', listener); * * // register a listener for multiple event types * bench.on('start cycle', listener); */ function on(type, listener) { var me = this, events = me.events || (me.events = {}); forEach(type.split(' '), function(type) { (hasKey(events, type) ? events[type] : (events[type] = []) ).push(listener); }); return me; } /*--------------------------------------------------------------------------*/ /** * Aborts the benchmark without recording times. * * @memberOf Benchmark * @returns {Object} The benchmark instance. */ function abort() { var event, me = this, resetting = calledBy.reset; if (me.running) { event = Event('abort'); me.emit(event); if (!event.cancelled || resetting) { // avoid infinite recursion calledBy.abort = true; me.reset(); delete calledBy.abort; if (support.timeout) { clearTimeout(me._timerId); delete me._timerId; } if (!resetting) { me.aborted = true; me.running = false; } } } return me; } /** * Creates a new benchmark using the same test and options. * * @memberOf Benchmark * @param {Object} options Options object to overwrite cloned options. * @returns {Object} The new benchmark instance. * @example * * var bizarro = bench.clone({ * 'name': 'doppelganger' * }); */ function clone(options) { var me = this, result = new me.constructor(extend({}, me, options)); // correct the `options` object result.options = extend({}, me.options, options); // copy own custom properties forOwn(me, function(value, key) { if (!hasKey(result, key)) { result[key] = deepClone(value); } }); return result; } /** * Determines if a benchmark is faster than another. * * @memberOf Benchmark * @param {Object} other The benchmark to compare. * @returns {Number} Returns `-1` if slower, `1` if faster, and `0` if indeterminate. */ function compare(other) { var critical, zStat, me = this, sample1 = me.stats.sample, sample2 = other.stats.sample, size1 = sample1.length, size2 = sample2.length, maxSize = max(size1, size2), minSize = min(size1, size2), u1 = getU(sample1, sample2), u2 = getU(sample2, sample1), u = min(u1, u2); function getScore(xA, sampleB) { return reduce(sampleB, function(total, xB) { return total + (xB > xA ? 0 : xB < xA ? 1 : 0.5); }, 0); } function getU(sampleA, sampleB) { return reduce(sampleA, function(total, xA) { return total + getScore(xA, sampleB); }, 0); } function getZ(u) { return (u - ((size1 * size2) / 2)) / sqrt((size1 * size2 * (size1 + size2 + 1)) / 12); } // exit early if comparing the same benchmark if (me == other) { return 0; } // reject the null hyphothesis the two samples come from the // same population (i.e. have the same median) if... if (size1 + size2 > 30) { // ...the z-stat is greater than 1.96 or less than -1.96 // http://www.statisticslectures.com/topics/mannwhitneyu/ zStat = getZ(u); return abs(zStat) > 1.96 ? (zStat > 0 ? -1 : 1) : 0; } // ...the U value is less than or equal the critical U value // http://www.geoib.com/mann-whitney-u-test.html critical = maxSize < 5 || minSize < 3 ? 0 : uTable[maxSize][minSize - 3]; return u <= critical ? (u == u1 ? 1 : -1) : 0; } /** * Reset properties and abort if running. * * @memberOf Benchmark * @returns {Object} The benchmark instance. */ function reset() { var data, event, me = this, index = 0, changes = { 'length': 0 }, queue = { 'length': 0 }; if (me.running && !calledBy.abort) { // no worries, `reset()` is called within `abort()` calledBy.reset = true; me.abort(); delete calledBy.reset; } else { // a non-recursive solution to check if properties have changed // http://www.jslab.dk/articles/non.recursive.preorder.traversal.part4 data = { 'destination': me, 'source': extend({}, me.constructor.prototype, me.options) }; do { forOwn(data.source, function(value, key) { var changed, destination = data.destination, currValue = destination[key]; if (value && typeof value == 'object') { if (isClassOf(value, 'Array')) { // check if an array value has changed to a non-array value if (!isClassOf(currValue, 'Array')) { changed = currValue = []; } // or has changed its length if (currValue.length != value.length) { changed = currValue = currValue.slice(0, value.length); currValue.length = value.length; } } // check if an object has changed to a non-object value else if (!currValue || typeof currValue != 'object') { changed = currValue = {}; } // register a changed object if (changed) { changes[changes.length++] = { 'destination': destination, 'key': key, 'value': currValue }; } queue[queue.length++] = { 'destination': currValue, 'source': value }; } // register a changed primitive else if (value !== currValue && !(value == null || isClassOf(value, 'Function'))) { changes[changes.length++] = { 'destination': destination, 'key': key, 'value': value }; } }); } while ((data = queue[index++])); // if changed emit the `reset` event and if it isn't cancelled reset the benchmark if (changes.length && (me.emit(event = Event('reset')), !event.cancelled)) { forEach(changes, function(data) { data.destination[data.key] = data.value; }); } } return me; } /** * Displays relevant benchmark information when coerced to a string. * * @name toString * @memberOf Benchmark * @returns {String} A string representation of the benchmark instance. */ function toStringBench() { var me = this, error = me.error, hz = me.hz, id = me.id, stats = me.stats, size = stats.sample.length, pm = support.java ? '+/-' : '\xb1', result = me.name || (isNaN(id) ? id : ''); if (error) { result += ': ' + join(error); } else { result += ' x ' + formatNumber(hz.toFixed(hz < 100 ? 2 : 0)) + ' ops/sec ' + pm + stats.rme.toFixed(2) + '% (' + size + ' run' + (size == 1 ? '' : 's') + ' sampled)'; } return result; } /*--------------------------------------------------------------------------*/ /** * Clocks the time taken to execute a test per cycle (secs). * * @private * @param {Object} bench The benchmark instance. * @returns {Number} The time taken. */ function clock() { var applet, options = Benchmark.options, template = { 'begin': 's$=new n$', 'end': 'r$=(new n$-s$)/1e3', 'uid': uid }, timers = [{ 'ns': timer.ns, 'res': max(0.0015, getRes('ms')), 'unit': 'ms' }]; // lazy define for hi-res timers clock = function(clone) { var deferred; if (clone instanceof Deferred) { deferred = clone; clone = deferred.benchmark; } var bench = clone._original, fn = bench.fn, fnArg = deferred ? getFirstArgument(fn) || 'deferred' : '', stringable = isStringable(fn); var source = { 'setup': getSource(bench.setup, preprocess('m$.setup()')), 'fn': getSource(fn, preprocess('m$.fn(' + fnArg + ')')), 'fnArg': fnArg, 'teardown': getSource(bench.teardown, preprocess('m$.teardown()')) }; var count = bench.count = clone.count, decompilable = support.decompilation || stringable, id = bench.id, isEmpty = !(source.fn || stringable), name = bench.name || (typeof id == 'number' ? '' : id), ns = timer.ns, result = 0; // init `minTime` if needed clone.minTime = bench.minTime || (bench.minTime = bench.options.minTime = options.minTime); // repair nanosecond timer // (some Chrome builds erase the `ns` variable after millions of executions) if (applet) { try { ns.nanoTime(); } catch(e) { // use non-element to avoid issues with libs that augment them ns = timer.ns = new applet.Packages.nano; } } // Compile in setup/teardown functions and the test loop. // Create a new compiled test, instead of using the cached `bench.compiled`, // to avoid potential engine optimizations enabled over the life of the test. var compiled = bench.compiled = createFunction(preprocess('t$'), interpolate( preprocess(deferred ? 'var d$=this,#{fnArg}=d$,m$=d$.benchmark._original,f$=m$.fn,su$=m$.setup,td$=m$.teardown;' + // when `deferred.cycles` is `0` then... 'if(!d$.cycles){' + // set `deferred.fn` 'd$.fn=function(){var #{fnArg}=d$;if(typeof f$=="function"){try{#{fn}\n}catch(e$){f$(d$)}}else{#{fn}\n}};' + // set `deferred.teardown` 'd$.teardown=function(){d$.cycles=0;if(typeof td$=="function"){try{#{teardown}\n}catch(e$){td$()}}else{#{teardown}\n}};' + // execute the benchmark's `setup` 'if(typeof su$=="function"){try{#{setup}\n}catch(e$){su$()}}else{#{setup}\n};' + // start timer 't$.start(d$);' + // execute `deferred.fn` and return a dummy object '}d$.fn();return{}' : 'var r$,s$,m$=this,f$=m$.fn,i$=m$.count,n$=t$.ns;#{setup}\n#{begin};' + 'while(i$--){#{fn}\n}#{end};#{teardown}\nreturn{elapsed:r$,uid:"#{uid}"}'), source )); try { if (isEmpty) { // Firefox may remove dead code from Function#toString results // http://bugzil.la/536085 throw new Error('The test "' + name + '" is empty. This may be the result of dead code removal.'); } else if (!deferred) { // pretest to determine if compiled code is exits early, usually by a // rogue `return` statement, by checking for a return object with the uid bench.count = 1; compiled = (compiled.call(bench, timer) || {}).uid == uid && compiled; bench.count = count; } } catch(e) { compiled = null; clone.error = e || new Error(String(e)); bench.count = count; } // fallback when a test exits early or errors during pretest if (decompilable && !compiled && !deferred && !isEmpty) { compiled = createFunction(preprocess('t$'), interpolate( preprocess( (clone.error && !stringable ? 'var r$,s$,m$=this,f$=m$.fn,i$=m$.count' : 'function f$(){#{fn}\n}var r$,s$,m$=this,i$=m$.count' ) + ',n$=t$.ns;#{setup}\n#{begin};m$.f$=f$;while(i$--){m$.f$()}#{end};' + 'delete m$.f$;#{teardown}\nreturn{elapsed:r$}' ), source )); try { // pretest one more time to check for errors bench.count = 1; compiled.call(bench, timer); bench.compiled = compiled; bench.count = count; delete clone.error; } catch(e) { bench.count = count; if (clone.error) { compiled = null; } else { bench.compiled = compiled; clone.error = e || new Error(String(e)); } } } // assign `compiled` to `clone` before calling in case a deferred benchmark // immediately calls `deferred.resolve()` clone.compiled = compiled; // if no errors run the full test loop if (!clone.error) { result = compiled.call(deferred || bench, timer).elapsed; } return result; }; /*------------------------------------------------------------------------*/ /** * Gets the current timer's minimum resolution (secs). */ function getRes(unit) { var measured, begin, count = 30, divisor = 1e3, ns = timer.ns, sample = []; // get average smallest measurable time while (count--) { if (unit == 'us') { divisor = 1e6; if (ns.stop) { ns.start(); while (!(measured = ns.microseconds())) { } } else if (ns[perfName]) { divisor = 1e3; measured = Function('n', 'var r,s=n.' + perfName + '();while(!(r=n.' + perfName + '()-s)){};return r')(ns); } else { begin = ns(); while (!(measured = ns() - begin)) { } } } else if (unit == 'ns') { divisor = 1e9; if (ns.nanoTime) { begin = ns.nanoTime(); while (!(measured = ns.nanoTime() - begin)) { } } else { begin = (begin = ns())[0] + (begin[1] / divisor); while (!(measured = ((measured = ns())[0] + (measured[1] / divisor)) - begin)) { } divisor = 1; } } else { begin = new ns; while (!(measured = new ns - begin)) { } } // check for broken timers (nanoTime may have issues) // http://alivebutsleepy.srnet.cz/unreliable-system-nanotime/ if (measured > 0) { sample.push(measured); } else { sample.push(Infinity); break; } } // convert to seconds return getMean(sample) / divisor; } /** * Replaces all occurrences of `$` with a unique number and * template tokens with content. */ function preprocess(code) { return interpolate(code, template).replace(/\$/g, /\d+/.exec(uid)); } /*------------------------------------------------------------------------*/ // detect nanosecond support from a Java applet each(doc && doc.applets || [], function(element) { return !(timer.ns = applet = 'nanoTime' in element && element); }); // check type in case Safari returns an object instead of a number try { if (typeof timer.ns.nanoTime() == 'number') { timers.push({ 'ns': timer.ns, 'res': getRes('ns'), 'unit': 'ns' }); } } catch(e) { } // detect Chrome's microsecond timer: // enable benchmarking via the --enable-benchmarking command // line switch in at least Chrome 7 to use chrome.Interval try { if ((timer.ns = new (window.chrome || window.chromium).Interval)) { timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' }); } } catch(e) { } // detect `performance.now` microsecond resolution timer if ((timer.ns = perfName && perfObject)) { timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' }); } // detect Node's nanosecond resolution timer available in Node >= 0.8 if (processObject && typeof (timer.ns = processObject.hrtime) == 'function') { timers.push({ 'ns': timer.ns, 'res': getRes('ns'), 'unit': 'ns' }); } // detect Wade Simmons' Node microtime module if (microtimeObject && typeof (timer.ns = microtimeObject.now) == 'function') { timers.push({ 'ns': timer.ns, 'res': getRes('us'), 'unit': 'us' }); } // pick timer with highest resolution timer = reduce(timers, function(timer, other) { return other.res < timer.res ? other : timer; }); // remove unused applet if (timer.unit != 'ns' && applet) { applet = destroyElement(applet); } // error if there are no working timers if (timer.res == Infinity) { throw new Error('Benchmark.js was unable to find a working timer.'); } // use API of chosen timer if (timer.unit == 'ns') { if (timer.ns.nanoTime) { extend(template, { 'begin': 's$=n$.nanoTime()', 'end': 'r$=(n$.nanoTime()-s$)/1e9' }); } else { extend(template, { 'begin': 's$=n$()', 'end': 'r$=n$(s$);r$=r$[0]+(r$[1]/1e9)' }); } } else if (timer.unit == 'us') { if (timer.ns.stop) { extend(template, { 'begin': 's$=n$.start()', 'end': 'r$=n$.microseconds()/1e6' }); } else if (perfName) { extend(template, { 'begin': 's$=n$.' + perfName + '()', 'end': 'r$=(n$.' + perfName + '()-s$)/1e3' }); } else { extend(template, { 'begin': 's$=n$()', 'end': 'r$=(n$()-s$)/1e6' }); } } // define `timer` methods timer.start = createFunction(preprocess('o$'), preprocess('var n$=this.ns,#{begin};o$.elapsed=0;o$.timeStamp=s$')); timer.stop = createFunction(preprocess('o$'), preprocess('var n$=this.ns,s$=o$.timeStamp,#{end};o$.elapsed=r$')); // resolve time span required to achieve a percent uncertainty of at most 1% // http://spiff.rit.edu/classes/phys273/uncert/uncert.html options.minTime || (options.minTime = max(timer.res / 2 / 0.01, 0.05)); return clock.apply(null, arguments); } /*--------------------------------------------------------------------------*/ /** * Computes stats on benchmark results. * * @private * @param {Object} bench The benchmark instance. * @param {Object} options The options object. */ function compute(bench, options) { options || (options = {}); var async = options.async, elapsed = 0, initCount = bench.initCount, minSamples = bench.minSamples, queue = [], sample = bench.stats.sample; /** * Adds a clone to the queue. */ function enqueue() { queue.push(bench.clone({ '_original': bench, 'events': { 'abort': [update], 'cycle': [update], 'error': [update], 'start': [update] } })); } /** * Updates the clone/original benchmarks to keep their data in sync. */ function update(event) { var clone = this, type = event.type; if (bench.running) { if (type == 'start') { // Note: `clone.minTime` prop is inited in `clock()` clone.count = bench.initCount; } else { if (type == 'error') { bench.error = clone.error; } if (type == 'abort') { bench.abort(); bench.emit('cycle'); } else { event.currentTarget = event.target = bench; bench.emit(event); } } } else if (bench.aborted) { // clear abort listeners to avoid triggering bench's abort/cycle again clone.events.abort.length = 0; clone.abort(); } } /** * Determines if more clones should be queued or if cycling should stop. */ function evaluate(event) { var critical, df, mean, moe, rme, sd, sem, variance, clone = event.target, done = bench.aborted, now = +new Date, size = sample.push(clone.times.period), maxedOut = size >= minSamples && (elapsed += now - clone.times.timeStamp) / 1e3 > bench.maxTime, times = bench.times, varOf = function(sum, x) { return sum + pow(x - mean, 2); }; // exit early for aborted or unclockable tests if (done || clone.hz == Infinity) { maxedOut = !(size = sample.length = queue.length = 0); } if (!done) { // sample mean (estimate of the population mean) mean = getMean(sample); // sample variance (estimate of the population variance) variance = reduce(sample, varOf, 0) / (size - 1) || 0; // sample standard deviation (estimate of the population standard deviation) sd = sqrt(variance); // standard error of the mean (a.k.a. the standard deviation of the sampling distribution of the sample mean) sem = sd / sqrt(size); // degrees of freedom df = size - 1; // critical value critical = tTable[Math.round(df) || 1] || tTable.infinity; // margin of error moe = sem * critical; // relative margin of error rme = (moe / mean) * 100 || 0; extend(bench.stats, { 'deviation': sd, 'mean': mean, 'moe': moe, 'rme': rme, 'sem': sem, 'variance': variance }); // Abort the cycle loop when the minimum sample size has been collected // and the elapsed time exceeds the maximum time allowed per benchmark. // We don't count cycle delays toward the max time because delays may be // increased by browsers that clamp timeouts for inactive tabs. // https://developer.mozilla.org/en/window.setTimeout#Inactive_tabs if (maxedOut) { // reset the `initCount` in case the benchmark is rerun bench.initCount = initCount; bench.running = false; done = true; times.elapsed = (now - times.timeStamp) / 1e3; } if (bench.hz != Infinity) { bench.hz = 1 / mean; times.cycle = mean * bench.count; times.period = mean; } } // if time permits, increase sample size to reduce the margin of error if (queue.length < 2 && !maxedOut) { enqueue(); } // abort the invoke cycle when done event.aborted = done; } // init queue and begin enqueue(); invoke(queue, { 'name': 'run', 'args': { 'async': async }, 'queued': true, 'onCycle': evaluate, 'onComplete': function() { bench.emit('complete'); } }); } /*--------------------------------------------------------------------------*/ /** * Cycles a benchmark until a run `count` can be established. * * @private * @param {Object} clone The cloned benchmark instance. * @param {Object} options The options object. */ function cycle(clone, options) { options || (options = {}); var deferred; if (clone instanceof Deferred) { deferred = clone; clone = clone.benchmark; } var clocked, cycles, divisor, event, minTime, period, async = options.async, bench = clone._original, count = clone.count, times = clone.times; // continue, if not aborted between cycles if (clone.running) { // `minTime` is set to `Benchmark.options.minTime` in `clock()` cycles = ++clone.cycles; clocked = deferred ? deferred.elapsed : clock(clone); minTime = clone.minTime; if (cycles > bench.cycles) { bench.cycles = cycles; } if (clone.error) { event = Event('error'); event.message = clone.error; clone.emit(event); if (!event.cancelled) { clone.abort(); } } } // continue, if not errored if (clone.running) { // time taken to complete last test cycle bench.times.cycle = times.cycle = clocked; // seconds per operation period = bench.times.period = times.period = clocked / count; // ops per second bench.hz = clone.hz = 1 / period; // avoid working our way up to this next time bench.initCount = clone.initCount = count; // do we need to do another cycle? clone.running = clocked < minTime; if (clone.running) { // tests may clock at `0` when `initCount` is a small number, // to avoid that we set its count to something a bit higher if (!clocked && (divisor = divisors[clone.cycles]) != null) { count = floor(4e6 / divisor); } // calculate how many more iterations it will take to achive the `minTime` if (count <= clone.count) { count += Math.ceil((minTime - clocked) / period); } clone.running = count != Infinity; } } // should we exit early? event = Event('cycle'); clone.emit(event); if (event.aborted) { clone.abort(); } // figure out what to do next if (clone.running) { // start a new cycle clone.count = count; if (deferred) { clone.compiled.call(deferred, timer); } else if (async) { delay(clone, function() { cycle(clone, options); }); } else { cycle(clone); } } else { // fix TraceMonkey bug associated with clock fallbacks // http://bugzil.la/509069 if (support.browser) { runScript(uid + '=1;delete ' + uid); } // done clone.emit('complete'); } } /*--------------------------------------------------------------------------*/ /** * Runs the benchmark. * * @memberOf Benchmark * @param {Object} [options={}] Options object. * @returns {Object} The benchmark instance. * @example * * // basic usage * bench.run(); * * // or with options * bench.run({ 'async': true }); */ function run(options) { var me = this, event = Event('start'); // set `running` to `false` so `reset()` won't call `abort()` me.running = false; me.reset(); me.running = true; me.count = me.initCount; me.times.timeStamp = +new Date; me.emit(event); if (!event.cancelled) { options = { 'async': ((options = options && options.async) == null ? me.async : options) && support.timeout }; // for clones created within `compute()` if (me._original) { if (me.defer) { Deferred(me); } else { cycle(me, options); } } // for original benchmarks else { compute(me, options); } } return me; } /*--------------------------------------------------------------------------*/ // Firefox 1 erroneously defines variable and argument names of functions on // the function itself as non-configurable properties with `undefined` values. // The bugginess continues as the `Benchmark` constructor has an argument // named `options` and Firefox 1 will not assign a value to `Benchmark.options`, // making it non-writable in the process, unless it is the first property // assigned by for-in loop of `extend()`. extend(Benchmark, { /** * The default options copied by benchmark instances. * * @static * @memberOf Benchmark * @type Object */ 'options': { /** * A flag to indicate that benchmark cycles will execute asynchronously * by default. * * @memberOf Benchmark.options * @type Boolean */ 'async': false, /** * A flag to indicate that the benchmark clock is deferred. * * @memberOf Benchmark.options * @type Boolean */ 'defer': false, /** * The delay between test cycles (secs). * @memberOf Benchmark.options * @type Number */ 'delay': 0.005, /** * Displayed by Benchmark#toString when a `name` is not available * (auto-generated if absent). * * @memberOf Benchmark.options * @type String */ 'id': undefined, /** * The default number of times to execute a test on a benchmark's first cycle. * * @memberOf Benchmark.options * @type Number */ 'initCount': 1, /** * The maximum time a benchmark is allowed to run before finishing (secs). * Note: Cycle delays aren't counted toward the maximum time. * * @memberOf Benchmark.options * @type Number */ 'maxTime': 5, /** * The minimum sample size required to perform statistical analysis. * * @memberOf Benchmark.options * @type Number */ 'minSamples': 5, /** * The time needed to reduce the percent uncertainty of measurement to 1% (secs). * * @memberOf Benchmark.options * @type Number */ 'minTime': 0, /** * The name of the benchmark. * * @memberOf Benchmark.options * @type String */ 'name': undefined, /** * An event listener called when the benchmark is aborted. * * @memberOf Benchmark.options * @type Function */ 'onAbort': undefined, /** * An event listener called when the benchmark completes running. * * @memberOf Benchmark.options * @type Function */ 'onComplete': undefined, /** * An event listener called after each run cycle. * * @memberOf Benchmark.options * @type Function */ 'onCycle': undefined, /** * An event listener called when a test errors. * * @memberOf Benchmark.options * @type Function */ 'onError': undefined, /** * An event listener called when the benchmark is reset. * * @memberOf Benchmark.options * @type Function */ 'onReset': undefined, /** * An event listener called when the benchmark starts running. * * @memberOf Benchmark.options * @type Function */ 'onStart': undefined }, /** * Platform object with properties describing things like browser name, * version, and operating system. * * @static * @memberOf Benchmark * @type Object */ 'platform': req('platform') || window.platform || { /** * The platform description. * * @memberOf Benchmark.platform * @type String */ 'description': window.navigator && navigator.userAgent || null, /** * The name of the browser layout engine. * * @memberOf Benchmark.platform * @type String|Null */ 'layout': null, /** * The name of the product hosting the browser. * * @memberOf Benchmark.platform * @type String|Null */ 'product': null, /** * The name of the browser/environment. * * @memberOf Benchmark.platform * @type String|Null */ 'name': null, /** * The name of the product's manufacturer. * * @memberOf Benchmark.platform * @type String|Null */ 'manufacturer': null, /** * The name of the operating system. * * @memberOf Benchmark.platform * @type String|Null */ 'os': null, /** * The alpha/beta release indicator. * * @memberOf Benchmark.platform * @type String|Null */ 'prerelease': null, /** * The browser/environment version. * * @memberOf Benchmark.platform * @type String|Null */ 'version': null, /** * Return platform description when the platform object is coerced to a string. * * @memberOf Benchmark.platform * @type Function * @returns {String} The platform description. */ 'toString': function() { return this.description || ''; } }, /** * The semantic version number. * * @static * @memberOf Benchmark * @type String */ 'version': '1.0.0', // an object of environment/feature detection flags 'support': support, // clone objects 'deepClone': deepClone, // iteration utility 'each': each, // augment objects 'extend': extend, // generic Array#filter 'filter': filter, // generic Array#forEach 'forEach': forEach, // generic own property iteration utility 'forOwn': forOwn, // converts a number to a comma-separated string 'formatNumber': formatNumber, // generic Object#hasOwnProperty // (trigger hasKey's lazy define before assigning it to Benchmark) 'hasKey': (hasKey(Benchmark, ''), hasKey), // generic Array#indexOf 'indexOf': indexOf, // template utility 'interpolate': interpolate, // invokes a method on each item in an array 'invoke': invoke, // generic Array#join for arrays and objects 'join': join, // generic Array#map 'map': map, // retrieves a property value from each item in an array 'pluck': pluck, // generic Array#reduce 'reduce': reduce }); /*--------------------------------------------------------------------------*/ extend(Benchmark.prototype, { /** * The number of times a test was executed. * * @memberOf Benchmark * @type Number */ 'count': 0, /** * The number of cycles performed while benchmarking. * * @memberOf Benchmark * @type Number */ 'cycles': 0, /** * The number of executions per second. * * @memberOf Benchmark * @type Number */ 'hz': 0, /** * The compiled test function. * * @memberOf Benchmark * @type Function|String */ 'compiled': undefined, /** * The error object if the test failed. * * @memberOf Benchmark * @type Object */ 'error': undefined, /** * The test to benchmark. * * @memberOf Benchmark * @type Function|String */ 'fn': undefined, /** * A flag to indicate if the benchmark is aborted. * * @memberOf Benchmark * @type Boolean */ 'aborted': false, /** * A flag to indicate if the benchmark is running. * * @memberOf Benchmark * @type Boolean */ 'running': false, /** * Compiled into the test and executed immediately **before** the test loop. * * @memberOf Benchmark * @type Function|String * @example * * // basic usage * var bench = Benchmark({ * 'setup': function() { * var c = this.count, * element = document.getElementById('container'); * while (c--) { * element.appendChild(document.createElement('div')); * } * }, * 'fn': function() { * element.removeChild(element.lastChild); * } * }); * * // compiles to something like: * var c = this.count, * element = document.getElementById('container'); * while (c--) { * element.appendChild(document.createElement('div')); * } * var start = new Date; * while (count--) { * element.removeChild(element.lastChild); * } * var end = new Date - start; * * // or using strings * var bench = Benchmark({ * 'setup': '\ * var a = 0;\n\ * (function() {\n\ * (function() {\n\ * (function() {', * 'fn': 'a += 1;', * 'teardown': '\ * }())\n\ * }())\n\ * }())' * }); * * // compiles to something like: * var a = 0; * (function() { * (function() { * (function() { * var start = new Date; * while (count--) { * a += 1; * } * var end = new Date - start; * }()) * }()) * }()) */ 'setup': noop, /** * Compiled into the test and executed immediately **after** the test loop. * * @memberOf Benchmark * @type Function|String */ 'teardown': noop, /** * An object of stats including mean, margin or error, and standard deviation. * * @memberOf Benchmark * @type Object */ 'stats': { /** * The margin of error. * * @memberOf Benchmark#stats * @type Number */ 'moe': 0, /** * The relative margin of error (expressed as a percentage of the mean). * * @memberOf Benchmark#stats * @type Number */ 'rme': 0, /** * The standard error of the mean. * * @memberOf Benchmark#stats * @type Number */ 'sem': 0, /** * The sample standard deviation. * * @memberOf Benchmark#stats * @type Number */ 'deviation': 0, /** * The sample arithmetic mean. * * @memberOf Benchmark#stats * @type Number */ 'mean': 0, /** * The array of sampled periods. * * @memberOf Benchmark#stats * @type Array */ 'sample': [], /** * The sample variance. * * @memberOf Benchmark#stats * @type Number */ 'variance': 0 }, /** * An object of timing data including cycle, elapsed, period, start, and stop. * * @memberOf Benchmark * @type Object */ 'times': { /** * The time taken to complete the last cycle (secs). * * @memberOf Benchmark#times * @type Number */ 'cycle': 0, /** * The time taken to complete the benchmark (secs). * * @memberOf Benchmark#times * @type Number */ 'elapsed': 0, /** * The time taken to execute the test once (secs). * * @memberOf Benchmark#times * @type Number */ 'period': 0, /** * A timestamp of when the benchmark started (ms). * * @memberOf Benchmark#times * @type Number */ 'timeStamp': 0 }, // aborts benchmark (does not record times) 'abort': abort, // creates a new benchmark using the same test and options 'clone': clone, // compares benchmark's hertz with another 'compare': compare, // executes listeners 'emit': emit, // get listeners 'listeners': listeners, // unregister listeners 'off': off, // register listeners 'on': on, // reset benchmark properties 'reset': reset, // runs the benchmark 'run': run, // pretty print benchmark info 'toString': toStringBench }); /*--------------------------------------------------------------------------*/ extend(Deferred.prototype, { /** * The deferred benchmark instance. * * @memberOf Benchmark.Deferred * @type Object */ 'benchmark': null, /** * The number of deferred cycles performed while benchmarking. * * @memberOf Benchmark.Deferred * @type Number */ 'cycles': 0, /** * The time taken to complete the deferred benchmark (secs). * * @memberOf Benchmark.Deferred * @type Number */ 'elapsed': 0, /** * A timestamp of when the deferred benchmark started (ms). * * @memberOf Benchmark.Deferred * @type Number */ 'timeStamp': 0, // cycles/completes the deferred benchmark 'resolve': resolve }); /*--------------------------------------------------------------------------*/ extend(Event.prototype, { /** * A flag to indicate if the emitters listener iteration is aborted. * * @memberOf Benchmark.Event * @type Boolean */ 'aborted': false, /** * A flag to indicate if the default action is cancelled. * * @memberOf Benchmark.Event * @type Boolean */ 'cancelled': false, /** * The object whose listeners are currently being processed. * * @memberOf Benchmark.Event * @type Object */ 'currentTarget': undefined, /** * The return value of the last executed listener. * * @memberOf Benchmark.Event * @type Mixed */ 'result': undefined, /** * The object to which the event was originally emitted. * * @memberOf Benchmark.Event * @type Object */ 'target': undefined, /** * A timestamp of when the event was created (ms). * * @memberOf Benchmark.Event * @type Number */ 'timeStamp': 0, /** * The event type. * * @memberOf Benchmark.Event * @type String */ 'type': '' }); /*--------------------------------------------------------------------------*/ /** * The default options copied by suite instances. * * @static * @memberOf Benchmark.Suite * @type Object */ Suite.options = { /** * The name of the suite. * * @memberOf Benchmark.Suite.options * @type String */ 'name': undefined }; /*--------------------------------------------------------------------------*/ extend(Suite.prototype, { /** * The number of benchmarks in the suite. * * @memberOf Benchmark.Suite * @type Number */ 'length': 0, /** * A flag to indicate if the suite is aborted. * * @memberOf Benchmark.Suite * @type Boolean */ 'aborted': false, /** * A flag to indicate if the suite is running. * * @memberOf Benchmark.Suite * @type Boolean */ 'running': false, /** * An `Array#forEach` like method. * Callbacks may terminate the loop by explicitly returning `false`. * * @memberOf Benchmark.Suite * @param {Function} callback The function called per iteration. * @returns {Object} The suite iterated over. */ 'forEach': methodize(forEach), /** * An `Array#indexOf` like method. * * @memberOf Benchmark.Suite * @param {Mixed} value The value to search for. * @returns {Number} The index of the matched value or `-1`. */ 'indexOf': methodize(indexOf), /** * Invokes a method on all benchmarks in the suite. * * @memberOf Benchmark.Suite * @param {String|Object} name The name of the method to invoke OR options object. * @param {Mixed} [arg1, arg2, ...] Arguments to invoke the method with. * @returns {Array} A new array of values returned from each method invoked. */ 'invoke': methodize(invoke), /** * Converts the suite of benchmarks to a string. * * @memberOf Benchmark.Suite * @param {String} [separator=','] A string to separate each element of the array. * @returns {String} The string. */ 'join': [].join, /** * An `Array#map` like method. * * @memberOf Benchmark.Suite * @param {Function} callback The function called per iteration. * @returns {Array} A new array of values returned by the callback. */ 'map': methodize(map), /** * Retrieves the value of a specified property from all benchmarks in the suite. * * @memberOf Benchmark.Suite * @param {String} property The property to pluck. * @returns {Array} A new array of property values. */ 'pluck': methodize(pluck), /** * Removes the last benchmark from the suite and returns it. * * @memberOf Benchmark.Suite * @returns {Mixed} The removed benchmark. */ 'pop': [].pop, /** * Appends benchmarks to the suite. * * @memberOf Benchmark.Suite * @returns {Number} The suite's new length. */ 'push': [].push, /** * Sorts the benchmarks of the suite. * * @memberOf Benchmark.Suite * @param {Function} [compareFn=null] A function that defines the sort order. * @returns {Object} The sorted suite. */ 'sort': [].sort, /** * An `Array#reduce` like method. * * @memberOf Benchmark.Suite * @param {Function} callback The function called per iteration. * @param {Mixed} accumulator Initial value of the accumulator. * @returns {Mixed} The accumulator. */ 'reduce': methodize(reduce), // aborts all benchmarks in the suite 'abort': abortSuite, // adds a benchmark to the suite 'add': add, // creates a new suite with cloned benchmarks 'clone': cloneSuite, // executes listeners of a specified type 'emit': emit, // creates a new suite of filtered benchmarks 'filter': filterSuite, // get listeners 'listeners': listeners, // unregister listeners 'off': off, // register listeners 'on': on, // resets all benchmarks in the suite 'reset': resetSuite, // runs all benchmarks in the suite 'run': runSuite, // array methods 'concat': concat, 'reverse': reverse, 'shift': shift, 'slice': slice, 'splice': splice, 'unshift': unshift }); /*--------------------------------------------------------------------------*/ // expose Deferred, Event and Suite extend(Benchmark, { 'Deferred': Deferred, 'Event': Event, 'Suite': Suite }); // expose Benchmark // some AMD build optimizers, like r.js, check for specific condition patterns like the following: if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { // define as an anonymous module so, through path mapping, it can be aliased define(function() { return Benchmark; }); } // check for `exports` after `define` in case a build optimizer adds an `exports` object else if (freeExports) { // in Node.js or RingoJS v0.8.0+ if (typeof module == 'object' && module && module.exports == freeExports) { (module.exports = Benchmark).Benchmark = Benchmark; } // in RingoJS v0.7.0- else { freeExports.Benchmark = Benchmark; } } // in a browser or Rhino else { // use square bracket notation so Closure Compiler won't munge `Benchmark` // http://code.google.com/closure/compiler/docs/api-tutorial3.html#export window['Benchmark'] = Benchmark; } // trigger clock's lazy define early to avoid a security error if (support.air) { clock({ '_original': { 'fn': noop, 'count': 1, 'options': {} } }); } }(this)); luaparse-0.3.1/test/lib/newton.css000066400000000000000000000046661405615720100171150ustar00rootroot00000000000000/*! * QUnit Styles for Newton * http://github.com/jquery/unit * * Based on work by Ben Alman. * http://benalman.com */ body { font: 13px 'Helvetica Neue Light', 'HelveticaNeue-Light', 'Helvetica Neue', Calibri, Helvetica, Arial; } p, ol, .suiteStatus { margin: 0; padding: 0; } p { padding: 0.4em 0.5em 0.4em 2.5em; border-bottom: 1px solid #fff; } a { color: inherit; text-decoration: underline; } a:hover, a:focus { text-decoration: none; } p a { color: #FF7F00; } li { list-style-position: inside; } p, .testRunning, .testPassed { color: #913D00; background-color: #FDEBDC; } .testFailed { background-color: #f99; color: #000; } .assertionList, .suiteHeader, .suiteSummary { -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; } .suiteHeader { color: #fff; background-color: #FF7F00; margin: 0; padding: 0.5em 1em; font-size: 24px; -webkit-border-bottom-right-radius: 0; -webkit-border-bottom-left-radius: 0; -moz-border-radius-bottomright: 0; -moz-border-radius-bottomleft: 0; border-bottom-right-radius: 0; border-bottom-left-radius: 0; } .suiteStatus { height: 5px; } .suiteRunning { background-color: #913D00; } .suitePassed { background-color: #0a0; } .suiteFailed { background-color: #f99; } .testBlock { padding: 0.4em 2.5em; border-bottom: 1px solid #fff; } .testName { cursor: pointer; } .assertionList { margin-top: 0.5em; padding: 0.5em; background-color: #fff; -moz-box-shadow: inset 0px 1px 8px #ccc; -webkit-box-shadow: inset 0px 1px 8px #ccc; box-shadow: inset 0px 1px 8px #ccc; } .assertionPassed, .assertionFailed { border-bottom: none; margin: 0.5em; background-color: #fff; list-style-position: inside; padding: 0.4em 0.5em; } .assertionPassed { border-left: 26px solid #0a0; background-color: #fff; color: #0a0; } .assertionFailed { border-left: 26px solid #f00; background-color: #fff; color: #f00; } .failureActual, .failureExpected { display: block; font-weight: bold; } .failureActual { color: #EE5757; } .failureExpected { color: green; } .jsonValue { font-weight: normal; } .suiteSummary { margin: 0; color: #913D00; background-color: #FDEBDC; padding: 0.5em 0.5em 0.5em 2.5em; -moz-border-radius-topright: 0; -moz-border-radius-topleft: 0; -webkit-border-top-right-radius: 0; -webkit-border-top-left-radius: 0; border-top-right-radius: 0; border-top-left-radius: 0; }luaparse-0.3.1/test/lib/newton.js000066400000000000000000000554151405615720100167370ustar00rootroot00000000000000/*! * Newton: a utility library for Spec * Provides logging and basic introspection functions. * * Copyright 2012, Kit Cambridge */ ;(function (root, definition) { // Detect asynchronous module loaders and CommonJS environments. var isLoader = typeof define == "function" && !!define.amd, isModule = typeof require == "function" && typeof exports == "object" && exports && !isLoader, // Weak object inferences for detecting browsers and JS engines. isBrowser = "window" in root && root.window == root && typeof root.navigator != "undefined", isEngine = !isBrowser && !isModule && typeof root.load == "function", Environment = { "isLoader": isLoader, "isModule": isModule, "isBrowser": isBrowser, "isEngine": isEngine }, Spec, Newton; if (isLoader) { // Export the plugin for asynchronous module loaders. define(["exports", "spec"], function (exports, Spec) { return definition(Environment, exports, Spec); }); } else if (isModule) { // Export for CommonJS environments. try { // Load Spec. Spec = require("./spec"); } catch (exception) {} definition(Environment, exports, Spec || {}); } else { // Export for web browsers and JavaScript engines. if (isBrowser) { Environment.document = root.document; } Newton = definition(Environment, (root.Newton = { "noConflict": (function (original) { function noConflict() { root.Newton = original; delete Newton.noConflict; return Newton; } return noConflict; })(root.Newton) }), root.Spec || {}); } })(this, function (Environment, exports, Spec) { "use strict"; // Convenience aliases. var getClass = {}.toString, document = Environment.document, // **stringify** returns a debug-oriented representation of an object, similar to // `JSON.stringify`. Objects are serialized according to a superset of the JSON encoding // algorithm. stringify = exports.stringify = (function () { function stringify(object) { return serialize(object, []); } // Converts `value` into a zero-padded string such that its length is at // least equal to `width`. The `width` must be <= 6. function toPaddedString(width, value) { return ("000000" + value).slice(-width); } // Maps control characters to their escaped equivalents. var Escapes = { "\\": "\\\\", '"': '\\"', "\b": "\\b", "\f": "\\f", "\n": "\\n", "\r": "\\r", "\t": "\\t" }; // Double-quotes a string, replacing all ASCII control characters with their // escaped equivalents. function quote(value) { var result = '"', index = 0, symbol; for (; symbol = value.charAt(index); index += 1) { // Escape the reverse solidus, double quote, backspace, form feed, line // feed, carriage return, and tab characters. result += '\\"\b\f\n\r\t'.indexOf(symbol) > -1 ? Escapes[symbol] : // If the character is a control character, append its Unicode escape // sequence; otherwise, append the character as-is. symbol < " " ? "\\u" + toPaddedString(4, symbol.charCodeAt(0).toString(16)) : symbol; } return result + '"'; } // `serialize` recursively serializes an object. function serialize(value, stack) { var className, length, element, result, year; if (value == null) { return "null"; } className = getClass.call(value); switch (className) { case "[object Number]": case "[object Boolean]": // JSON numbers must be finite. `Infinity` and `NaN` are converted // to `"null"`. return isEmpty(value) ? "null" : "" + value; case "[object String]": // Strings are double-quoted and escaped. return quote(value); case "[object Date]": if (isEmpty(value)) { return "null"; } // Dates are serialized according to the `Date.toJSON` method // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15 for // the ISO 8601 date time string format. year = value.getUTCFullYear(); // Serialize extended years correctly. return '"' + (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, Math.abs(year)) : toPaddedString(4, year)) + "-" + toPaddedString(2, value.getUTCMonth() + 1) + "-" + toPaddedString(2, value.getUTCDate()) + // Months, dates, hours, minutes, and seconds should have two // digits; milliseconds should have three. "T" + toPaddedString(2, value.getUTCHours()) + ":" + toPaddedString(2, value.getUTCMinutes()) + ":" + toPaddedString(2, value.getUTCSeconds()) + // Milliseconds are optional in ES 5.0, but required in 5.1. "." + toPaddedString(3, value.getUTCMilliseconds()) + 'Z"'; case "[object RegExp]": return substitute('{"source": %s, "global": %s, "ignoreCase": %s, "multiline": %s}', quote(value.source), value.global, value.ignoreCase, value.multiline); } // Recursively serialize objects and arrays. if (typeof value == "object") { // ES 5.1 section 15.12.3 dictates that JSON structures must be acyclic. // `stringify` replaces all circular references with `null` to avoid // infinite recursion. for (length = stack.length; length--;) { if (stack[length] == value) { return "null"; } } // Add the object to the stack of traversed objects. stack.push(value); result = []; if (className == "[object Array]") { // Recursively serialize array elements. for (length = value.length; length--;) { if (length in value) { result[length] = serialize(value[length], stack); } } return "[" + result.join(", ") + "]"; } else { Spec.forOwn(value, function (key, value) { // Recursively serialize object members. result.push(quote(key) + ": " + serialize(value, stack)); }); return "{" + result.join(", ") + "}"; } // Remove the object from the traversed object stack. stack.pop(); } return "null"; } return stringify; })(), // **all** determines whether the callback returns `true` for all object // members. all = exports.all = function all(object, callback, context) { var result = true; Spec.forOwn(object, function (key, value, object) { return result = !!callback.call(context, key, value, object); }); return result; }, // Internal; produces an encoded `parameter=value` pair. toQueryPair = function toQueryPair(parameter, value) { parameter = encodeURIComponent(parameter); if (value == null) { return parameter; } switch (getClass.call(value)) { case "[object String]": case "[object Number]": case "[object Boolean]": return parameter + "=" + encodeURIComponent(value); } }, // **serializeQuery** returns a query string containing the contents of the // `map` serialized as `parameter=value` pairs. `null` and `undefined` values // produce parameters without value portions; array values produce // identically-named parameters for each element. All values are encoded using // the `encodeURIComponent` function. The order of the pairs in the resulting // string is not guaranteed. serializeQuery = exports.serializeQuery = function serializeQuery(map, separator) { var result = [], member; Spec.forOwn(map, function (parameter, value) { if (value && getClass.call(value) == "[object Array]") { Spec.forEach(value, function (value) { var member = toQueryPair(parameter, value); if (member) { result.push(member); } }); } else if ((member = toQueryPair(parameter, value))) { result.push(member); } }); return result.join(separator || "&"); }, // **parseQuery** parses a query `string` and returns an object containing // the URL-decoded `parameter=value` pairs. If the `string` contains a `?` or // `#` character, all characters before the `?` and after the `#` are ignored. // The values of identical parameters (e.g., `a=1&a=2`) are aggregated into an // array of values. Parameters without corresponding values are set to `null`. // The `separator` argument is optional, and defaults to `"&"`. parseQuery = exports.parseQuery = function parseQuery(string, separator) { var match = ("" + string).split("?"), results = {}, member, parameter, value, index, position, members, length; // Ensure that the given value contains a query string. if (match.length > 1 && !match[1] || !(((match = (match = match[1] || match[0]).split("#"))) && (match = match[0].split(" ")[0]))) { return results; } members = match.split(separator || "&"); for (index = 0, length = members.length; index < length; index += 1) { value = null; position = (member = members[index]).indexOf("="); if (member && position) { if (position > -1) { parameter = decodeURIComponent(member.slice(0, position)); if ((value = member.slice(position + 1))) { value = decodeURIComponent(value); } } else { parameter = member; } if (Spec.hasKey(results, parameter)) { if (getClass.call(results[parameter]) != "[object Array]") { results[parameter] = [results[parameter]]; } results[parameter].push(value); } else { results[parameter] = value; } } } return results; }, // **isEmpty** checks if the given `value` is empty. isEmpty = exports.isEmpty = function isEmpty(value) { var result; if (value == null) { return true; } switch (getClass.call(value)) { case "[object Number]": case "[object Date]": // `NaN` values are considered empty. value = +value; return value != value || false; case "[object Boolean]": case "[object Function]": case "[object RegExp]": return false; case "[object String]": case "[object Array]": return !value.length; default: return all(function () { return false; }, value); } }, // **substitute** formats a string containing `sprintf`-style specifiers by // successively interpolating the provided replacement arguments. substitute = exports.substitute = function substitute(value) { var result, argument, index, length, symbol, directive; value = "" + value; if (value.indexOf("%") < 0 || arguments.length < 2) { return value; } for (result = "", argument = 1, index = 0, length = value.length; index < length; index += 1) { symbol = value.charAt(index); if (symbol == "%") { directive = value.charAt(index + 1); if (directive == "%") { // Escape sequence; append a literal `%` character. result += directive; } else { if (argument in arguments) { // Format replacement arguments according to the directive. switch (directive) { // Floor integers. `NaN` is converted to `0`. case "i": case "d": result += Math.floor(arguments[argument]) || 0; break; // Represent floating-point values as-is. case "f": result += +arguments[argument] || 0; break; // Serialize objects. case "o": result += stringify(arguments[argument]); break; // Coerce all other values to strings. default: result += arguments[argument]; } } else { // No replacement argument; append the format specifier as-is. result += symbol + directive; } // Use the next replacement argument for the subsequent interpolation. argument += 1; } index += 1; } else { result += symbol; } } return result; }, // **createConsole** creates a new console-based logger. createConsole = exports.createConsole = function createConsole(print) { function onEvent(event) { switch (event.type) { case "start": print(substitute("Started spec `%s`.", this.name)); break; case "setup": print(substitute("Started test `%s`.", event.target.name)); break; case "assertion": print(substitute("Assertion: %s.", event.message)); break; case "failure": print(substitute("Failure: %s. Expected: %o. Actual: %o.", event.message, event.expected, event.actual)); break; case "teardown": print(substitute("Finished test `%s`. %d assertions, %d failures.", event.target.name, event.target.assertions, event.target.failures)); break; case "complete": print(substitute("Finished spec `%s`. %d assertions, %d failures.", this.name, this.assertions, this.failures)); } } return onEvent; }, // **createTAP** creates a new TAP-based reporter. createTAP = exports.createTAP = function createTAP(print) { var testNumber = 0; // Sanitize TAP descriptions by removing directive delimiter. function description(description) { return description.replace(/#/g, ''); } function onEvent(event) { switch (event.type) { case "assertion": print(substitute("ok %d %s", ++testNumber, description(event.message))); break; case "failure": print(substitute("not ok %d %s", ++testNumber, description(event.message))); print(substitute(" Expected: %o", event.expected)); print(substitute(" Actual: %o", event.actual)); break; case "complete": print(substitute('# tests %d', testNumber)); print(substitute('# pass %d', this.assertions)); print(substitute('# fail %d', this.failures)); print(substitute('%d..%d', 1, this.assertions + this.failures)); break; } } return onEvent; }, // DOM-only methods. onClick, buildNode, clearElement, createReport; if (document) { // Internal; expands and collapses the test message list. onClick = function onClick() { // The event target is the list of messages. var target = this.parentNode && this.parentNode.childNodes[1]; if (target) { target.style.display = target.style.display == "none" ? "" : "none"; } }; // **buildNode** creates and returns a new element with the given `tagName`, // DOM `properties`, and `children`. buildNode = exports.buildNode = (function () { // Internal: Tests whether `document.createElement` supports the MSHTML // extended syntax. This syntax is necessary for setting the `name` and // `type` properties of elements, which are read-only in IE 7 and earlier. var supportsExtendedElementSyntax = (function () { var element, result = false; try { element = document.createElement(""); result = element.name == "a" && element.type == "b"; } catch (exception) {} element = null; return result; })(), // Internal: Detect the style property name used to set the `float` // property: `cssFloat` in DOM Level 2-compliant browsers; `styleFloat` in // IE <= 8. cssFloat = "styleFloat" in document.createElement("div").style ? "styleFloat" : "cssFloat", // Internal: Elements used to convert HTML special characters to their // entity equivalents. textElement = document.createElement("pre"), textNode = textElement.appendChild(document.createTextNode("")), // Internal: Returns an attribute string comprising the given attribute // `name` and `value`. serializeAttribute = function serializeAttribute(name, value) { textNode.data = "" + value; return name + '="' + textElement.innerHTML.replace(/"/g, """) + '"'; }, // Expose the `buildNode` function. buildNode = function buildNode(tagName, properties, children) { var hasProperties, element, property, length, value; if (properties && getClass.call(properties) == "[object Array]") { children = properties; properties = null; } else { hasProperties = Object(properties) === properties; } // Set the read-only `name` and `type` properties in IE. if (hasProperties && supportsExtendedElementSyntax) { tagName = "<" + tagName; if (Spec.hasKey(properties, "name")) { tagName += " " + serializeAttribute("name", properties.name); delete properties.name; } if (Spec.hasKey(properties, "type")) { tagName += " " + serializeAttribute("type", properties.type); delete properties.type; } tagName += ">"; } element = document.createElement(tagName); // Set the corresponding element and style properties. if (hasProperties) { if (Spec.hasKey(properties, "style")) { Spec.forOwn(properties.style, function (property, value) { // Normalize the `float` style property. element.style[1, (/(?:style|css)Float/).test(property) ? cssFloat : property] = value; }); delete properties.style; } Spec.forOwn(properties, function (property, value) { element[property] = value; }); } // Append any child elements. if (Object(children) === children) { Spec.forEach(children, function (value) { element.appendChild(value); }); } return element; }; return buildNode; })(); // **clearElement** removes all child nodes from the given `element`. clearElement = function clearElement(element) { while (element.firstChild) { element.removeChild(element.firstChild); } return element; }; // **createReport** creates a new QUnit-style web logger, returning an event // handler that can be attached to a Spec suite. createReport = exports.createReport = function createReport(element) { function onEvent(event) { var type = event.type, target = event.target, messages, message; if (getClass.call(element) == "[object String]") { element = document.getElementById(element); } if (!element) { throw TypeError(substitute("Invalid logger element: `%o`.", element)); } switch (type) { // Clear the previous test results and initialize the logger elements. case "start": // Clear the previous test results. clearElement(element); // Re-initialize the logger elements. this.elements = { "header": element.appendChild(buildNode("h1", { "className": "suiteHeader" }, [document.createTextNode(this.name)])), // Representing the status of the suite (e.g., running, passed, failed). "status": element.appendChild(buildNode("div", { "className": "suiteStatus suiteRunning" })), // Contains the aggregate suite results. "results": element.appendChild(buildNode("ol", { "className": "testList" })), // Contains the aggregate suite summary. "stats": element.appendChild(buildNode("p", { "className": "suiteSummary" }, [document.createTextNode("Running...")])) }; break; // Create a new element to display the results of the current test. case "setup": // Attach the internal event handler to the element. this.elements.results.appendChild(buildNode("li", { "className": "testBlock testRunning" }, [ buildNode("strong", { "onclick": onClick, "className": "testName" }, [document.createTextNode(target.name)]) ])); break; // Update the status of the current test. case "teardown": this.elements.results.childNodes[this.position].className = target.failures ? "testBlock testFailed" : "testBlock testPassed"; break; // Update the suite status and cumulative summary. case "complete": // Set the spec status. this.elements.status.className = target.failures ? "suiteStatus suiteFailed" : "suiteStatus suitePassed"; // Create the aggregate spec summary. clearElement(this.elements.stats).appendChild(document.createTextNode(substitute("%d assertions, %d failures.", target.assertions, target.failures))); // Clean up. delete this.elements; break; case "assertion": case "failure": // Create the message list if it doesn't already exist. if (!(messages = this.elements.results.childNodes[this.position].childNodes[1])) { // Hide the messages by default. messages = buildNode("ol", { "className": "assertionList", "style": { "display": "none" } }); this.elements.results.childNodes[this.position].appendChild(messages); } // Create a new message. message = type == "assertion" ? // `assertion` is fired when an assertion succeeds. buildNode("li", { "className": "assertionPassed" }, [ document.createTextNode(event.message) ]) : // `failure` is fired when an assertion fails. buildNode("li", { "className": "assertionFailed" }, [ // Add the message to the list of messages. document.createTextNode(event.message), // Format and show the expected value. buildNode("span", { "className": "failureExpected" }, // Convert the expected value to JSON. [document.createTextNode("Expected: "), buildNode("code", { "className": "jsonValue" }, [ document.createTextNode(stringify(event.expected)) ])]), // Format and show the actual value. buildNode("span", { "className": "failureActual" }, // Convert the actual value to JSON. [document.createTextNode("Actual: "), buildNode("code", { "className": "jsonValue" }, [ document.createTextNode(stringify(event.actual)) ])]) ]); // Show the message. messages.appendChild(message); } } return onEvent; }; } // Expose the environment information. exports.Environment = Environment; return exports; }); luaparse-0.3.1/test/lib/spec.js000066400000000000000000000724031405615720100163530ustar00rootroot00000000000000/*! * Spec unit testing library * http://github.com/kitcambridge/spec * * Copyright 2011-2012, Kit Cambridge * http://kitcambridge.github.com * * Released under the MIT License. */ ;(function (root, Spec) { if (typeof define == "function" && define.amd) { // Export Spec for asynchronous module loaders. define("spec", ["exports"], Spec); } else { // Export for CommonJS environments, web browsers, and JavaScript engines. Spec = Spec(typeof exports == "object" && exports || (root.Spec = { // **noConflict** restores the original value of the `Spec` variable and // returns a reference to the Spec object. "noConflict": (function (original) { function noConflict() { root.Spec = original; // `noConflict` can't be invoked more than once. delete Spec.noConflict; return Spec; } return noConflict; })(root.Spec) })); } })(this, function (exports) { "use strict"; // The current version of Spec. Keep in sync with `package.json`. exports.version = "1.0.0rc4"; // Utility Methods // --------------- // `Object#toString` exposes the internal `[[Class]]` name of an object. var getClass = {}.toString, call = getClass.call, // **Spec.Environment** stores information about the current environment. Environment = exports.Environment = { // Indicates whether the `Object#hasOwnProperty` function is supported. "hasOwnProp": false, // Indicates whether the `[[Prototype]]` chain is exposed via the // `__proto__` property and can be mutated. "mutableProto": false, // Indicates whether the JScript `[[DontEnum]]` bug is present. "dontEnum": false, // Indicates whether the Safari 2 shadowed property enumeration bug is // present. "shadowEnum": false, // Indicates whether `undefined` elements in arrays are treated as elisions // (JScript 5.x spec, section 2.1.26). "undefinedElisions": !(0 in [void 0]), // Indicates whether Node's `process.nextTick` function is supported. "nextTick": typeof process == "object" && process != null && typeof process.nextTick == "function", // Indicates whether the `setTimeout` function is supported. "setTimeout": typeof setTimeout != "undefined", // Indicates whether Mozilla's LiveConnect APIs are supported. "java": typeof java != "undefined" && java != null && getClass.call(java) == "[object JavaPackage]" && typeof JavaAdapter == "function", // Indicates whether `JavaAdapter`s work with abstract base classes. "javaAdapter": false }, // **hasKey** determines if a property is a direct property of the // specified object. hasKey = exports.hasKey = (function () { var memo = {}, hasOwnProperty = memo.hasOwnProperty, hasKey; // The `__proto__` property can't be set more than once in Gecko. Environment.mutableProto = (memo.__proto__ = null, memo.__proto__ = { 1: 2 }, memo)[1] == 2; memo = null; if ((Environment.hasOwnProp = getClass.call(hasOwnProperty) == "[object Function]")) { // Wrap `Object#hasOwnProperty` in conforming implementations. hasKey = function hasKey(object, property) { if (object !== Object(object)) { throw TypeError("Invalid argument."); } return call.call(hasOwnProperty, object, property); }; } else if (Environment.mutableProto) { // Simulate `Object#hasOwnProperty` in Safari 2.0.3 and earlier. hasKey = function hasKey(object, property) { var original, result; if (object !== Object(object)) { throw TypeError("Invalid argument."); } // Capture and break the object's prototype chain. See the ES 5.1 spec, // section 8.6.2. original = object.__proto__; result = property in (object.__proto__ = null, object); // Restore the original prototype chain. object.__proto__ = original; return result; }; } else { // Use the `constructor` property to simulate `Object#hasOwnProperty` in // environments that don't expose the prototype chain. hasKey = function hasKey(object, property) { if (object !== Object(object)) { throw TypeError("Invalid argument."); } var parent = (object.constructor || Object).prototype; return property in object && !(property in parent && object[property] === parent[property]); }; } return hasKey; })(), // **forOwn** iterates over an `object`, executing a `callback` function once // per object member. If a `context` is specified, the `callback` is bound to // it. The iteration algorithm is normalized to account for cross-environment // inconsistencies. forOwn = exports.forOwn = (function () { var members, property, forOwn, size = 0; // Tests for bugs in the current environment's `for...in` algorithm. The // `valueOf` property inherits the non-enumerable flag from // `Object.prototype` in JScript <= 5.8 and Gecko <= 1.0. function Properties() { this.valueOf = 0; } Properties.prototype.valueOf = 0; // Iterate over a new instance of the `Properties` class. members = new Properties(); for (property in members) { // Ignore all other properties inherited from `Object.prototype`. if (hasKey(members, property)) { size += 1; } } members = null; // Normalize the iteration algorithm. if (!size) { // A list of non-enumerable properties inherited from `Object.prototype`. members = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"]; // IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable // properties. Environment.dontEnum = true; forOwn = function forOwn(object, callback, context) { var isFunction, property, length; if (object !== Object(object)) { throw TypeError("Invalid argument."); } isFunction = getClass.call(object) == "[object Function]"; for (property in object) { // Gecko <= 1.0 enumerates the `prototype` property of functions under // certain conditions; IE does not. if (!(isFunction && property == "prototype") && hasKey(object, property) && call.call(callback, context, property, object[property], object) === false) { return; } } // Manually invoke the callback for each non-enumerable property. for (length = members.length; length--;) { property = members[length]; if (hasKey(object, property) && call.call(callback, context, property, object[property], object) === false) { break; } } }; } else if (size == 2) { // Safari <= 2.0.4 enumerates shadowed properties twice. Environment.shadowEnum = true; forOwn = function forOwn(object, callback, context) { var members, isFunction, property; if (object !== Object(object)) { throw TypeError("Invalid argument."); } // Create a set of iterated properties. members = {}; isFunction = getClass.call(object) == "[object Function]"; for (property in object) { // Store each property name to prevent double enumeration. The // `prototype` property of functions is not enumerated due to cross- // environment inconsistencies. if (!(isFunction && property == "prototype") && !hasKey(members, property) && (members[property] = 1) && hasKey(object, property) && call.call(callback, context, property, object[property], object) === false) { break; } } }; } else { // No bugs detected; use the standard `for...in` algorithm. forOwn = function forOwn(object, callback, context) { var isFunction, property, isConstructor; if (object !== Object(object)) { throw TypeError("Invalid argument."); } isFunction = getClass.call(object) == "[object Function]"; for (property in object) { if (!(isFunction && property == "prototype") && hasKey(object, property) && !(isConstructor = property === "constructor") && call.call(callback, context, property, object[property], object) === false) { return; } } // Manually invoke the callback for the `constructor` property due to // cross-environment inconsistencies. if (isConstructor || hasKey(object, "constructor")) { call.call(callback, context, "constructor", object.constructor, object); } }; } return forOwn; })(), // **equals** recursively compares two objects. equals = exports.equals = (function () { // Comparison algorithm derived from work by Jeremy Ashkenas and Philippe // Rathe. function eq(left, right, stack) { var className, size, result; // Identical objects are equivalent. if (left === right) { // `0` and `-0` are identical, but they aren't equivalent. See the // ECMAScript Harmony `egal` proposal. return left != 0 || (1 / left == 1 / right); } // `null` and `undefined` are compared by identity. if (left == null) { return left === right; } className = getClass.call(left); if (className != getClass.call(right)) { return false; } switch (className) { // Strings, numbers, dates, and booleans are compared by value. // Primitives and their corresponding object wrappers are equivalent; // thus, `"5"` is equivalent to `new String("5")`. case "[object String]": return String(left) == String(right); case "[object Number]": left = +left; right = +right; // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is // performed for other numeric values. return left != left ? right != right : (left ? left == right : (1 / left == 1 / right)); // Coerce dates and booleans to numeric primitive values. Dates are // compared by their millisecond representations; invalid dates are not // equivalent. case "[object Date]": case "[object Boolean]": return +left == +right; // RegExps are compared by their source patterns, flags, and // last-matched index. case "[object RegExp]": return left.source == right.source && left.global == right.global && left.multiline == right.multiline && left.ignoreCase == right.ignoreCase && left.lastIndex == right.lastIndex; } if (typeof left != "object" || typeof right != "object") { return false; } // Assume equality for cyclic structures. The algorithm for detecting // cyclic structures is adapted from ES 5.1 section 15.12.3, abstract // operation `JO`. This is a linear search; performance is inversely // proportional to the number of unique nested objects. for (size = stack.length; size--;) { if (stack[size] == left) { return true; } } // Add the first object to the stack of traversed objects. stack.push(left); result = true; // Recursively compare objects and arrays. if (className == "[object Array]") { // Compare array lengths to determine if a deep comparison is necessary. size = left.length; result = size == right.length; if (result) { // Deep compare the contents, ignoring non-numeric properties. while (size--) { // Ensure commutative equality for sparse arrays. if (!(result = (size in left == size in right) && eq(left[size], right[size], stack))) { break; } } } } else { size = 0; // Deep compare objects. result = true; forOwn(left, function (key, value) { // Count the expected number of properties. size += 1; // Deep compare each own object member. return result = hasKey(right, key) && eq(value, right[key], stack); }); // Ensure that both objects contain the same number of properties. if (result) { forOwn(right, function () { if (!(size--)) { return false; } }); result = !size; } } // Remove the first object from the stack of traversed objects. stack.pop(); return result; } // Define the top-level `equals` function. function equals() { for (var index = 0, length = arguments.length; index < length - 1;) { // Apply the comparison function left-to-right until all the provided // arguments have been consumed. if (!eq(arguments[index], arguments[index += 1], [])) { return false; } } return true; } return equals; })(), // **forEach** iterates over a `list` of elements, yielding to a `callback` // function on each iteration. If the `callback` explicitly returns `false`, // the loop will terminate. forEach = exports.forEach = function forEach(list, callback, context) { var index, length; if (Object(list) !== list) { throw TypeError("Invalid argument."); } for (index = 0, length = list.length >>> 0; index < length; index += 1) { if (call.call(callback, context, list[index], index, list) === false) { break; } } return list; }, // **defer** attempts to execute a callback function asynchronously in supported // environments. defer = exports.defer = (function() { var defer, timer; // `process.nextTick` executes a function asynchronously in Node. if (Environment.nextTick) { defer = function defer(callback, context) { // `process.nextTick` is an efficient alternative to `setTimeout(..., 0)`. // As of Node 0.6.9, neither `process.nextTick` nor `setTimeout` isolate // execution; if the `callback` throws an exception, subsequent deferred // callbacks **will not execute**. This is an unfortunate incompatibility // with both the `setTimeout` function exposed in Browsers, // and the Java `Timer` API exposed via LiveConnect in Rhino. function run() { call.call(callback, context); } process.nextTick(run); }; // Browsers provide the `setTimeout` function. } else if (Environment.setTimeout) { defer = function defer(callback, context) { function run() { call.call(callback, context); } setTimeout(run, 0); }; // Mozilla Rhino's LiveConnect interface exposes the Java `Timer` API for // executing tasks in a background thread. } else if (Environment.java) { defer = function defer(callback, context) { timer = new java.util.Timer(); function run() { // Terminate the background thread once the task runs. If the thread // is not terminated, the Rhino process will persist even after // execution is completed. timer.cancel(); call.call(callback, context); } // Schedule the timer task for background execution. A new scheduler is // created for each task to ensure that exceptions do not leak between // tasks. timer.schedule(new JavaAdapter(java.util.TimerTask, { "run": run }), 0); }; // Rhino 1.74R has a bug that prevents `JavaAdapter` to work with abstract // base classes. try { defer(function() {}); Environment.javaAdapter = true; } catch(exception) { timer.cancel(); } } // Execute the callback function synchronously in other environments. if (!defer || !Environment.javaAdapter) { defer = function defer(callback, context) { call.call(callback, context); }; } return defer; }()); // Custom Events // ------------- // `Spec.Events` provides an interface for managing custom events. You can // add and remove individual event handlers; triggering an event executes its // handlers in succession. Based on work by Jeremy Ashkenas. exports.Events = Events; function Events() { this.events = {}; } // **addListener** attaches a `callback` function to an `event`. The callback // will be invoked whenever the event, specified by a string identifier, is // fired. If the `event` contains spaces, it is treated as a list of multiple // event types. If the optional `context` argument is provided, the `callback` // will be bound to it. Callbacks attached to the special `all` event will be // invoked for **all** triggered events. Events.prototype.on = Events.prototype.addListener = addListener; function addListener(event, callback, context) { if (event && callback) { forEach(event.split(" "), function (event) { var callbacks = hasKey(this.events, event) && this.events[event], target = callbacks ? callbacks.previous : {}, previous; target.next = previous = {}; // Store the event handler and context. target.callback = callback; target.context = context; // Create a new event target node. this.events[event] = { "previous": previous, "next": callbacks ? callbacks.next : target }; }, this); } return this; } // **removeListener** removes a previously-bound event handler. If the // `context` is omitted, all versions of the handler, including those bound to // different contexts, will be removed. If the `callback` is omitted, all // registered handlers for the given `event` will be removed. If both the // `callback` and `event` are omitted, **all** listeners for all events will // be removed. Events.prototype.removeListener = removeListener; function removeListener(event, callback, context) { if (!event) { // Remove all event listeners. this.events = {}; } else if (this.events) { forEach(event.split(" "), function (event) { var target = hasKey(this.events, event) && this.events[event], previous; if (target) { // Remove the event listener registry. delete this.events[event]; if (callback) { // Create a new registry without the given listener. previous = hasKey(target, "previous") && target.previous; for (; (target = hasKey(target, "next") && target.next) != previous;) { if (hasKey(target, "callback") && target.callback != callback || (context && (hasKey(target, "context") && target.context != context))) { this.on(event, target.callback, target.context); } } } } }, this); } return this; } // **emit** fires an event, specified by either a string identifier or an // event object with a `type` property. Multiple event types are not // supported for string identifiers. Events.prototype.emit = emit; function emit(event) { var target, type, previous, all, error; // Convert a string identifier into an event object. if (typeof event == "string" || getClass.call(event) == "[object String]") { event = { "type": event }; } type = hasKey(event, "type") && event.type; // Capture a reference to the current event target. if (!hasKey(event, "target")) { event.target = this; } // Capture a reference to the callback registry for the `all` event. all = type != "all" && hasKey(this.events, "all") && this.events.all; if ((target = hasKey(this.events, type) && this.events[type])) { previous = hasKey(target, "previous") && target.previous; for (; (target = hasKey(target, "next") && target.next) != previous;) { // Execute the callbacks in succession. try { call.call(target.callback, hasKey(target, "context") && target.context || this, event); } catch (exception) { error = exception; // Re-throw exceptions asynchronously, allowing all subsequent // callbacks to fire. defer(function () { throw error; }); } } } // Fire the `all` event. if (all) { previous = hasKey(all, "previous") && all.previous; for (; (all = hasKey(all, "next") && all.next) != previous;) { try { call.call(all.callback, hasKey(all, "context") && all.context || this, event); } catch (exception) { error = exception; defer(function () { throw error; }); } } } return this; }; // Suites // ------ // Suites are event-driven collections of unit tests. Using custom events, you // can create routines for setting up and tearing down tests, handling // assertions and failures, and logging test results. exports.Suite = Suite; // Creates a new suite with an optional `name`. function Suite(name) { Events.call(this); if (name != null) { this.name = name; } this.length = 0; } // The default suite name. Suite.prototype.name = "Anonymous Suite"; // Add support for custom events. Suite.prototype = new Events(); Suite.prototype.constructor = Suite; // Extend the `Suite` prototype with generic array methods. (function (prototype, methods) { for (var index = -1, method; method = methods[index += 1];) { prototype[method] = methods[method]; } })(Suite.prototype, ["join", "pop", "push", "reverse", "shift", "sort", "splice", "unshift"]); // Shuffles the suite using a Fisher-Yates shuffle. Suite.prototype.shuffle = shuffle; function shuffle() { for (var value, index, length = this.length >>> 0; length;) { index = Math.floor(Math.random() * length); value = this[--length]; this[length] = this[index]; this[index] = value; } return this; }; // Adds a test to the suite. The test name is optional. Suite.prototype.addTest = addTest; function addTest(name, test) { this.push(new Test(name, test)); return this; }; // Returns the index of the next available test relative to the given // `position`, or `null` if no additional tests are available. Suite.prototype.index = index; function index(position) { var length = this.length >>> 0, test; position || (position = 0); if (position < 0) { position = length + position; } for (; position < length; position += 1) { test = position in this && this[position]; if (test && typeof test.constructor == "function" && test instanceof Test) { return position; } } return null; }; // An event handler invoked each time a test in the suite emits an event. // This event handler updates the suite summary and prepares to run the next // test. Suite.prototype.onEvent = onSuiteEvent; function onSuiteEvent(event) { var target = event.target; // Proxy the fired event. this.emit(event); switch (event.type) { // Update the suite summary. case "assertion": this.assertions += 1; break; case "failure": this.failures += 1; break; case "teardown": // Unbind the internal event handler. target.removeListener("all", this.onEvent, this); if ((this.position = this.index(this.position += 1)) != null) { target = this[this.position]; // Run the next test. defer(target.on("all", this.onEvent, this).run, target); } else { // Finish running the suite. this.emit("complete"); } } } // Runs the suite. Suite.prototype.run = runSuite; function runSuite() { // Create the spec summary. var target; this.position = this.assertions = this.failures = 0; // Begin running the suite. this.emit("start"); // Bind the internal event handler to the first test. if ((this.position = this.index(this.position)) != null) { target = this[this.position]; // Run the first test. defer(target.on("all", this.onEvent, this).run, target); } else { // Finish running the suite. this.emit("complete"); } return this; }; // Tests // ----- // Wraps a test function with convenience methods and assertions. exports.Test = Test; function Test(name, test) { Events.call(this); if (name && test == null) { test = name; name = null; } if (name != null) { this.name = name; } this.test = test; // Bind the helper event handler. this.on("all", this.onEvent, this); } // Add support for custom events. Test.prototype = new Events(); Test.prototype.constructor = Test; // The default test name. Test.prototype.name = "Anonymous Test"; // An event handler invoked each time a test emits an event. Test.prototype.onEvent = onTestEvent; function onTestEvent(event) { var expected; switch (event.type) { case "setup": this.assertions = this.failures = 0; break; case "assertion": this.assertions += 1; break; case "failure": this.failures += 1; break; case "teardown": expected = event.expected; // Verify that the expected number of assertions were executed. if ((typeof expected == "number" || getClass.call(expected) == "[object Number]") && expected != this.assertions) { this.emit({ "type": "failure", "actual": this.assertions, "expected": expected, "message": "done" }); } } }; // **assert** creates a new assertion method with the given `name`. If the // provided `callback` function returns a falsy value, the assertion fails. Test.assert = assert; function assert(name, callback) { function assertion(actual, expected, message) { return this.ok(call.call(callback, this, actual, expected), { "actual": actual, "expected": expected, "message": message == null ? name : message }); } return assertion; }; // Runs the test. Test.prototype.run = runTest; function runTest() { this.emit("setup"); // Pass the wrapper as the first argument to the test function. this.test(this); return this; }; // **ok** tests whether an `expression` is truthy. The optional `message` // defaults to the name of the current assertion (e.g., `ok`). Test.prototype.ok = ok; function ok(expression, event) { if (Object(event) !== event) { event = { "actual": expression, "expected": true, "message": event == null ? "ok" : event }; } // Note: To test for the boolean `true`, use the `strictEqual` assertion. event.type = expression ? "assertion" : "failure"; return this.emit(event); }; // **notOk** tests whether an `expression` is falsy. Test.prototype.notOk = notOk; function notOk(expression, message) { return this.ok(!expression, message == null ? "notOk" : message); }; // **equal** tests whether `actual` is **equal** to `expected`, as determined // by the `==` operator. Test.prototype.equal = assert("equal", assertEqual); function assertEqual(actual, expected) { return actual == expected; } // **notEqual** tests for **loose** or coercive inequality. Test.prototype.notEqual = assert("notEqual", assertNotEqual); function assertNotEqual(actual, expected) { return actual != expected; } // **strictEqual** tests for **strict** equality (`actual === expected`). Test.prototype.strictEqual = assert("strictEqual", assertStrictEqual); function assertStrictEqual(actual, expected) { return actual === expected; } // **notStrictEqual** tests for strict inequality. Test.prototype.notStrictEqual = assert("notStrictEqual", assertStrictNotEqual); function assertStrictNotEqual(actual, expected) { return actual !== expected; } // **deepEqual** tests for deep equality and equivalence, as determined by the // `Spec.equals` function. Test.prototype.deepEqual = assert("deepEqual", equals); // **notDeepEqual** tests for deep inequality. Test.prototype.notDeepEqual = assert("notDeepEqual", assertNotDeepEqual); function assertNotDeepEqual(actual, expected) { return !equals(actual, expected); } // Ensures that the `callback` function throws an exception. Test.prototype.error = assertError; function assertError(callback, expected, message) { var ok = false, isFunction = typeof expected == "function"; // Invalid expected value; the message was passed as the second argument. if (!isFunction && message == null) { message = expected; expected = null; } try { callback(); } catch (exception) { ok = expected == null || (isFunction && call.call(expected, this, exception, this)); } return this.ok(ok, message == null ? "error" : message); }; // Ensures that the `callback` function does not throw any exceptions. Test.prototype.noError = assertNoError; function assertNoError(callback, message) { var ok = true; try { callback(); } catch (exception) { ok = false; } return this.ok(ok, message == null ? "noError" : message); }; // **done** completes a test with an optional number of expected `assertions`. // This method **must** be called at the end of each test. Test.prototype.done = done; function done(assertions) { return this.emit({ "type": "teardown", "expected": assertions }); }; return exports; }); luaparse-0.3.1/test/lib/spec_adapter.js000066400000000000000000000024041405615720100200450ustar00rootroot00000000000000(function(root) { function specAdapter(socket) { var testResults = [], id = 0; root.luaparse.testSuite.on('all', function(event) { var test; switch (event.type) { case 'assertion': case 'failure': var isSuccess = (event.type === 'assertion'); test = { passed: isSuccess ? 1 : 0 , failed: isSuccess ? 0 : 1 , total: 1 , id: id++ , name: event.message , items: [] }; if (!isSuccess) { test.items.push({ passed: false , message: 'Expected ' + root.Newton.stringify(event.expected) + ' to match ' + root.Newton.stringify(event.actual) }); } testResults.push(test); root.Testem.emit('test-result', test); break; case 'complete': root.Testem.emit('all-test-results', { failed: this.failures , total: this.assertions , tests: [] }); break; case 'start': root.Testem.emit('tests-start'); break; case 'teardown': break; case 'setup': break; } }); } root.specAdapter = specAdapter; }(this)); luaparse-0.3.1/test/runner.js000066400000000000000000000564271405615720100161740ustar00rootroot00000000000000/*global require, define, exports, load, console, print, module, emit, process, __loadScript */ (function (root) { var isLoader = typeof define === 'function' && !!define.amd , isModule = typeof require === 'function' && typeof exports === 'object' && exports && !isLoader , isBrowser = 'window' in root && root.window === root && typeof root.navigator !== 'undefined' , isEngine = !isBrowser && !isModule && typeof root.load === 'function' , isTestem = isBrowser && root.location.hash === '#testem' // Use the console reporter , isConsole = typeof process === 'object' && process.argv && process.argv.indexOf('--console') >= 0; function makeLoader(readTextFile) { function loadModule(id, filename) { /*jshint evil:true */ var filedir = filename.replace(/[^/]+$/, '') || '.'; var loader = new Function( "require", "exports", "module", readTextFile(filename) ); var module = { id: id, exports: {} }; loader( function (what) { return loadModule(what, filedir + '/' + what + '.js'); }, module.exports, module ); return module.exports; } return loadModule; } var load = function load(mod, path) { if (root[mod]) return root[mod]; if (isModule) return require(path); var filename = path.replace(/\.js$/, '') + '.js'; if (isEngine) { root.load(filename); return root[mod]; } // Duktape if (typeof Duktape !== 'undefined' && typeof readFile === 'function') { return root[mod] = makeLoader(function (filename) { /*global readFile, TextDecoder */ return (new TextDecoder('utf-8')).decode(readFile(filename)); })(mod, filename); } // QuickJS if (typeof __loadScript !== 'undefined') { __loadScript(filename); return root[mod]; } }; var Spec = load('Spec', './lib/spec') , Newton = load('Newton', './lib/newton') , luaparse = load('luaparse', '../luaparse') , specs = root.specs = [ './spec/assignments' , './spec/break' , './spec/comments' , './spec/conditional' , './spec/do' , './spec/escapesequences' , './spec/expressions' , './spec/for' , './spec/functioncalls' , './spec/functions' , './spec/labels' , './spec/literals' , './spec/local' , './spec/misc' , './spec/operators' , './spec/repeat' , './spec/return' , './spec/scope' , './spec/statements' , './spec/tableconstructors' , './spec/while' ] // Print function used for Spec reporters. , output = (function() { if (typeof console !== 'undefined' && console.log) return function(value) { console.log(value); }; // In browsers, the global `print` function prints the current page. else if (typeof print === 'function' && !isBrowser) return print; else return function(value) { }; }()) // Create the test suite. , suite = new Spec.Suite('Luaparse Unit Tests'); if (!('assign' in Object)) { Object.assign = function () { var args = arguments; var target = args[0]; for (var i = 1; i < args.length; ++i) { var source = args[i]; for (var k in source) { if (!Object.prototype.hasOwnProperty.call(source, k)) continue; target[k] = source[k]; } } return target; }; } function escapeString(string) { return string.replace(/\n/g, '\\n') .replace(/\r/g, '\\r') .replace(/\t/g, '\\t') .replace(/\f/g, '\\f') .replace(/\v/g, '\\v'); } // Expect a parse error to occur Spec.Test.prototype.parseError = function (source, expected, options) { var ok = false, actual; try { actual = luaparse.parse(source, options); } catch (exception) { if (!(exception instanceof luaparse.SyntaxError)) throw exception; actual = exception.message; ok = actual === expected; } return this.ok(ok, { 'expected': expected, 'actual': actual, 'message': escapeString(source) }); }; // Expect the parsed AST to match. Spec.Test.prototype.parses = function (source, expected, options, variant) { return this.deepEqual(luaparse.parse(source, options), expected, escapeString(source) + (variant ? (' ' + variant) : '')); }; Spec.Test.prototype.equalPrecedence = function (source, expected, options) { function normalise(node) { if (!node || typeof node !== 'object') return node; node.inParens = null; for (var key in node) if (node.hasOwnProperty(key)) { normalise(node[key]); } return node; } return this.deepEqual( normalise(luaparse.parse('a = ' + source, options)), normalise(luaparse.parse('a = ' + expected, options)), source + ' is equal to ' + expected ); }; // Create a test, and delegate to appropiate test function. function addTest(testName, tests) { // Make a semi-deep copy of the tree, modified by the visitor function. function rebuildTree(node, visit) { if (!node) return; node = Object.assign({}, node); visit(node); function visitKey(key) { if (!node[key]) return; if (Array.isArray(node[key])) { node[key] = node[key].map(function (item) { return rebuildTree(item, visit); }); } else node[key] = rebuildTree(node[key], visit); } switch (node.type) { case 'LocalStatement': case 'AssignmentStatement': visitKey('variables'); visitKey('init'); break; case 'UnaryExpression': visitKey('argument'); break; case 'BinaryExpression': case 'LogicalExpression': visitKey('left'); visitKey('right'); break; case 'FunctionDeclaration': visitKey('identifier'); visitKey('parameters'); visitKey('body'); break; case 'ForGenericStatement': visitKey('variables'); visitKey('iterators'); visitKey('body'); break; case 'IfClause': case 'ElseifClause': case 'WhileStatement': case 'RepeatStatement': visitKey('condition'); /* fall through */ case 'Chunk': case 'ElseClause': case 'DoStatement': visitKey('body'); visitKey('globals'); visitKey('comments'); break; case 'ForNumericStatement': visitKey('variable'); visitKey('start'); visitKey('end'); visitKey('step'); visitKey('body'); break; case 'ReturnStatement': visitKey('arguments'); break; case 'IfStatement': visitKey('clauses'); break; case 'MemberExpression': visitKey('base'); visitKey('identifier'); break; case 'IndexExpression': visitKey('base'); visitKey('index'); break; case 'LabelStatement': visitKey('label'); break; case 'CallStatement': visitKey('expression'); break; case 'GotoStatement': visitKey('label'); break; case 'TableConstructorExpression': visitKey('fields'); break; case 'TableKey': case 'TableKeyString': visitKey('key'); /* fall through */ case 'TableValue': visitKey('value'); break; case 'CallExpression': visitKey('base'); visitKey('arguments'); break; case 'TableCallExpression': visitKey('base'); visitKey('arguments'); break; case 'StringCallExpression': visitKey('base'); visitKey('argument'); break; case 'Identifier': case 'NumericLiteral': case 'BooleanLiteral': case 'StringLiteral': case 'NilLiteral': case 'VarargLiteral': case 'BreakStatement': case 'Comment': break; default: throw new Error('Unhandled ' + node.type); } return node; } suite.addTest(testName, function() { var count = 0; for (var i = 0; i < tests.length; ++i) { var expected = tests[i].result; var opts = Object.assign({}, tests[i].options, { comments: true, locations: true, ranges: true, scope: true }); if (typeof expected === 'string') { this.parseError(tests[i].source, expected, opts); count++; } else { count += 5; this.parses(tests[i].source, expected, opts); opts.locations = false; expected = rebuildTree(expected, function (node) { delete node.loc; }); this.parses(tests[i].source, expected, opts, '(no locations)'); opts.ranges = false; expected = rebuildTree(expected, function (node) { delete node.range; }); this.parses(tests[i].source, expected, opts, '(no locations, ranges)'); opts.comments = false; expected = Object.assign({}, expected); delete expected.comments; this.parses(tests[i].source, expected, opts, '(no locations, ranges, comments)'); opts.scope = false; expected = rebuildTree(expected, function (node) { if (node.type !== 'FunctionDeclaration') delete node.isLocal; }); delete expected.globals; this.parses(tests[i].source, expected, opts, '(no locations, ranges, comments, scopes)'); } } this.done(count); }); } // Reporters ---------------------------------------------------------------- // Beautify console output Mocha-style. var consoleReporter = (function() { var failures = [] , colors = { 'red': 31 , 'green': 32 , 'gray': 90 , 'white': 0 } , line = '-------------------------------------------------' , colorize = function colorize(color, string) { return '\u001b[' + colors[color] + 'm' + string + '\u001b[0m'; }; return function consoleReporter(event) { switch (event.type) { case 'assertion': output(' ' + colorize('green', '✓ ') + colorize('gray', event.message)); break; case 'failure': output(' ' + colorize('red', '✖ ' + event.message)); failures.push(event); break; case 'start': output(this.name); break; case 'setup': output('\n ' + colorize('white', event.target.name)); break; case 'complete': var assertionCount = event.target.assertions , failureCount = event.target.failures , totalCount = assertionCount + failureCount; for (var i = 0, l = failures.length; i < l; i++) { var failure = failures[i] , expected = Newton.stringify(failure.expected) , actual = Newton.stringify(failure.actual); output(Newton.substitute('\n%s\n Expected: %s\n Actual: %s', colorize('red', failure.message + ' ' + line), colorize('gray', expected), colorize('gray', actual))); } output('\n' + assertionCount + '/' + totalCount + ' assertions'); break; } }; }()); var testemReporter = (function() { var id = 0 , testResults = []; return function(event) { var test, isSuccess; switch (event.type) { case 'assertion': case 'failure': isSuccess = (event.type === 'assertion'); test = { passed: isSuccess ? 1 : 0 , failed: isSuccess ? 0 : 1 , total: 1 , id: id++ , name: event.message , items: [] }; if (!isSuccess) { test.items.push({ passed: false , message: Newton.substitute('Expected %o to match %o', event.expected, event.actual) }); } testResults.push(test); root.Testem.emit('test-result', test); break; case 'complete': root.Testem.emit('all-test-results', { failed: this.failures , total: this.assertions , tests: [] }); break; case 'start': root.Testem.emit('tests-start'); break; } }; }()); // Use the appropiate reporter depending on enviroment. var reporter = isBrowser ? Newton.createReport('suite') : isConsole ? consoleReporter : Newton.createTAP(output); if (isTestem) suite.on('all', testemReporter); suite.on('all', reporter); // Additional tests --------------------------------------------------------- suite.addTest('API', function() { this.equal(typeof luaparse, 'object', 'luaparse is an object'); this.equal(typeof luaparse.parse, 'function', 'luaparse.parse() is a function'); this.equal(typeof luaparse.write, 'function', 'luaparse.write() is a function'); this.equal(typeof luaparse.end, 'function', 'luaparse.end() is a function'); var parse = luaparse.parse({ wait: true }); this.deepEqual(parse.end('return'), { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [] } ], "comments": [] }, 'should support waiting on input'); var nodes = [] , createdScopes = 0 , destroyedScopes = 0 , localDeclarations = []; parse = luaparse.parse('do local a = 1 b = 1 end -- comment', { scope: true , locations: true , ranges: true , onCreateNode: function(node) { nodes.push(node); } , onCreateScope: function() { createdScopes++; } , onDestroyScope: function() { destroyedScopes++; } , onLocalDeclaration: function(ident) { localDeclarations.push(ident); } }); this.equal(createdScopes, 2, 'should invoke onCreateScope callback'); this.equal(createdScopes, destroyedScopes, 'should invoke onDestroyScope callback'); this.deepEqual(localDeclarations, ['a'], 'should invoke onLocalDeclaration callback'); this.equal(nodes.length, 9, 'should invoke onCreateNode callback'); this.deepEqual( nodes[0] , {"type": "Identifier", "name": "a", "loc": {"start": {"line": 1, "column": 9}, "end": {"line": 1, "column": 10}}, "range": [9, 10], "isLocal": true} , 'should invoke onCreateNode callback with syntax node parameter' ); this.deepEqual(luaparse.parse('#!/usr/bin/lua\nreturn', { locations: true, ranges: true }), { "type": "Chunk", "body": [{"type": "ReturnStatement", "arguments": [], "loc": {"start": {"line": 2, "column": 0}, "end": {"line": 2, "column": 6}}, "range": [15, 21]}], "loc": {"start": {"line": 2, "column": 0}, "end": {"line": 2, "column": 6}}, "range": [15, 21], "comments": [] }, 'should ignore shebangs'); this.done(11); }); suite.addTest('Option validation', function() { var optionErrors = [ { options: { luaVersion: '4.0' } , message: "Lua version '4.0' not supported" }, { options: { encodingMode: 'ebcdic' } , message: "Encoding mode 'ebcdic' not supported" }, { options: { luaVersion: 'hasOwnProperty' } , message: "Lua version 'hasOwnProperty' not supported" }, ]; /*jshint loopfunc:true */ for (var i = 0; i < optionErrors.length; ++i) { this.error(function () { return luaparse.parse('', optionErrors[i].options); }, optionErrors[i].message); } this.done(optionErrors.length); }); suite.addTest('Interpretation of literals', function () { var testcases = [ [ '019' , '19' , '0x13' ] , [ '"a"' , '"\\97"' , '"\\097"' , '"\\x61"' , '"\\u{61}"' , '"\\u{061}"' ] , [ '"\\u{1f4a9}"' , '"\\u{000001f4a9}"' , '"\\xf0\\x9f\\x92\\xa9"' , '"\ud83d\udca9"' , "'\ud83d\udca9'" , '[[\ud83d\udca9]]' ] , [ '"\\\\a"' , '[==[\\a]==]' ] , [ '"\\nfoo"' , '"\\\nfoo"' , '"\\\rfoo"' , '"\\\r\nfoo"' , '"\\\n\rfoo"' , '[[\n\nfoo]]' ] ]; var count = 0; function symbolicControlChars(s) { /* control characters should not appears in test output; * use characters from the 'Control Pictures' block instead */ return s.replace(/[\x00-\x1f]/g, function (m) { return String.fromCharCode(0x2400 + m.charCodeAt(0)); }); } for (var i = 0; i < testcases.length; ++i) { count += testcases[i].length - 1; var list = testcases[i]; var left = luaparse.parse('return ' + list[0], { "luaVersion": "5.3" }).body[0].arguments[0]; for (var j = 1; j < list.length; ++j) { var right = luaparse.parse('return ' + list[j], { "luaVersion": "5.3" }).body[0].arguments[0]; this.equal(left.value, right.value, symbolicControlChars(left.raw) + ' == ' + symbolicControlChars(right.raw)); left = right; } } this.done(count); }); suite.addTest('Precedence', function() { this.equalPrecedence('2^3^2', '2^(3^2)'); this.equalPrecedence('2^3*4', '(2^3)*4'); this.equalPrecedence('2^2^3', '2^(2^3)'); this.equalPrecedence('2^2^3^4', '2^(2^(3^4))'); this.equalPrecedence('2^2^3^4+1', '2^(2^(3^4))+1'); this.equalPrecedence('1*2/3', '(1*2)/3'); this.equalPrecedence('1 + 1 * 2 > 3', '( 1 + ( 1 * 2 ) ) > 3'); this.equalPrecedence('1 < 2 and 2 < 1', '(1 < 2) and (2 < 1)'); this.equalPrecedence('1 / 2 + 4 * 2 > 8', '((1 / 2) + (4 * 2)) > 8'); this.equalPrecedence('2 < 1 == true', '(2 < 1) == true'); this.equalPrecedence('2 < 1 + 1 == true', '(2 < (1 + 1)) == true'); this.equalPrecedence('not 1 + 1', '(not 1) + 1'); this.equalPrecedence('not not 1 + 1', '(not (not (1)) + 1)'); this.equalPrecedence('1 + #1', '1 + (#1)'); this.equalPrecedence('-x^2', '-(x^2)'); this.equalPrecedence('3~2&1', '3~(2&1)', { "luaVersion": "5.3" }); this.equalPrecedence('3~2|1', '(3~2)|1', { "luaVersion": "5.3" }); this.equalPrecedence('1<<2 ..3', '1<<(2 ..3)', { "luaVersion": "5.3" }); this.done(18); }); suite.addTest('EOL sequences', function() { var options = { locations: true } , baseline = luaparse.parse('foo = 1\nbar = 1', options); this.deepEqual(baseline, luaparse.parse('foo = 1\rbar = 1', options), 'carriage return'); this.deepEqual(baseline, luaparse.parse('foo = 1\n\rbar = 1', options), 'newline followed by carriage return'); this.deepEqual(baseline, luaparse.parse('foo = 1\r\nbar = 1', options), 'carriage return followed by newline'); this.done(3); }); suite.addTest('Encoding modes', function () { var cases = [ { mode: 'x-user-defined', src: '"\\u{0}"', value: '\u0000' }, { mode: 'x-user-defined', src: '"\\u{80}"', value: '\uf7c2\uf780' }, { mode: 'x-user-defined', src: '"\\u{d800}"', value: '\uf7ed\uf7a0\uf780' }, { mode: 'x-user-defined', src: '"\\u{20000}"', value: '\uf7f0\uf7a0\uf780\uf780' }, { mode: 'x-user-defined', src: '"\\x80"', value: '\uf780' }, { mode: 'x-user-defined', src: '"\\x61"', value: 'a' }, { mode: 'x-user-defined', src: '"\\128"', value: '\uf780' }, { mode: 'x-user-defined', src: '"\uf780"', value: '\uf780' }, { mode: 'x-user-defined', src: '"\ud800"', error: true }, { mode: 'x-user-defined', src: '"\u0080"', error: true }, { mode: 'x-user-defined', src: '[[\uf780]]', value: '\uf780' }, { mode: 'x-user-defined', src: '[[\ud800]]', error: true }, { mode: 'x-user-defined', src: '[[\u0080]]', error: true }, { mode: 'x-user-defined', src: '"a"', value: 'a' }, { mode: 'x-user-defined', src: '\uf780', name: '\uf780' }, { mode: 'x-user-defined', src: '\x80', error: true }, { mode: 'x-user-defined', src: 'a', name: 'a' }, { mode: 'pseudo-latin1', src: '"\\u{0}"', value: '\u0000' }, { mode: 'pseudo-latin1', src: '"\\u{80}"', value: '\u00c2\u0080' }, { mode: 'pseudo-latin1', src: '"\\u{d800}"', value: '\u00ed\u00a0\u0080' }, { mode: 'pseudo-latin1', src: '"\\u{20000}"', value: '\u00f0\u00a0\u0080\u0080' }, { mode: 'pseudo-latin1', src: '"\\x80"', value: '\u0080' }, { mode: 'pseudo-latin1', src: '"\\x61"', value: 'a' }, { mode: 'pseudo-latin1', src: '"\\128"', value: '\u0080' }, { mode: 'pseudo-latin1', src: '"\uf780"', error: true }, { mode: 'pseudo-latin1', src: '"\ud800"', error: true }, { mode: 'pseudo-latin1', src: '"\u0080"', value: '\u0080' }, { mode: 'pseudo-latin1', src: '[[\uf780]]', error: true }, { mode: 'pseudo-latin1', src: '[[\ud800]]', error: true }, { mode: 'pseudo-latin1', src: '[[\u0080]]', value: '\u0080' }, { mode: 'pseudo-latin1', src: '"a"', value: 'a' }, { mode: 'pseudo-latin1', src: '\uf780', error: true }, { mode: 'pseudo-latin1', src: '\x80', name: '\x80' }, { mode: 'pseudo-latin1', src: 'a', name: 'a' }, { mode: 'none', src: '"\\u{80}"', value: null }, { mode: 'none', src: '"\\u{d800}"', value: null }, { mode: 'none', src: '"\\x80"', value: null }, { mode: 'none', src: '"\\x61"', value: null }, { mode: 'none', src: '"\\128"', value: null }, { mode: 'none', src: '"\uf780"', value: null }, { mode: 'none', src: '"\ud800"', value: null }, { mode: 'none', src: '"\u0080"', value: null }, { mode: 'none', src: '"a"', value: null }, { mode: 'none', src: '[[a]]', value: null }, { mode: 'none', src: '\uf780', name: '\uf780' }, { mode: 'none', src: '\x80', name: '\x80' }, { mode: 'none', src: 'a', name: 'a' }, ]; for (var i = 0; i < cases.length; ++i) { var label = cases[i].src + ' (' + cases[i].mode + ')'; var opts = { luaVersion: "5.3", encodingMode: cases[i].mode, extendedIdentifiers: true }; if (cases[i].error) { var ok = false; try { luaparse.parse("return " + cases[i].src, opts); } catch (e) { if (!(e instanceof luaparse.SyntaxError)) throw e; ok = true; } this.ok(ok, { 'message': label }); continue; } var node = luaparse.parse("return " + cases[i].src, opts).body[0].arguments[0]; if (cases[i].name) this.deepEqual(node.name, cases[i].name, label); else this.deepEqual(node.value, cases[i].value, label); } this.done(cases.length); }); if (isLoader) { define(specs, function () { Spec.forEach(arguments, function(test) { addTest(test.name, test.spec); }); suite.shuffle(); return suite; }); } else if (isBrowser || (!isModule || (typeof module === 'object' && module === require.main))) { var run = root.run = function() { // Add all tests. In a browser the tests are expected to be loaded // therefore this function is exposed as a wrapper around the test suites // `run()` so that it can run on load. Spec.forEach(specs, function(spec) { var name = spec.replace(/^[\s\S]*\/([^\/]+)$/, '$1') , tests = load(name, spec); addTest(tests.name, tests.spec); }); suite.shuffle(); suite.run(); }; if (!isBrowser) run(); } }(this)); luaparse-0.3.1/test/scaffolding/000077500000000000000000000000001405615720100165665ustar00rootroot00000000000000luaparse-0.3.1/test/scaffolding/assignments000066400000000000000000000020451405615720100210450ustar00rootroot00000000000000a -- FAIL a, -- FAIL a,b,c -- FAIL a,b = -- FAIL a = 1 a = 1,2,3 a,b,c = 1 a,b,c = 1,2,3 a.b = 1 a.b.c = 1 a[b] = 1 a[b][c] = 1 a.b[c] = 1 a[b].c = 1 a[b], a[c] = 1 a().b = 1 ({})[b] = 1 a""[b] = 1 a{}[b] = 1 ({{}})[a][b] = 1 (a).b = 1 (1).a = 0 0 = 0 -- FAIL "foo" = 0 -- FAIL true = 0 -- FAIL (a) = 0 -- FAIL {} = 0 -- FAIL a, b() c() -- FAIL a, b(), c -- FAIL a:b() = 0 -- FAIL a() = 0 -- FAIL a.b:c() = 0 -- FAIL a[b]() = 0 -- FAIL a = a b -- FAIL a = 1 2 -- FAIL a = a = 1 -- FAIL luaparse-0.3.1/test/scaffolding/break000066400000000000000000000026021405615720100175750ustar00rootroot00000000000000break -- FAIL do break end -- FAIL if 0 then break end -- FAIL if 0 then else break end -- FAIL while 0 do function x() break end end -- FAIL repeat function x() break end until 0 -- FAIL repeat x = function() break end until 0 -- FAIL repeat break until 0 repeat do break end until 0 repeat if 0 then break end until 0 repeat if 0 then else break end until 0 while 0 do break end while 0 do do break end end while 0 do if 0 then break end end while 0 do if 0 then else break end end for i = 1, 2 do break end for i = 1, 2 do do break end end for i = 1, 2 do if 0 then break end end for i = 1, 2 do if 0 then else break end end for a in b do break end for a in b do do break end end for a in b do if 0 then break end end for a in b do if 0 then else break end end function x() break end -- FAIL local function x() break end -- FAIL function x() repeat break until 0 end // { "luaVersion": "5.2" } break -- FAIL do break end -- FAIL if 0 then break end -- FAIL if 0 then else break end -- FAIL while 0 do function x() break end end -- FAIL repeat function x() break end until 0 -- FAIL repeat x = function() break end until 0 -- FAIL repeat break until 0 repeat do break end until 0 luaparse-0.3.1/test/scaffolding/comments000066400000000000000000000005401405615720100203350ustar00rootroot00000000000000-- comment -- comment@n@-- comment --coment -- comment@n@return return --comment @n@ --[[comment]] if true--[[comment]]then end --[=[comment]=] return --[===[comment@n@--[=[sub]=]--@n@]===]return --[[comment@n@line two]] --[[@n@comment@n@line two@n@]] --[==@n@return --]] if true -- comment@n@then end --[=[x]x -- FAIL luaparse-0.3.1/test/scaffolding/conditional000066400000000000000000000022501405615720100210130ustar00rootroot00000000000000if -- FAIL elseif -- FAIL else -- FAIL then -- FAIL if then -- FAIL if 1 -- FAIL if 1 then -- FAIL if 1 else -- FAIL if 1 then else -- FAIL if 1 then elseif -- FAIL if 1 then end if 1 then local a end if 1 then local a local b end if 1 then local a; local b; end if 1 then else end if 1 then local a else local b end if 1 then local a; else local b; end if 1 then elseif 2 -- FAIL if 1 then elseif 2 then -- FAIL if 1 then elseif 2 then end if 1 then local a elseif 2 then local b end if 1 then local a; elseif 2 then local b; end if 1 then elseif 2 then else end if 1 then else if 2 then end end if 1 then else if 2 then end -- FAIL if 1 then return end if 1 then return return end -- FAIL if 1 then end; if 1 then end; if then end -- FAIL if 1 then elseif then end -- FAIL luaparse-0.3.1/test/scaffolding/do000066400000000000000000000011631405615720100171140ustar00rootroot00000000000000do -- FAIL end -- FAIL do end do ; end -- FAIL do 1 end -- FAIL do "foo" end -- FAIL do local a, b end do local a local b end do local a; local b; end do local a = 1 end do do end end do do end; end do do do end end end do do do end; end; end do do do return end end end do end do -- FAIL do end end -- FAIL do return end do return return end -- FAIL // { "luaVersion": "5.2" } do ; end luaparse-0.3.1/test/scaffolding/escapesequences000066400000000000000000000020151405615720100216630ustar00rootroot00000000000000a = "bar@n@baz" -- FAIL a = "bar@r@baz" -- FAIL a = "bar\n\r\t@t@baz" a = "bar\80baz\a\80\0foo" a = "bar\f\v\bbaz" a = "bar@f@@v@@b@az" a = '\\' a = '\'' a = '\[' a = '\123' a = '\255' a = '\256' -- FAIL a = '\300' -- FAIL a = [[bar\f\v\bbaz]] a = [[\]] a = '\z \x' // { "luaVersion": "5.2" } a = '\[' -- FAIL a = '\x23' a = '\x0' -- FAIL a = '\x0x' -- FAIL a = '\xx' -- FAIL a = "bar\z baz" // { "luaVersion": "5.3" } a = '\u{0}' a = '\u{1f4a9}' a = '\u{7f}\u{80}' a = '\u{7ff}\u{800}' a = '\u{ffff}\u{1f4a9}' a = '\u{10ffff}' a = '\u{110000}' -- FAIL a = '\u{120000}' -- FAIL a = '\u{000000001f4a9}' a = '\u{100000001f4a9}' -- FAIL a = '\u{1f4a9' -- FAIL a = "\u{1f4a9" -- FAIL a = '\uaa' -- FAIL a = '\u{}' -- FAIL a = '\u{0g}' -- FAIL luaparse-0.3.1/test/scaffolding/expressions000066400000000000000000000021201405615720100210660ustar00rootroot00000000000000a = -- FAIL a = [[foo]] a = {} a = (a) a = (nil) a = (true) a = (1) a = ("foo") a = ([[foo]]) a = ({}) a = a.b a = a.b. -- FAIL a = a.b.c a = a:b -- FAIL a = a[] -- FAIL a = a[b] a = a[1] a = a["foo"] a = () -- FAIL a = function -- FAIL a = function 1 -- FAIL a = function a -- FAIL a = function end -- FAIL a = function( -- FAIL a = function() end a = function(1 -- FAIL a = function(p) end a = function(p,q) end a = function(p q) end -- FAIL a = function(p,) -- FAIL a = function(p q -- FAIL a = function(p,q,r) end a = function(p,q,1 -- FAIL a = function(...) end a = function(..., -- FAIL a = function(p,...) end a = function(p,q,r,...) end a = {'-'} a = {'not'} a = {not true} luaparse-0.3.1/test/scaffolding/for000066400000000000000000000042601405615720100173010ustar00rootroot00000000000000for -- FAIL for do -- FAIL for end -- FAIL for 1 -- FAIL for a -- FAIL for true -- FAIL for a, in -- FAIL for a in -- FAIL for a do -- FAIL for a in do -- FAIL for a in b do -- FAIL for a in b end -- FAIL for a in b, do -- FAIL for a in b do end for a in b do local a local b end for a in b do local a; local b; end for a in b do 1 end -- FAIL for a in b do "foo" end -- FAIL for a b in -- FAIL for a, b, c in p do end for a, b, c in p, q, r do end for a in 1 do end for a in true do end for a in "foo" do end for a in b do break end for a in b do break break end -- FAIL for a in b do return end for a in b do return return end -- FAIL for a in b do do end end for a in b do do break end end for a in b do do return end end for = -- FAIL for a = -- FAIL for a, b = -- FAIL for a = do -- FAIL for a = 1, do -- FAIL for a = p, q, do -- FAIL for a = p q do -- FAIL for a = b do end -- FAIL for a = 1, 2, 3, 4 do end -- FAIL for a = p, q do end for a = 1, 2 do end for a = 1, 2 do local a local b end for a = 1, 2 do local a; local b; end for a = 1, 2 do 3 end -- FAIL for a = 1, 2 do "foo" end -- FAIL for a = p, q, r do end for a = 1, 2, 3 do end for a = p, q do break end for a = p, q do break break end -- FAIL for a = 1, 2 do return end for a = 1, 2 do return return end -- FAIL for a = p, q do do end end for a = p, q do do break end end for a = p, q do do return end end // { "luaVersion": "5.2" } for a in b do break break end for a = p, q do break break end luaparse-0.3.1/test/scaffolding/functioncalls000066400000000000000000000031741405615720100213620ustar00rootroot00000000000000a( -- FAIL a() a(1) a(1,) -- FAIL a(1,2,3) 1() -- FAIL a()() a.b() a[b]() a.1 -- FAIL a.b -- FAIL a[b] -- FAIL a.b.( -- FAIL a.b.c() a[b][c]() a[b].c() a.b[c]() a:b() a:b -- FAIL a:1 -- FAIL a.b:c() a[b]:c() a:b: -- FAIL a:b():c() (a)() ()() -- FAIL ("foo")() (a)()() (a).b() (a)[b]() (a):b() a"foo" a"foo -- FAIL a[[foo]] a.b"foo" a[b]"foo" a:b"foo" a()"foo" a"foo"() a"foo".b() a"foo"[b]() a"foo":c() a"foo""bar" a"foo"{} (a):b"foo".c[d]:e"bar" (a):b"foo"[c].d:e"bar" a{}"foo" a{} a.b{} a[b]{} a:b{} a(){} a{}() a{}.b() a{}[b]() a{}:c() a{}{} (a):b{}.c[d]:e{} (a):b{}[c].d:e{} (a"") -- FAIL (a()) -- FAIL (a{}) -- FAIL a@n@() -- FAIL a@n@"" a@n@{} a.b@n@() -- FAIL a.b@n@"" a.b@n@{} a:b@n@() -- FAIL a:b@n@"" a:b@n@{} (a@n@()) -- FAIL (a@n@"") -- FAIL (a@n@{}) -- FAIL (a)@n@() -- FAIL (a)@n@"" (a)@n@{} // { "luaVersion": "5.2" } a@n@() a.b@n@() a:b@n@() (a@n@()) -- FAIL (a)@n@() luaparse-0.3.1/test/scaffolding/functions000066400000000000000000000034511405615720100205240ustar00rootroot00000000000000function -- FAIL function 1 -- FAIL function end -- FAIL function a -- FAIL function a end -- FAIL function a( end -- FAIL function a() end function a(1 -- FAIL function a("foo" -- FAIL function a(p -- FAIL function a(p,) -- FAIL function a(p q -- FAIL function a(p) end function a(p,q) end function a(p q) end -- FAIL function a(p,q,) end -- FAIL function a(p,q,r) end function a(p,q,1 -- FAIL function a(p) do -- FAIL function a(p) 1 end -- FAIL function a(p) return end function a(p) return return end -- FAIL function a(p) do end end function a.( -- FAIL function a.1 -- FAIL function a.b() end function a.b, -- FAIL function a.b.( -- FAIL function a.b.c.d() end function a: -- FAIL function a:1 -- FAIL function a:b() end function a:b: -- FAIL function a:b. -- FAIL function a.b.c:d() end function a(...) end function a(..., -- FAIL function a(p,...) end function a(...,p) end -- FAIL function a(p,q,r,...) end function a() local a local b end function a() local a; local b; end function a() end; function a() end; return ... function a(...) return ... end function a() return ... end -- FAIL function a(...) function b() return ... end end -- FAIL luaparse-0.3.1/test/scaffolding/labels000066400000000000000000000022301405615720100177500ustar00rootroot00000000000000goto "foo" ::foo:: -- FAIL goto foo -- FAIL // { "luaVersion": "5.2" } ::foo -- FAIL ::foo:: ::break:: -- FAIL goto "foo" -- FAIL goto hasOwnProperty -- FAIL goto x ::x:: goto x do ::x:: end -- FAIL do ::l1:: end goto l1 -- FAIL ::x:: ::x:: -- FAIL goto x local a ::x:: f() -- FAIL goto x local a, b ::x:: f() -- FAIL goto x local function a() end ::x:: f() -- FAIL do goto x local a end ::x:: f() do local a goto x end local b ::x:: f() -- FAIL do goto x local a ::x:: end while 0 do goto x local a ::x:: end repeat goto x local a ::x:: until 0 -- FAIL do goto x local a ::x:: ::y:: ::z:: end do do ::x:: end do goto x end end -- FAIL do do goto x end do ::x:: end end -- FAIL do do goto x end do end ::x:: end // { "luaVersion": "LuaJIT" } ::foo:: goto "foo" goto foo -- FAIL ::foo:: goto foo goto goto -- FAIL ::goto:: -- sic! luaparse-0.3.1/test/scaffolding/literals000066400000000000000000000043751405615720100203410ustar00rootroot00000000000000a -- FAIL a = 1 a = .1 a = 1.1 a = 10.1 a = 1e -- FAIL a = 1e1 a = 1E1 a = 1e+9 a = 1e-1 a = 0x -- FAIL a = 0xf a = 0xf. a = 0xf.3 a = 0xfp -- FAIL a = 0xfp1 a = 0xfp+1 a = 0xfp-1 a = 0xFP+9 a = 1 .. 3 .. -2 a = 1 .. "bar" a = " -- FAIL a = "' -- FAIL a = '" -- FAIL a = "@n@" -- FAIL a = ' -- FAIL a = '@n@' -- FAIL a = [[ -- FAIL a = [[@n@]] a = "bar -- FAIL a = 'bar' a = "bar" a = [=aa -- FAIL a = nil a = true a = false a = ... a = [[hello@n@world]] a = { 1, 2, [[hello@n@@n@world]], @n@ 3 } a = "\@r@" a = "\@n@" a = "\@r@@n@" a = "\@n@@r@" a = "\u" a = "\?" a = [=[] -- FAIL a = [=[x] -- FAIL a = [=[x]x -- FAIL // { "luaVersion": "5.2" } a = "\u" -- FAIL a = "\?" -- FAIL // { "luaVersion": "LuaJIT" } a = 1 a = 1L -- FAIL a = 1LL a = 1.1L -- FAIL a = 1.1LL -- FAIL a = 1l -- FAIL a = 1ll a = 1.1l -- FAIL a = 1.1ll -- FAIL a = 1U -- FAIL a = 1UL -- FAIL a = 1ULL a = 1.1U -- FAIL a = 1.1UL -- FAIL a = 1.1ULL -- FAIL a = 1u -- FAIL a = 1ul -- FAIL a = 1ull a = 1.1u -- FAIL a = 1.1ul -- FAIL a = 1.1ull -- FAIL a = 1i a = 1.1i a = 1I a = 1.1I a = 1e1i a = 1.1e1i a = 1e1I a = 1.1e1I a = 0xfi a = 0xf.i a = 0xf.3i a = 0xfp1i a = 0xf.p1i a = 0xf.3p+1i luaparse-0.3.1/test/scaffolding/local000066400000000000000000000041721405615720100176070ustar00rootroot00000000000000local -- FAIL local; -- FAIL local = -- FAIL local end -- FAIL local a local a; local a, b, c local a; local b local c; local a = 1 local a local b = a local a, b = 1, 2 local a, b, c = 1, 2, 3 local a, b, c = 1 local a = 1, 2, 3 local a, local -- FAIL local 1 -- FAIL local "foo" -- FAIL local a = local -- FAIL local a, b, = -- FAIL local a, b = 1, local -- FAIL local a, b = , local -- FAIL local function -- FAIL local function 1 -- FAIL local function end -- FAIL local function a -- FAIL local function a end -- FAIL local function a( end -- FAIL local function a() end local function a(1 -- FAIL local function a("foo" -- FAIL local function a(p -- FAIL local function a(p,) -- FAIL local function a(p q -- FAIL local function a(p) end local function a(p,q) end local function a(p q) end -- FAIL local function a(p,q,) end -- FAIL local function a(p,q,r) end local function a(p,q,1 -- FAIL local function a(p) do -- FAIL local function a(p) 1 end -- FAIL local function a(p) return end local function a(p) return return end -- FAIL local function a(p) do end end local function a. -- FAIL local function a: -- FAIL local function a(...) end local function a(..., -- FAIL local function a(p,...) end local function a(p,q,r,...) end local function a() local a local b end local function a() local a; local b; end local function a() end; local function a() end; local a = { b = { z = 1 } } local Дождь = {} -- FAIL // { "extendedIdentifiers": true } local Дождь = {} luaparse-0.3.1/test/scaffolding/operators000066400000000000000000000027061405615720100205340ustar00rootroot00000000000000a = -"foo" a = - -- FAIL a = not 10 a = not -- FAIL a = 1 + -- FAIL a = 1 .. -- FAIL a = 1 * / -- FAIL a = 1 + -2; a = 1 - -2 a = 1 * - -- FAIL a = 1 * not 2; a = 1 / not 2 a = 1 / not -- FAIL a = 1 + 2 - 3 * 4 / 5 ^ 6 a = ((1 -- FAIL a = ((1 + 2) -- FAIL a = 1) -- FAIL a = a + b - c a = "foo" + "bar" a = "foo".."bar".."baz" a = true + false - nil a = {} * {} a = function() end / function() end a = a() ^ b() a = 1 == 2; a = 1 ~= 2 a = 1 < 2 <= 2 > 2 >= 2 == 2 a = 1 == -- FAIL a = ` -- FAIL a = ~ -- FAIL a = ~= 2 -- FAIL a = a ~= b a = 1 and 2 or 2 a = 1 and -- FAIL a = or 1 -- FAIL a = {} and {} or {} a = (1) and ("foo") or (nil) // { "luaVersion": "5.2" } a = 1 // 0 -- FAIL a = p ~ q -- FAIL a = p & q -- FAIL // { "luaVersion": "5.3" } a = 1 // 0 a = p ~ q >> r | s a = ~ p ~ q / r a = a <= -- FAIL a = a >= -- FAIL luaparse-0.3.1/test/scaffolding/repeat000066400000000000000000000015121405615720100177700ustar00rootroot00000000000000repeat -- FAIL repeat until -- FAIL repeat until 0 repeat until false repeat until local -- FAIL repeat end -- FAIL repeat 1 -- FAIL repeat = -- FAIL repeat local a until 1 repeat local a local b until 0 repeat local a; local b; until 0 repeat ; until 1 -- FAIL repeat 2 until 1 -- FAIL repeat "foo" until 1 -- FAIL repeat return until 0 repeat return return until 0 -- FAIL repeat break until 0 repeat break break until 0 -- FAIL repeat do end until 0 repeat do return end until 0 repeat do break end until 0 // { "luaVersion": "5.2" } repeat ; until 1 repeat break break until 0 luaparse-0.3.1/test/scaffolding/return000066400000000000000000000003161405615720100200300ustar00rootroot00000000000000return return -- FAIL return 1 return local -- FAIL return "foo" return 1, -- FAIL return 1,2,3 return a,b,c,d return 1,2; luaparse-0.3.1/test/scaffolding/scope000066400000000000000000000011421405615720100176200ustar00rootroot00000000000000local foo = 1 do foo = 2 end do local foo = 1 end foo = 2 do local foo = 1 end do foo = 2 end local foo do foo = 1 do foo = 2 end end local function foo() end foo() local a = { a } local b = { b, b.a, b[a], b:a() } local b = {} local a = { b, b.a, b[a], b:a() } local c local a = { b[c] } local a = function() end a() local a, b = 1, a local a, b = 1, function() b = 2 end local a (a):b():c() local a, b for i, a, b in c do end local a, b, c for i, a, b in c do end local a = {} function a:b() return self end self = nil repeat local a = true until a local a = function (b) end b = 0 for a = 1, 5 do end a = 0 luaparse-0.3.1/test/scaffolding/statements000066400000000000000000000003041405615720100206750ustar00rootroot00000000000000return nil -- FAIL return; ; -- FAIL // { "luaVersion": "5.2" } return; return;; -- FAIL ; luaparse-0.3.1/test/scaffolding/tableconstructors000066400000000000000000000024201405615720100222670ustar00rootroot00000000000000a = { -- FAIL a = {} a = {,} -- FAIL a = {;} -- FAIL a = {,,} -- FAIL a = {;;} -- FAIL a = {{ -- FAIL a = {{{}}} a = {{},{},{{}},} a = { 1 } a = { 1, } a = { 1; } a = { 1, 2 } a = { a, b, c, } a = { true; false, nil; } a = { a.b, a[b]; a:c(), } a = { 1 + 2, a > b, "a" or "b" } a = { a=1, } a = { a=1, b="foo", c=nil } a = { a -- FAIL a = { a= -- FAIL a = { a=, -- FAIL a = { a=; -- FAIL a = { 1, a="foo" -- FAIL a = { 1, a="foo"; b={}, d=true; } a = { [ -- FAIL a = { [1 -- FAIL a = { [1] -- FAIL a = { [a]= -- FAIL a = { ["foo"]="bar" } a = { [1]=a, [2]=b, } a = { true, a=1; ["foo"]="bar", } a = { [] } -- FAIL a = { a= } -- FAIL a = { a.b=1 } -- FAIL a = { a[b[c]]=1 } -- FAIL a = { 2 3 4 } -- FAIL luaparse-0.3.1/test/scaffolding/while000066400000000000000000000016511405615720100176240ustar00rootroot00000000000000while -- FAIL while do -- FAIL while = -- FAIL while 1 do -- FAIL while 1 do end while 1 do local a end while 1 do local a local b end while 1 do local a; local b; end while 1 do 2 end -- FAIL while 1 do "foo" end -- FAIL while true do end while 1 do ; end -- FAIL while 1 do while -- FAIL while 1 end -- FAIL while 1 2 do -- FAIL while 1 = 2 do -- FAIL while 1 do return end while 1 do return return end -- FAIL while 1 do do end end while 1 do do return end end while 1 do break end while 1 do break break end -- FAIL while 1 do do break end end // { "luaVersion": "5.2" } while 1 do ; end while 1 do break break end luaparse-0.3.1/test/spec/000077500000000000000000000000001405615720100152415ustar00rootroot00000000000000luaparse-0.3.1/test/spec/.jshintrc000077700000000000000000000000001405615720100211212../.jshintrcustar00rootroot00000000000000luaparse-0.3.1/test/spec/assignments.js000066400000000000000000002263731405615720100201470ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'assignments', function (exports) { 'use strict'; exports.name = 'assignments'; exports.spec = [ { "source": "a", "result": "[1:1] '=' expected near ''" }, { "source": "a,", "result": "[1:2] unexpected symbol near ''" }, { "source": "a,b,c", "result": "[1:5] '=' expected near ''" }, { "source": "a,b =", "result": "[1:5] expected near ''" }, { "source": "a = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1,2,3", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, { "type": "NumericLiteral", "value": 3, "raw": "3", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a,b,c = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false } ] } }, { "source": "a,b,c = 1,2,3", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ] }, { "type": "NumericLiteral", "value": 3, "raw": "3", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false } ] } }, { "source": "a.b = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a.b.c = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a[b] = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false } ] } }, { "source": "a[b][c] = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "IndexExpression", "base": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] }, "index": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ], "isLocal": false } ] } }, { "source": "a.b[c] = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "IndexExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "index": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false } ] } }, { "source": "a[b].c = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ] }, "base": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false } ] } }, { "source": "a[b], a[c] = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] }, { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": false }, "index": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 10 } }, "range": [ 6, 10 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false } ] } }, { "source": "a().b = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "({})[b] = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "IndexExpression", "base": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 3 } }, "range": [ 1, 3 ] }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ], "isLocal": false } ] } }, { "source": "a\"\"[b] = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "IndexExpression", "base": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"\"", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 3 } }, "range": [ 1, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false } ] } }, { "source": "a{}[b] = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "IndexExpression", "base": { "type": "TableCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 3 } }, "range": [ 1, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false } ] } }, { "source": "({{}})[a][b] = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "IndexExpression", "base": { "type": "IndexExpression", "base": { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 4 } }, "range": [ 2, 4 ] }, "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 4 } }, "range": [ 2, 4 ] } ], "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 5 } }, "range": [ 1, 5 ] }, "index": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": false } ] } }, { "source": "(a).b = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false } ] } }, { "source": "(1).a = 0", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "init": [ { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [] } }, { "source": "0 = 0", "result": "[1:0] unexpected number '0' near '='" }, { "source": "\"foo\" = 0", "result": "[1:0] unexpected string '\"foo\"' near '='" }, { "source": "true = 0", "result": "[1:0] unexpected boolean 'true' near '='" }, { "source": "(a) = 0", "result": "[1:4] unexpected symbol '=' near '0'" }, { "source": "{} = 0", "result": "[1:0] unexpected symbol '{' near '}'" }, { "source": "a, b() c()", "result": "[1:7] unexpected identifier 'c' near '('" }, { "source": "a, b(), c", "result": "[1:6] unexpected symbol ',' near 'c'" }, { "source": "a:b() = 0", "result": "[1:6] unexpected symbol '=' near '0'" }, { "source": "a() = 0", "result": "[1:4] unexpected symbol '=' near '0'" }, { "source": "a.b:c() = 0", "result": "[1:8] unexpected symbol '=' near '0'" }, { "source": "a[b]() = 0", "result": "[1:7] unexpected symbol '=' near '0'" }, { "source": "a = a b", "result": "[1:7] '=' expected near ''" }, { "source": "a = 1 2", "result": "[1:6] unexpected number '2' near ''" }, { "source": "a = a = 1", "result": "[1:6] unexpected symbol '=' near '1'" } ]; })); luaparse-0.3.1/test/spec/break.js000066400000000000000000001770761405615720100167050ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'break', function (exports) { 'use strict'; exports.name = 'break'; exports.spec = [ { "source": "break", "result": "[1:5] no loop to break near ''" }, { "source": "do break end", "result": "[1:9] no loop to break near 'end'" }, { "source": "if 0 then break end", "result": "[1:16] no loop to break near 'end'" }, { "source": "if 0 then else break end", "result": "[1:21] no loop to break near 'end'" }, { "source": "while 0 do function x() break end end", "result": "[1:30] no loop to break near 'end'" }, { "source": "repeat function x() break end until 0", "result": "[1:26] no loop to break near 'end'" }, { "source": "repeat x = function() break end until 0", "result": "[1:28] no loop to break near 'end'" }, { "source": "repeat break until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 12 } }, "range": [ 7, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ], "comments": [], "globals": [] } }, { "source": "repeat do break end until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 27 } }, "range": [ 26, 27 ] }, "body": [ { "type": "DoStatement", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 15 } }, "range": [ 10, 15 ] } ], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 19 } }, "range": [ 7, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] } }, { "source": "repeat if 0 then break end until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 33 }, "end": { "line": 1, "column": 34 } }, "range": [ 33, 34 ] }, "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 22 } }, "range": [ 17, 22 ] } ], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 22 } }, "range": [ 7, 22 ] } ], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 26 } }, "range": [ 7, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 34 } }, "range": [ 0, 34 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 34 } }, "range": [ 0, 34 ], "comments": [], "globals": [] } }, { "source": "repeat if 0 then else break end until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 38 }, "end": { "line": 1, "column": 39 } }, "range": [ 38, 39 ] }, "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ] }, "body": [], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 16 } }, "range": [ 7, 16 ] }, { "type": "ElseClause", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 27 } }, "range": [ 22, 27 ] } ], "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 27 } }, "range": [ 17, 27 ] } ], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 31 } }, "range": [ 7, 31 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 39 } }, "range": [ 0, 39 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 39 } }, "range": [ 0, 39 ], "comments": [], "globals": [] } }, { "source": "while 0 do break end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 16 } }, "range": [ 11, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ], "comments": [], "globals": [] } }, { "source": "while 0 do do break end end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "DoStatement", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 19 } }, "range": [ 14, 19 ] } ], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 23 } }, "range": [ 11, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] } }, { "source": "while 0 do if 0 then break end end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 26 } }, "range": [ 21, 26 ] } ], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 26 } }, "range": [ 11, 26 ] } ], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 30 } }, "range": [ 11, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 34 } }, "range": [ 0, 34 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 34 } }, "range": [ 0, 34 ], "comments": [], "globals": [] } }, { "source": "while 0 do if 0 then else break end end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ] }, "body": [], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 20 } }, "range": [ 11, 20 ] }, { "type": "ElseClause", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 31 } }, "range": [ 26, 31 ] } ], "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 31 } }, "range": [ 21, 31 ] } ], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 35 } }, "range": [ 11, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 39 } }, "range": [ 0, 39 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 39 } }, "range": [ 0, 39 ], "comments": [], "globals": [] } }, { "source": "for i = 1, 2 do break end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "end": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "step": null, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 21 } }, "range": [ 16, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [] } }, { "source": "for i = 1, 2 do do break end end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "end": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "step": null, "body": [ { "type": "DoStatement", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 24 } }, "range": [ 19, 24 ] } ], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 28 } }, "range": [ 16, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ], "comments": [], "globals": [] } }, { "source": "for i = 1, 2 do if 0 then break end end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "end": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "step": null, "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 31 } }, "range": [ 26, 31 ] } ], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 31 } }, "range": [ 16, 31 ] } ], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 35 } }, "range": [ 16, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 39 } }, "range": [ 0, 39 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 39 } }, "range": [ 0, 39 ], "comments": [], "globals": [] } }, { "source": "for i = 1, 2 do if 0 then else break end end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "end": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "step": null, "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ] }, "body": [], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 25 } }, "range": [ 16, 25 ] }, { "type": "ElseClause", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 31 }, "end": { "line": 1, "column": 36 } }, "range": [ 31, 36 ] } ], "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 36 } }, "range": [ 26, 36 ] } ], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 40 } }, "range": [ 16, 40 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 44 } }, "range": [ 0, 44 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 44 } }, "range": [ 0, 44 ], "comments": [], "globals": [] } }, { "source": "for a in b do break end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 19 } }, "range": [ 14, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for a in b do do break end end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "DoStatement", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 22 } }, "range": [ 17, 22 ] } ], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 26 } }, "range": [ 14, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for a in b do if 0 then break end end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 29 } }, "range": [ 24, 29 ] } ], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 29 } }, "range": [ 14, 29 ] } ], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 33 } }, "range": [ 14, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 37 } }, "range": [ 0, 37 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 37 } }, "range": [ 0, 37 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for a in b do if 0 then else break end end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ] }, "body": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 23 } }, "range": [ 14, 23 ] }, { "type": "ElseClause", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 29 }, "end": { "line": 1, "column": 34 } }, "range": [ 29, 34 ] } ], "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 34 } }, "range": [ 24, 34 ] } ], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 38 } }, "range": [ 14, 38 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 42 } }, "range": [ 0, 42 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 42 } }, "range": [ 0, 42 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function x() break end", "result": "[1:19] no loop to break near 'end'" }, { "source": "local function x() break end", "result": "[1:25] no loop to break near 'end'" }, { "source": "function x() repeat break until 0 end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [], "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 32 }, "end": { "line": 1, "column": 33 } }, "range": [ 32, 33 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 25 } }, "range": [ 20, 25 ] } ], "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 33 } }, "range": [ 13, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 37 } }, "range": [ 0, 37 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 37 } }, "range": [ 0, 37 ], "comments": [], "globals": [ { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "break", "result": "[1:5] no loop to break near ''", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "do break end", "result": "[1:9] no loop to break near 'end'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "if 0 then break end", "result": "[1:16] no loop to break near 'end'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "if 0 then else break end", "result": "[1:21] no loop to break near 'end'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "while 0 do function x() break end end", "result": "[1:30] no loop to break near 'end'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "repeat function x() break end until 0", "result": "[1:26] no loop to break near 'end'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "repeat x = function() break end until 0", "result": "[1:28] no loop to break near 'end'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "repeat break until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 12 } }, "range": [ 7, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "repeat do break end until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 27 } }, "range": [ 26, 27 ] }, "body": [ { "type": "DoStatement", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 15 } }, "range": [ 10, 15 ] } ], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 19 } }, "range": [ 7, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } } ]; })); luaparse-0.3.1/test/spec/comments.js000066400000000000000000000422051405615720100174270ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'comments', function (exports) { 'use strict'; exports.name = 'comments'; exports.spec = [ { "source": "-- comment", "result": { "type": "Chunk", "body": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 10 } }, "range": [ 10, 10 ], "comments": [ { "type": "Comment", "value": " comment", "raw": "-- comment", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "globals": [] } }, { "source": "-- comment\n-- comment", "result": { "type": "Chunk", "body": [], "loc": { "start": { "line": 2, "column": 10 }, "end": { "line": 2, "column": 10 } }, "range": [ 21, 21 ], "comments": [ { "type": "Comment", "value": " comment", "raw": "-- comment", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, { "type": "Comment", "value": " comment", "raw": "-- comment", "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 10 } }, "range": [ 11, 21 ] } ], "globals": [] } }, { "source": "--coment", "result": { "type": "Chunk", "body": [], "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 8 } }, "range": [ 8, 8 ], "comments": [ { "type": "Comment", "value": "coment", "raw": "--coment", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "globals": [] } }, { "source": "-- comment\nreturn", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 6 } }, "range": [ 11, 17 ] } ], "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 6 } }, "range": [ 11, 17 ], "comments": [ { "type": "Comment", "value": " comment", "raw": "-- comment", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "globals": [] } }, { "source": "return --comment \n", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [ { "type": "Comment", "value": "comment ", "raw": "--comment ", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 17 } }, "range": [ 7, 17 ] } ], "globals": [] } }, { "source": "--[[comment]]", "result": { "type": "Chunk", "body": [], "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 13 } }, "range": [ 13, 13 ], "comments": [ { "type": "Comment", "value": "comment", "raw": "--[[comment]]", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] } ], "globals": [] } }, { "source": "if true--[[comment]]then end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 7 } }, "range": [ 3, 7 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ], "comments": [ { "type": "Comment", "value": "comment", "raw": "--[[comment]]", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 20 } }, "range": [ 7, 20 ] } ], "globals": [] } }, { "source": "--[=[comment]=] return", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 22 } }, "range": [ 16, 22 ] } ], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 22 } }, "range": [ 16, 22 ], "comments": [ { "type": "Comment", "value": "comment", "raw": "--[=[comment]=]", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 15 } }, "range": [ 0, 15 ] } ], "globals": [] } }, { "source": "--[===[comment\n--[=[sub]=]--\n]===]return", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 3, "column": 5 }, "end": { "line": 3, "column": 11 } }, "range": [ 34, 40 ] } ], "loc": { "start": { "line": 3, "column": 5 }, "end": { "line": 3, "column": 11 } }, "range": [ 34, 40 ], "comments": [ { "type": "Comment", "value": "comment\n--[=[sub]=]--\n", "raw": "--[===[comment\n--[=[sub]=]--\n]===]", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 3, "column": 5 } }, "range": [ 0, 34 ] } ], "globals": [] } }, { "source": "--[[comment\nline two]]", "result": { "type": "Chunk", "body": [], "loc": { "start": { "line": 2, "column": 10 }, "end": { "line": 2, "column": 10 } }, "range": [ 22, 22 ], "comments": [ { "type": "Comment", "value": "comment\nline two", "raw": "--[[comment\nline two]]", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 10 } }, "range": [ 0, 22 ] } ], "globals": [] } }, { "source": "--[[\ncomment\nline two\n]]", "result": { "type": "Chunk", "body": [], "loc": { "start": { "line": 4, "column": 2 }, "end": { "line": 4, "column": 2 } }, "range": [ 24, 24 ], "comments": [ { "type": "Comment", "value": "comment\nline two\n", "raw": "--[[\ncomment\nline two\n]]", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 4, "column": 2 } }, "range": [ 0, 24 ] } ], "globals": [] } }, { "source": "--[==\nreturn --]]", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 6 } }, "range": [ 6, 12 ] } ], "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 6 } }, "range": [ 6, 12 ], "comments": [ { "type": "Comment", "value": "[==", "raw": "--[==", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, { "type": "Comment", "value": "]]", "raw": "--]]", "loc": { "start": { "line": 2, "column": 7 }, "end": { "line": 2, "column": 11 } }, "range": [ 13, 17 ] } ], "globals": [] } }, { "source": "if true -- comment\nthen end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 7 } }, "range": [ 3, 7 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 4 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 8 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 8 } }, "range": [ 0, 27 ], "comments": [ { "type": "Comment", "value": " comment", "raw": "-- comment", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 18 } }, "range": [ 8, 18 ] } ], "globals": [] } }, { "source": "--[=[x]x", "result": "[1:9] unfinished long comment (starting at line 1) near ''" } ]; })); luaparse-0.3.1/test/spec/conditional.js000066400000000000000000001514351405615720100201130ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'conditional', function (exports) { 'use strict'; exports.name = 'conditional'; exports.spec = [ { "source": "if", "result": "[1:2] expected near ''" }, { "source": "elseif", "result": "[1:0] unexpected keyword 'elseif' near ''" }, { "source": "else", "result": "[1:0] unexpected keyword 'else' near ''" }, { "source": "then", "result": "[1:0] unexpected keyword 'then' near ''" }, { "source": "if then", "result": "[1:3] expected near 'then'" }, { "source": "if 1", "result": "[1:4] 'then' expected near ''" }, { "source": "if 1 then", "result": "[1:9] 'end' expected near ''" }, { "source": "if 1 else", "result": "[1:5] 'then' expected near 'else'" }, { "source": "if 1 then else", "result": "[1:14] 'end' expected near ''" }, { "source": "if 1 then elseif", "result": "[1:16] expected near ''" }, { "source": "if 1 then end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ], "comments": [], "globals": [] } }, { "source": "if 1 then local a end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 17 } }, "range": [ 10, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [] } }, { "source": "if 1 then local a local b end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 17 } }, "range": [ 10, 17 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 25 } }, "range": [ 24, 25 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 25 } }, "range": [ 18, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 29 } }, "range": [ 0, 29 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 29 } }, "range": [ 0, 29 ], "comments": [], "globals": [] } }, { "source": "if 1 then local a; local b; end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 17 } }, "range": [ 10, 17 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 26 } }, "range": [ 25, 26 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 26 } }, "range": [ 19, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 31 } }, "range": [ 0, 31 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 31 } }, "range": [ 0, 31 ], "comments": [], "globals": [] } }, { "source": "if 1 then else end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, { "type": "ElseClause", "body": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 14 } }, "range": [ 10, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ], "comments": [], "globals": [] } }, { "source": "if 1 then local a else local b end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 17 } }, "range": [ 10, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] }, { "type": "ElseClause", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 29 }, "end": { "line": 1, "column": 30 } }, "range": [ 29, 30 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 23 }, "end": { "line": 1, "column": 30 } }, "range": [ 23, 30 ] } ], "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 30 } }, "range": [ 18, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 34 } }, "range": [ 0, 34 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 34 } }, "range": [ 0, 34 ], "comments": [], "globals": [] } }, { "source": "if 1 then local a; else local b; end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 17 } }, "range": [ 10, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] }, { "type": "ElseClause", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 30 }, "end": { "line": 1, "column": 31 } }, "range": [ 30, 31 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 31 } }, "range": [ 24, 31 ] } ], "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 32 } }, "range": [ 19, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 36 } }, "range": [ 0, 36 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 36 } }, "range": [ 0, 36 ], "comments": [], "globals": [] } }, { "source": "if 1 then elseif 2", "result": "[1:18] 'then' expected near ''" }, { "source": "if 1 then elseif 2 then", "result": "[1:23] 'end' expected near ''" }, { "source": "if 1 then elseif 2 then end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, { "type": "ElseifClause", "condition": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ] }, "body": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 23 } }, "range": [ 10, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] } }, { "source": "if 1 then local a elseif 2 then local b end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 17 } }, "range": [ 10, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] }, { "type": "ElseifClause", "condition": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 26 } }, "range": [ 25, 26 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 38 }, "end": { "line": 1, "column": 39 } }, "range": [ 38, 39 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 32 }, "end": { "line": 1, "column": 39 } }, "range": [ 32, 39 ] } ], "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 39 } }, "range": [ 18, 39 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 43 } }, "range": [ 0, 43 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 43 } }, "range": [ 0, 43 ], "comments": [], "globals": [] } }, { "source": "if 1 then local a; elseif 2 then local b; end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 17 } }, "range": [ 10, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] }, { "type": "ElseifClause", "condition": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 27 } }, "range": [ 26, 27 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 39 }, "end": { "line": 1, "column": 40 } }, "range": [ 39, 40 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 33 }, "end": { "line": 1, "column": 40 } }, "range": [ 33, 40 ] } ], "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 41 } }, "range": [ 19, 41 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 45 } }, "range": [ 0, 45 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 45 } }, "range": [ 0, 45 ], "comments": [], "globals": [] } }, { "source": "if 1 then elseif 2 then else end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, { "type": "ElseifClause", "condition": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ] }, "body": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 23 } }, "range": [ 10, 23 ] }, { "type": "ElseClause", "body": [], "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 28 } }, "range": [ 24, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ], "comments": [], "globals": [] } }, { "source": "if 1 then else if 2 then end end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, { "type": "ElseClause", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 19 } }, "range": [ 18, 19 ] }, "body": [], "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 24 } }, "range": [ 15, 24 ] } ], "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 28 } }, "range": [ 15, 28 ] } ], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 28 } }, "range": [ 10, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ], "comments": [], "globals": [] } }, { "source": "if 1 then else if 2 then end", "result": "[1:28] 'end' expected near ''" }, { "source": "if 1 then return end", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 16 } }, "range": [ 10, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ], "comments": [], "globals": [] } }, { "source": "if 1 then return return end", "result": "[1:17] 'end' expected near 'return'" }, { "source": "if 1 then end; if 1 then end;", "result": { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 4 } }, "range": [ 3, 4 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] }, { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 19 } }, "range": [ 18, 19 ] }, "body": [], "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 24 } }, "range": [ 15, 24 ] } ], "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 28 } }, "range": [ 15, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 29 } }, "range": [ 0, 29 ], "comments": [], "globals": [] } }, { "source": "if then end", "result": "[1:3] expected near 'then'" }, { "source": "if 1 then elseif then end", "result": "[1:17] expected near 'then'" } ]; })); luaparse-0.3.1/test/spec/do.js000066400000000000000000000566471405615720100162230ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'do', function (exports) { 'use strict'; exports.name = 'do'; exports.spec = [ { "source": "do", "result": "[1:2] 'end' expected near ''" }, { "source": "end", "result": "[1:0] unexpected keyword 'end' near ''" }, { "source": "do end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [], "globals": [] } }, { "source": "do ; end", "result": "[1:3] unexpected symbol ';' near 'end'" }, { "source": "do 1 end", "result": "[1:3] unexpected number '1' near 'end'" }, { "source": "do \"foo\" end", "result": "[1:3] unexpected string '\"foo\"' near 'end'" }, { "source": "do local a, b end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 13 } }, "range": [ 3, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [] } }, { "source": "do local a local b end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 10 } }, "range": [ 3, 10 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 18 } }, "range": [ 11, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [] } }, { "source": "do local a; local b; end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 10 } }, "range": [ 3, 10 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 19 } }, "range": [ 18, 19 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 19 } }, "range": [ 12, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ], "comments": [], "globals": [] } }, { "source": "do local a = 1 end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] } ], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 14 } }, "range": [ 3, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ], "comments": [], "globals": [] } }, { "source": "do do end end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 9 } }, "range": [ 3, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ], "comments": [], "globals": [] } }, { "source": "do do end; end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 9 } }, "range": [ 3, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ], "comments": [], "globals": [] } }, { "source": "do do do end end end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "DoStatement", "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 12 } }, "range": [ 6, 12 ] } ], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 16 } }, "range": [ 3, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ], "comments": [], "globals": [] } }, { "source": "do do do end; end; end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "DoStatement", "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 12 } }, "range": [ 6, 12 ] } ], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 17 } }, "range": [ 3, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [] } }, { "source": "do do do return end end end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "DoStatement", "body": [ { "type": "DoStatement", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 15 } }, "range": [ 9, 15 ] } ], "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 19 } }, "range": [ 6, 19 ] } ], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 23 } }, "range": [ 3, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] } }, { "source": "do end do", "result": "[1:9] 'end' expected near ''" }, { "source": "do end end", "result": "[1:7] unexpected keyword 'end' near ''" }, { "source": "do return end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 9 } }, "range": [ 3, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ], "comments": [], "globals": [] } }, { "source": "do return return end", "result": "[1:10] 'end' expected near 'return'" }, { "source": "do ; end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } } ]; })); luaparse-0.3.1/test/spec/escapesequences.js000066400000000000000000001502041405615720100207550ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'escapesequences', function (exports) { 'use strict'; exports.name = 'escapesequences'; exports.spec = [ { "source": "a = \"bar\nbaz\"", "result": "[1:10] unfinished string near '\"bar'" }, { "source": "a = \"bar\rbaz\"", "result": "[1:10] unfinished string near '\"bar'" }, { "source": "a = \"bar\\n\\r\\t\tbaz\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"bar\\n\\r\\t\tbaz\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 19 } }, "range": [ 4, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"bar\\80baz\\a\\80\\0foo\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"bar\\80baz\\a\\80\\0foo\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 25 } }, "range": [ 4, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"bar\\f\\v\\bbaz\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"bar\\f\\v\\bbaz\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 18 } }, "range": [ 4, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"bar\f\u000b\baz\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"bar\f\u000b\baz\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 14 } }, "range": [ 4, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = '\\\\'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\\\'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = '\\''", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\''", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = '\\['", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\['", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = '\\123'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\123'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = '\\255'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\255'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = '\\256'", "result": "[1:10] decimal escape too large near '\\256'" }, { "source": "a = '\\300'", "result": "[1:10] decimal escape too large near '\\300'" }, { "source": "a = [[bar\\f\\v\\bbaz]]", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "[[bar\\f\\v\\bbaz]]", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 20 } }, "range": [ 4, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = [[\\]]", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "[[\\]]", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = '\\z \\x'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\z \\x'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 11 } }, "range": [ 4, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = '\\['", "result": "[1:7] invalid escape sequence near '\\['", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = '\\x23'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\x23'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = '\\x0'", "result": "[1:7] hexadecimal digit expected near '\\x0'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = '\\x0x'", "result": "[1:7] hexadecimal digit expected near '\\x0'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = '\\xx'", "result": "[1:7] hexadecimal digit expected near '\\xx'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = \"bar\\z baz\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"bar\\z baz\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 18 } }, "range": [ 4, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = '\\u{0}'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\u{0}'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 11 } }, "range": [ 4, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{1f4a9}'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\u{1f4a9}'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 15 } }, "range": [ 4, 15 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 15 } }, "range": [ 0, 15 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 15 } }, "range": [ 0, 15 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{7f}\\u{80}'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\u{7f}\\u{80}'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 18 } }, "range": [ 4, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{7ff}\\u{800}'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\u{7ff}\\u{800}'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 20 } }, "range": [ 4, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{ffff}\\u{1f4a9}'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\u{ffff}\\u{1f4a9}'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 23 } }, "range": [ 4, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{10ffff}'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\u{10ffff}'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 16 } }, "range": [ 4, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{110000}'", "result": "[1:16] UTF-8 value too large near '\\u{110000}'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{120000}'", "result": "[1:16] UTF-8 value too large near '\\u{120000}'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{000000001f4a9}'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'\\u{000000001f4a9}'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 23 } }, "range": [ 4, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{100000001f4a9}'", "result": "[1:16] UTF-8 value too large near '\\u{1000000'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{1f4a9'", "result": "[1:14] missing '}' near '\\u{1f4a9''", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = \"\\u{1f4a9\"", "result": "[1:14] missing '}' near '\\u{1f4a9\"'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\uaa'", "result": "[1:9] missing '{' near '\\ua'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{}'", "result": "[1:9] hexadecimal digit expected near '\\u{'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = '\\u{0g}'", "result": "[1:11] hexadecimal digit expected near '\\u{0g'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } } ]; })); luaparse-0.3.1/test/spec/expressions.js000066400000000000000000002221311405615720100201620ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'expressions', function (exports) { 'use strict'; exports.name = 'expressions'; exports.spec = [ { "source": "a =", "result": "[1:3] expected near ''" }, { "source": "a = [[foo]]", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "[[foo]]", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 11 } }, "range": [ 4, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = {}", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 6 } }, "range": [ 4, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = (a)", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ], "isLocal": false } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = (nil)", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NilLiteral", "value": null, "raw": "nil", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 8 } }, "range": [ 5, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = (true)", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 9 } }, "range": [ 5, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = (1)", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = (\"foo\")", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 10 } }, "range": [ 5, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = ([[foo]])", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "[[foo]]", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 12 } }, "range": [ 5, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = ({})", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 7 } }, "range": [ 5, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = a.b", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = a.b.", "result": "[1:8] expected near ''" }, { "source": "a = a.b.c", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = a:b", "result": "[1:7] function arguments expected near ''" }, { "source": "a = a[]", "result": "[1:6] expected near ']'" }, { "source": "a = a[b]", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": false } ] } }, { "source": "a = a[1]", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "index": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = a[\"foo\"]", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "index": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 11 } }, "range": [ 6, 11 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 12 } }, "range": [ 4, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = ()", "result": "[1:5] expected near ')'" }, { "source": "a = function", "result": "[1:12] '(' expected near ''" }, { "source": "a = function 1", "result": "[1:13] '(' expected near '1'" }, { "source": "a = function a", "result": "[1:13] '(' expected near 'a'" }, { "source": "a = function end", "result": "[1:13] '(' expected near 'end'" }, { "source": "a = function(", "result": "[1:13] or '...' expected near ''" }, { "source": "a = function() end", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 18 } }, "range": [ 4, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = function(1", "result": "[1:13] or '...' expected near '1'" }, { "source": "a = function(p) end", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 19 } }, "range": [ 4, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = function(p,q) end", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 21 } }, "range": [ 4, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = function(p q) end", "result": "[1:15] ')' expected near 'q'" }, { "source": "a = function(p,)", "result": "[1:15] or '...' expected near ')'" }, { "source": "a = function(p q", "result": "[1:15] ')' expected near 'q'" }, { "source": "a = function(p,q,r) end", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 23 } }, "range": [ 4, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = function(p,q,1", "result": "[1:17] or '...' expected near '1'" }, { "source": "a = function(...) end", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [ { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 16 } }, "range": [ 13, 16 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 21 } }, "range": [ 4, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = function(...,", "result": "[1:16] ')' expected near ','" }, { "source": "a = function(p,...) end", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true }, { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 18 } }, "range": [ 15, 18 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 23 } }, "range": [ 4, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = function(p,q,r,...) end", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true }, { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 22 } }, "range": [ 19, 22 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 27 } }, "range": [ 4, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = {'-'}", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "StringLiteral", "value": null, "raw": "'-'", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 8 } }, "range": [ 5, 8 ] }, "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 8 } }, "range": [ 5, 8 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = {'not'}", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "StringLiteral", "value": null, "raw": "'not'", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 10 } }, "range": [ 5, 10 ] }, "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 10 } }, "range": [ 5, 10 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 11 } }, "range": [ 4, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = {not true}", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "UnaryExpression", "operator": "not", "argument": { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 13 } }, "range": [ 9, 13 ] }, "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 13 } }, "range": [ 5, 13 ] }, "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 13 } }, "range": [ 5, 13 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 14 } }, "range": [ 4, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } } ]; })); luaparse-0.3.1/test/spec/for.js000066400000000000000000002573131405615720100164000ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'for', function (exports) { 'use strict'; exports.name = 'for'; exports.spec = [ { "source": "for", "result": "[1:3] expected near ''" }, { "source": "for do", "result": "[1:4] expected near 'do'" }, { "source": "for end", "result": "[1:4] expected near 'end'" }, { "source": "for 1", "result": "[1:4] expected near '1'" }, { "source": "for a", "result": "[1:5] 'in' expected near ''" }, { "source": "for true", "result": "[1:4] expected near 'true'" }, { "source": "for a, in", "result": "[1:7] expected near 'in'" }, { "source": "for a in", "result": "[1:8] expected near ''" }, { "source": "for a do", "result": "[1:6] 'in' expected near 'do'" }, { "source": "for a in do", "result": "[1:9] expected near 'do'" }, { "source": "for a in b do", "result": "[1:13] 'end' expected near ''" }, { "source": "for a in b end", "result": "[1:11] 'do' expected near 'end'" }, { "source": "for a in b, do", "result": "[1:12] expected near 'do'" }, { "source": "for a in b do end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for a in b do local a local b end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 21 } }, "range": [ 14, 21 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 29 } }, "range": [ 28, 29 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 29 } }, "range": [ 22, 29 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for a in b do local a; local b; end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 21 } }, "range": [ 14, 21 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 29 }, "end": { "line": 1, "column": 30 } }, "range": [ 29, 30 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 23 }, "end": { "line": 1, "column": 30 } }, "range": [ 23, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 35 } }, "range": [ 0, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 35 } }, "range": [ 0, 35 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for a in b do 1 end", "result": "[1:14] unexpected number '1' near 'end'" }, { "source": "for a in b do \"foo\" end", "result": "[1:14] unexpected string '\"foo\"' near 'end'" }, { "source": "for a b in", "result": "[1:6] 'in' expected near 'b'" }, { "source": "for a, b, c in p do end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ], "isLocal": true }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": false } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ], "comments": [], "globals": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": false } ] } }, { "source": "for a, b, c in p, q, r do end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ], "isLocal": true }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 19 } }, "range": [ 18, 19 ], "isLocal": false }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 22 } }, "range": [ 21, 22 ], "isLocal": false } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 29 } }, "range": [ 0, 29 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 29 } }, "range": [ 0, 29 ], "comments": [], "globals": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 19 } }, "range": [ 18, 19 ], "isLocal": false }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 22 } }, "range": [ 21, 22 ], "isLocal": false } ] } }, { "source": "for a in 1 do end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [] } }, { "source": "for a in true do end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 13 } }, "range": [ 9, 13 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ], "comments": [], "globals": [] } }, { "source": "for a in \"foo\" do end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 14 } }, "range": [ 9, 14 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [] } }, { "source": "for a in b do break end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 19 } }, "range": [ 14, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for a in b do break break end", "result": "[1:20] 'end' expected near 'break'" }, { "source": "for a in b do return end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 20 } }, "range": [ 14, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for a in b do return return end", "result": "[1:21] 'end' expected near 'return'" }, { "source": "for a in b do do end end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 20 } }, "range": [ 14, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for a in b do do break end end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "DoStatement", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 22 } }, "range": [ 17, 22 ] } ], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 26 } }, "range": [ 14, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for a in b do do return end end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "DoStatement", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 23 } }, "range": [ 17, 23 ] } ], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 27 } }, "range": [ 14, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 31 } }, "range": [ 0, 31 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 31 } }, "range": [ 0, 31 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "for =", "result": "[1:4] expected near '='" }, { "source": "for a =", "result": "[1:7] expected near ''" }, { "source": "for a, b =", "result": "[1:9] 'in' expected near '='" }, { "source": "for a = do", "result": "[1:8] expected near 'do'" }, { "source": "for a = 1, do", "result": "[1:11] expected near 'do'" }, { "source": "for a = p, q, do", "result": "[1:14] expected near 'do'" }, { "source": "for a = p q do", "result": "[1:10] ',' expected near 'q'" }, { "source": "for a = b do end", "result": "[1:10] ',' expected near 'do'" }, { "source": "for a = 1, 2, 3, 4 do end", "result": "[1:15] 'do' expected near ','" }, { "source": "for a = p, q do end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "end": { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, "step": null, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ], "comments": [], "globals": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false } ] } }, { "source": "for a = 1, 2 do end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "end": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "step": null, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ], "comments": [], "globals": [] } }, { "source": "for a = 1, 2 do local a local b end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "end": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "step": null, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 23 } }, "range": [ 22, 23 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 23 } }, "range": [ 16, 23 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 30 }, "end": { "line": 1, "column": 31 } }, "range": [ 30, 31 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 31 } }, "range": [ 24, 31 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 35 } }, "range": [ 0, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 35 } }, "range": [ 0, 35 ], "comments": [], "globals": [] } }, { "source": "for a = 1, 2 do local a; local b; end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "end": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "step": null, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 23 } }, "range": [ 22, 23 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 23 } }, "range": [ 16, 23 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 31 }, "end": { "line": 1, "column": 32 } }, "range": [ 31, 32 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 32 } }, "range": [ 25, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 37 } }, "range": [ 0, 37 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 37 } }, "range": [ 0, 37 ], "comments": [], "globals": [] } }, { "source": "for a = 1, 2 do 3 end", "result": "[1:16] unexpected number '3' near 'end'" }, { "source": "for a = 1, 2 do \"foo\" end", "result": "[1:16] unexpected string '\"foo\"' near 'end'" }, { "source": "for a = p, q, r do end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "end": { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, "step": { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ], "isLocal": false }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ], "isLocal": false } ] } }, { "source": "for a = 1, 2, 3 do end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "end": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "step": { "type": "NumericLiteral", "value": 3, "raw": "3", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [] } }, { "source": "for a = p, q do break end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "end": { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, "step": null, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 21 } }, "range": [ 16, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false } ] } }, { "source": "for a = p, q do break break end", "result": "[1:22] 'end' expected near 'break'" }, { "source": "for a = 1, 2 do return end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "end": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "step": null, "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 22 } }, "range": [ 16, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "range": [ 0, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "range": [ 0, 26 ], "comments": [], "globals": [] } }, { "source": "for a = 1, 2 do return return end", "result": "[1:23] 'end' expected near 'return'" }, { "source": "for a = p, q do do end end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "end": { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, "step": null, "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 22 } }, "range": [ 16, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "range": [ 0, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "range": [ 0, 26 ], "comments": [], "globals": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false } ] } }, { "source": "for a = p, q do do break end end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "end": { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, "step": null, "body": [ { "type": "DoStatement", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 24 } }, "range": [ 19, 24 ] } ], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 28 } }, "range": [ 16, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ], "comments": [], "globals": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false } ] } }, { "source": "for a = p, q do do return end end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "end": { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, "step": null, "body": [ { "type": "DoStatement", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 25 } }, "range": [ 19, 25 ] } ], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 29 } }, "range": [ 16, 29 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ], "comments": [], "globals": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false } ] } }, { "source": "for a in b do break break end", "result": { "type": "Chunk", "body": [ { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ], "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 19 } }, "range": [ 14, 19 ] }, { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 25 } }, "range": [ 20, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 29 } }, "range": [ 0, 29 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 29 } }, "range": [ 0, 29 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "for a = p, q do break break end", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "end": { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, "step": null, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 21 } }, "range": [ 16, 21 ] }, { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 27 } }, "range": [ 22, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 31 } }, "range": [ 0, 31 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 31 } }, "range": [ 0, 31 ], "comments": [], "globals": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } } ]; })); luaparse-0.3.1/test/spec/functioncalls.js000066400000000000000000006726151405615720100204640ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'functioncalls', function (exports) { 'use strict'; exports.name = 'functioncalls'; exports.spec = [ { "source": "a(", "result": "[1:2] ')' expected near ''" }, { "source": "a()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a(1)", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a(1,)", "result": "[1:4] expected near ')'" }, { "source": "a(1,2,3)", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, { "type": "NumericLiteral", "value": 3, "raw": "3", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "1()", "result": "[1:0] unexpected number '1' near '('" }, { "source": "a()()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a.b()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a[b]()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false } ] } }, { "source": "a.1", "result": "[1:1] '=' expected near '.1'" }, { "source": "a.b", "result": "[1:3] '=' expected near ''" }, { "source": "a[b]", "result": "[1:4] '=' expected near ''" }, { "source": "a.b.(", "result": "[1:4] expected near '('" }, { "source": "a.b.c()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a[b][c]()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "IndexExpression", "base": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] }, "index": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ], "isLocal": false } ] } }, { "source": "a[b].c()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ] }, "base": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false } ] } }, { "source": "a.b[c]()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "IndexExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "index": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false } ] } }, { "source": "a:b()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a:b", "result": "[1:3] function arguments expected near ''" }, { "source": "a:1", "result": "[1:2] expected near '1'" }, { "source": "a.b:c()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a[b]:c()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ] }, "base": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false } ] } }, { "source": "a:b:", "result": "[1:3] function arguments expected near ':'" }, { "source": "a:b():c()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "base": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "(a)()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false } ] } }, { "source": "()()", "result": "[1:1] expected near ')'" }, { "source": "(\"foo\")()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 6 } }, "range": [ 1, 6 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [] } }, { "source": "(a)()()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false } ] } }, { "source": "(a).b()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false } ] } }, { "source": "(a)[b]()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false } ] } }, { "source": "(a):b()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false } ] } }, { "source": "a\"foo\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 6 } }, "range": [ 1, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a\"foo", "result": "[1:7] unfinished string near '\"foo'" }, { "source": "a[[foo]]", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "[[foo]]", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 8 } }, "range": [ 1, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a.b\"foo\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 8 } }, "range": [ 3, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a[b]\"foo\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false } ] } }, { "source": "a:b\"foo\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 8 } }, "range": [ 3, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a()\"foo\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 8 } }, "range": [ 3, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a\"foo\"()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 6 } }, "range": [ 1, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a\"foo\".b()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ] }, "base": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 6 } }, "range": [ 1, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a\"foo\"[b]()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "IndexExpression", "base": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 6 } }, "range": [ 1, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ], "isLocal": false } ] } }, { "source": "a\"foo\":c()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ] }, "base": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 6 } }, "range": [ 1, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a\"foo\"\"bar\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 6 } }, "range": [ 1, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"bar\"", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 11 } }, "range": [ 6, 11 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a\"foo\"{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 6 } }, "range": [ 1, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 8 } }, "range": [ 6, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "(a):b\"foo\".c[d]:e\"bar\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "e", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] }, "base": { "type": "IndexExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "base": { "type": "StringCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 10 } }, "range": [ 5, 10 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] }, "index": { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 15 } }, "range": [ 0, 15 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"bar\"", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 22 } }, "range": [ 17, 22 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": false } ] } }, { "source": "(a):b\"foo\"[c].d:e\"bar\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "e", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ] }, "base": { "type": "IndexExpression", "base": { "type": "StringCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 10 } }, "range": [ 5, 10 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, "index": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 15 } }, "range": [ 0, 15 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"bar\"", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 22 } }, "range": [ 17, 22 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false } ] } }, { "source": "a{}\"foo\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "TableCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 3 } }, "range": [ 1, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 8 } }, "range": [ 3, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 3 } }, "range": [ 1, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a.b{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 5 } }, "range": [ 3, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a[b]{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 6 } }, "range": [ 4, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ], "isLocal": false } ] } }, { "source": "a:b{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 5 } }, "range": [ 3, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a(){}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 5 } }, "range": [ 3, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a{}()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "TableCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 3 } }, "range": [ 1, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a{}.b()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "TableCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 3 } }, "range": [ 1, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a{}[b]()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "IndexExpression", "base": { "type": "TableCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 3 } }, "range": [ 1, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false } ] } }, { "source": "a{}:c()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "TableCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 3 } }, "range": [ 1, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a{}{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "TableCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 3 } }, "range": [ 1, 3 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 5 } }, "range": [ 3, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "(a):b{}.c[d]:e{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "e", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] }, "base": { "type": "IndexExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "base": { "type": "TableCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 7 } }, "range": [ 5, 7 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, "index": { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 16 } }, "range": [ 14, 16 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": false } ] } }, { "source": "(a):b{}[c].d:e{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "e", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "base": { "type": "IndexExpression", "base": { "type": "TableCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 7 } }, "range": [ 5, 7 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, "index": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 16 } }, "range": [ 14, 16 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false } ] } }, { "source": "(a\"\")", "result": "[1:5] unexpected symbol near ''" }, { "source": "(a())", "result": "[1:5] unexpected symbol near ''" }, { "source": "(a{})", "result": "[1:5] unexpected symbol near ''" }, { "source": "a\n()", "result": "[2:3] ambiguous syntax (function call x new statement) near '('" }, { "source": "a\n\"\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"\"", "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 2, 4 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 4 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 4 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 4 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a\n{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 2, 4 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 4 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 4 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 4 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a.b\n()", "result": "[2:3] ambiguous syntax (function call x new statement) near '('" }, { "source": "a.b\n\"\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"\"", "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 4, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a.b\n{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 4, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a:b\n()", "result": "[2:3] ambiguous syntax (function call x new statement) near '('" }, { "source": "a:b\n\"\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"\"", "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 4, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a:b\n{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 4, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "(a\n())", "result": "[2:3] ambiguous syntax (function call x new statement) near '('" }, { "source": "(a\n\"\")", "result": "[2:3] unexpected symbol near ''" }, { "source": "(a\n{})", "result": "[2:3] unexpected symbol near ''" }, { "source": "(a)\n()", "result": "[2:3] ambiguous syntax (function call x new statement) near '('" }, { "source": "(a)\n\"\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"\"", "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 4, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false } ] } }, { "source": "(a)\n{}", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "TableCallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "arguments": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 4, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false } ] } }, { "source": "a\n()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 4 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 4 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 4 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a.b\n()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a:b\n()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 3 } }, "range": [ 2, 3 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } }, "range": [ 0, 3 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "(a\n())", "result": "[2:3] unexpected symbol near ''", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "(a)\n()", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 1 }, "end": { "line": 1, "column": 2 } }, "range": [ 1, 2 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } } ]; })); luaparse-0.3.1/test/spec/functions.js000066400000000000000000001615301405615720100176150ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'functions', function (exports) { 'use strict'; exports.name = 'functions'; exports.spec = [ { "source": "function", "result": "[1:8] expected near ''" }, { "source": "function 1", "result": "[1:9] expected near '1'" }, { "source": "function end", "result": "[1:9] expected near 'end'" }, { "source": "function a", "result": "[1:10] '(' expected near ''" }, { "source": "function a end", "result": "[1:11] '(' expected near 'end'" }, { "source": "function a( end", "result": "[1:12] or '...' expected near 'end'" }, { "source": "function a() end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a(1", "result": "[1:11] or '...' expected near '1'" }, { "source": "function a(\"foo\"", "result": "[1:11] or '...' expected near '\"foo\"'" }, { "source": "function a(p", "result": "[1:12] ')' expected near ''" }, { "source": "function a(p,)", "result": "[1:13] or '...' expected near ')'" }, { "source": "function a(p q", "result": "[1:13] ')' expected near 'q'" }, { "source": "function a(p) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a(p,q) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": true }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a(p q) end", "result": "[1:13] ')' expected near 'q'" }, { "source": "function a(p,q,) end", "result": "[1:15] or '...' expected near ')'" }, { "source": "function a(p,q,r) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": true }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a(p,q,1", "result": "[1:15] or '...' expected near '1'" }, { "source": "function a(p) do", "result": "[1:16] 'end' expected near ''" }, { "source": "function a(p) 1 end", "result": "[1:14] unexpected number '1' near 'end'" }, { "source": "function a(p) return end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": true } ], "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 20 } }, "range": [ 14, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a(p) return return end", "result": "[1:21] 'end' expected near 'return'" }, { "source": "function a(p) do end end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": true } ], "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 20 } }, "range": [ 14, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a.(", "result": "[1:11] expected near '('" }, { "source": "function a.1", "result": "[1:10] '(' expected near '.1'" }, { "source": "function a.b() end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 12 } }, "range": [ 9, 12 ] }, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a.b,", "result": "[1:12] '(' expected near ','" }, { "source": "function a.b.(", "result": "[1:13] expected near '('" }, { "source": "function a.b.c.d() end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ] }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 12 } }, "range": [ 9, 12 ] }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 14 } }, "range": [ 9, 14 ] }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 16 } }, "range": [ 9, 16 ] }, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a:", "result": "[1:11] expected near ''" }, { "source": "function a:1", "result": "[1:11] expected near '1'" }, { "source": "function a:b() end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 12 } }, "range": [ 9, 12 ] }, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a:b:", "result": "[1:12] '(' expected near ':'" }, { "source": "function a:b.", "result": "[1:12] '(' expected near '.'" }, { "source": "function a.b.c:d() end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ] }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 12 } }, "range": [ 9, 12 ] }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 14 } }, "range": [ 9, 14 ] }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 16 } }, "range": [ 9, 16 ] }, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a(...) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [ { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 14 } }, "range": [ 11, 14 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a(...,", "result": "[1:14] ')' expected near ','" }, { "source": "function a(p,...) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": true }, { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 16 } }, "range": [ 13, 16 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a(...,p) end", "result": "[1:14] ')' expected near ','" }, { "source": "function a(p,q,r,...) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": true }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 20 } }, "range": [ 17, 20 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a() local a local b end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [], "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 20 } }, "range": [ 13, 20 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 28 } }, "range": [ 27, 28 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 28 } }, "range": [ 21, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a() local a; local b; end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [], "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 20 } }, "range": [ 13, 20 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 29 } }, "range": [ 28, 29 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 29 } }, "range": [ 22, 29 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 34 } }, "range": [ 0, 34 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 34 } }, "range": [ 0, 34 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a() end; function a() end;", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] }, { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 28 } }, "range": [ 27, 28 ], "isLocal": false }, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 34 } }, "range": [ 18, 34 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 35 } }, "range": [ 0, 35 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "return ...", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [ { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 10 } }, "range": [ 7, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [] } }, { "source": "function a(...) return ... end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "isLocal": false, "parameters": [ { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 14 } }, "range": [ 11, 14 ] } ], "body": [ { "type": "ReturnStatement", "arguments": [ { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 23 }, "end": { "line": 1, "column": 26 } }, "range": [ 23, 26 ] } ], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 26 } }, "range": [ 16, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "function a() return ... end", "result": "[1:20] cannot use '...' outside a vararg function near '...'" }, { "source": "function a(...) function b() return ... end end", "result": "[1:36] cannot use '...' outside a vararg function near '...'" } ]; })); luaparse-0.3.1/test/spec/labels.js000066400000000000000000001245241405615720100170510ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'labels', function (exports) { 'use strict'; exports.name = 'labels'; exports.spec = [ { "source": "goto \"foo\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "goto", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 10 } }, "range": [ 5, 10 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "goto", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ], "isLocal": false } ] } }, { "source": "::foo::", "result": "[1:0] unexpected symbol ':' near ':'" }, { "source": "goto foo", "result": "[1:5] '=' expected near 'foo'" }, { "source": "::foo", "result": "[1:5] '::' expected near ''", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "::foo::", "result": { "type": "Chunk", "body": [ { "type": "LabelStatement", "label": { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 5 } }, "range": [ 2, 5 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "::break::", "result": "[1:2] expected near 'break'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "goto \"foo\"", "result": "[1:5] expected near '\"foo\"'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "goto hasOwnProperty", "result": "[1:0] no visible label 'hasOwnProperty' for ", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "goto x ::x::", "result": { "type": "Chunk", "body": [ { "type": "GotoStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] }, { "type": "LabelStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 12 } }, "range": [ 7, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "goto x do ::x:: end", "result": "[1:0] no visible label 'x' for ", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "do ::l1:: end goto l1", "result": "[1:14] no visible label 'l1' for ", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "::x:: ::x::", "result": "[1:8] label 'x' already defined on line 1", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "goto x local a ::x:: f()", "result": "[1:0] jumps into the scope of local 'a'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "goto x local a, b ::x:: f()", "result": "[1:0] jumps into the scope of local 'a'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "goto x local function a() end ::x:: f()", "result": "[1:0] jumps into the scope of local 'a'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "do goto x local a end ::x:: f()", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "GotoStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 9 } }, "range": [ 3, 9 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 17 } }, "range": [ 10, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] }, { "type": "LabelStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 25 } }, "range": [ 24, 25 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 27 } }, "range": [ 22, 27 ] }, { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "Identifier", "name": "f", "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 29 } }, "range": [ 28, 29 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 31 } }, "range": [ 28, 31 ] }, "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 31 } }, "range": [ 28, 31 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 31 } }, "range": [ 0, 31 ], "comments": [], "globals": [ { "type": "Identifier", "name": "f", "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 29 } }, "range": [ 28, 29 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "do local a goto x end local b ::x:: f()", "result": "[1:11] jumps into the scope of local 'b'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "do goto x local a ::x:: end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "GotoStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 9 } }, "range": [ 3, 9 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 17 } }, "range": [ 10, 17 ] }, { "type": "LabelStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 23 } }, "range": [ 18, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "while 0 do goto x local a ::x:: end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "GotoStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] }, "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 17 } }, "range": [ 11, 17 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 25 } }, "range": [ 24, 25 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 25 } }, "range": [ 18, 25 ] }, { "type": "LabelStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 29 } }, "range": [ 28, 29 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 31 } }, "range": [ 26, 31 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 35 } }, "range": [ 0, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 35 } }, "range": [ 0, 35 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "repeat goto x local a ::x:: until 0", "result": "[1:7] jumps into the scope of local 'a'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "do goto x local a ::x:: ::y:: ::z:: end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "GotoStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 9 } }, "range": [ 3, 9 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 17 } }, "range": [ 10, 17 ] }, { "type": "LabelStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 23 } }, "range": [ 18, 23 ] }, { "type": "LabelStatement", "label": { "type": "Identifier", "name": "y", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 27 } }, "range": [ 26, 27 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 29 } }, "range": [ 24, 29 ] }, { "type": "LabelStatement", "label": { "type": "Identifier", "name": "z", "loc": { "start": { "line": 1, "column": 32 }, "end": { "line": 1, "column": 33 } }, "range": [ 32, 33 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 30 }, "end": { "line": 1, "column": 35 } }, "range": [ 30, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 39 } }, "range": [ 0, 39 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 39 } }, "range": [ 0, 39 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "do do ::x:: end do goto x end end", "result": "[1:19] no visible label 'x' for ", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "do do goto x end do ::x:: end end", "result": "[1:6] no visible label 'x' for ", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "do do goto x end do end ::x:: end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "DoStatement", "body": [ { "type": "GotoStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 12 } }, "range": [ 6, 12 ] } ], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 16 } }, "range": [ 3, 16 ] }, { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 23 } }, "range": [ 17, 23 ] }, { "type": "LabelStatement", "label": { "type": "Identifier", "name": "x", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 27 } }, "range": [ 26, 27 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 29 } }, "range": [ 24, 29 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "::foo::", "result": { "type": "Chunk", "body": [ { "type": "LabelStatement", "label": { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 5 } }, "range": [ 2, 5 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "goto \"foo\"", "result": { "type": "Chunk", "body": [ { "type": "CallStatement", "expression": { "type": "StringCallExpression", "base": { "type": "Identifier", "name": "goto", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ], "isLocal": false }, "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 10 } }, "range": [ 5, 10 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "goto", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 4 } }, "range": [ 0, 4 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "goto foo", "result": "[1:0] no visible label 'foo' for ", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "::foo:: goto foo", "result": { "type": "Chunk", "body": [ { "type": "LabelStatement", "label": { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 5 } }, "range": [ 2, 5 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, { "type": "GotoStatement", "label": { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 16 } }, "range": [ 13, 16 ] }, "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 16 } }, "range": [ 8, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "goto goto", "result": "[1:5] '=' expected near 'goto'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "::goto:: -- sic!", "result": { "type": "Chunk", "body": [ { "type": "LabelStatement", "label": { "type": "Identifier", "name": "goto", "loc": { "start": { "line": 1, "column": 2 }, "end": { "line": 1, "column": 6 } }, "range": [ 2, 6 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [ { "type": "Comment", "value": " sic!", "raw": "-- sic!", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 16 } }, "range": [ 9, 16 ] } ], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } } ]; })); luaparse-0.3.1/test/spec/literals.js000066400000000000000000004033331405615720100174240ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'literals', function (exports) { 'use strict'; exports.name = 'literals'; exports.spec = [ { "source": "a", "result": "[1:1] '=' expected near ''" }, { "source": "a = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = .1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 0.1, "raw": ".1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 6 } }, "range": [ 4, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1.1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1.1, "raw": "1.1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 10.1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 10.1, "raw": "10.1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1e", "result": "[1:7] malformed number near '1e'" }, { "source": "a = 1e1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 10, "raw": "1e1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1E1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 10, "raw": "1E1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1e+9", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1000000000, "raw": "1e+9", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1e-1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 0.1, "raw": "1e-1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 0x", "result": "[1:7] malformed number near '0x'" }, { "source": "a = 0xf", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 15, "raw": "0xf", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 0xf.", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 15, "raw": "0xf.", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 0xf.3", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 15.1875, "raw": "0xf.3", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 0xfp", "result": "[1:9] malformed number near '0xfp'" }, { "source": "a = 0xfp1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 30, "raw": "0xfp1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 0xfp+1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 30, "raw": "0xfp+1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 0xfp-1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 7.5, "raw": "0xfp-1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 0xFP+9", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 7680, "raw": "0xFP+9", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1 .. 3 .. -2", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "..", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "right": { "type": "BinaryExpression", "operator": "..", "left": { "type": "NumericLiteral", "value": 3, "raw": "3", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] }, "right": { "type": "UnaryExpression", "operator": "-", "argument": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ] }, "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 16 } }, "range": [ 14, 16 ] }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 16 } }, "range": [ 9, 16 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 16 } }, "range": [ 4, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1 .. \"bar\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "..", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "right": { "type": "StringLiteral", "value": null, "raw": "\"bar\"", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 14 } }, "range": [ 9, 14 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 14 } }, "range": [ 4, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"", "result": "[1:7] unfinished string near '\"'" }, { "source": "a = \"'", "result": "[1:8] unfinished string near '\"''" }, { "source": "a = '\"", "result": "[1:8] unfinished string near ''\"'" }, { "source": "a = \"\n\"", "result": "[1:7] unfinished string near '\"'" }, { "source": "a = '", "result": "[1:7] unfinished string near '''" }, { "source": "a = '\n'", "result": "[1:7] unfinished string near '''" }, { "source": "a = [[", "result": "[1:7] unfinished long string (starting at line 1) near ''" }, { "source": "a = [[\n]]", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "[[\n]]", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 2, "column": 2 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 2 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"bar", "result": "[1:10] unfinished string near '\"bar'" }, { "source": "a = 'bar'", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "'bar'", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"bar\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"bar\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = [=aa", "result": "[1:2] '[' expected near '='" }, { "source": "a = nil", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NilLiteral", "value": null, "raw": "nil", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = true", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = false", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BooleanLiteral", "value": false, "raw": "false", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = ...", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = [[hello\nworld]]", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "[[hello\nworld]]", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 2, "column": 7 } }, "range": [ 4, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 7 } }, "range": [ 0, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 7 } }, "range": [ 0, 19 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { 1, 2, [[hello\n\nworld]], \n 3 }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, { "type": "TableValue", "value": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] }, { "type": "TableValue", "value": { "type": "StringLiteral", "value": null, "raw": "[[hello\n\nworld]]", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 3, "column": 7 } }, "range": [ 12, 28 ] }, "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 3, "column": 7 } }, "range": [ 12, 28 ] }, { "type": "TableValue", "value": { "type": "NumericLiteral", "value": 3, "raw": "3", "loc": { "start": { "line": 4, "column": 1 }, "end": { "line": 4, "column": 2 } }, "range": [ 32, 33 ] }, "loc": { "start": { "line": 4, "column": 1 }, "end": { "line": 4, "column": 2 } }, "range": [ 32, 33 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 4, "column": 4 } }, "range": [ 4, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 4, "column": 4 } }, "range": [ 0, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 4, "column": 4 } }, "range": [ 0, 35 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"\\\r\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"\\\r\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 2, "column": 1 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 1 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 1 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"\\\n\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"\\\n\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 2, "column": 1 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 1 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 1 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"\\\r\n\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"\\\r\n\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 2, "column": 1 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 1 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 1 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"\\\n\r\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"\\\n\r\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 2, "column": 1 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 1 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 2, "column": 1 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"\\u\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"\\u\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"\\?\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "StringLiteral", "value": null, "raw": "\"\\?\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = [=[]", "result": "[1:9] unfinished long string (starting at line 1) near ''" }, { "source": "a = [=[x]", "result": "[1:10] unfinished long string (starting at line 1) near ''" }, { "source": "a = [=[x]x", "result": "[1:11] unfinished long string (starting at line 1) near ''" }, { "source": "a = \"\\u\"", "result": "[1:7] invalid escape sequence near '\\u'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = \"\\?\"", "result": "[1:7] invalid escape sequence near '\\?'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = 1", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 5 } }, "range": [ 0, 5 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1L", "result": "[1:7] malformed number near '1L'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1LL", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1LL", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1L", "result": "[1:9] malformed number near '1.1L'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1LL", "result": "[1:10] malformed number near '1.1LL'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1l", "result": "[1:7] malformed number near '1l'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1ll", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1ll", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1l", "result": "[1:9] malformed number near '1.1l'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1ll", "result": "[1:10] malformed number near '1.1ll'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1U", "result": "[1:7] malformed number near '1U'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1UL", "result": "[1:8] malformed number near '1UL'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1ULL", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1ULL", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1U", "result": "[1:9] malformed number near '1.1U'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1UL", "result": "[1:10] malformed number near '1.1UL'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1ULL", "result": "[1:11] malformed number near '1.1ULL'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1u", "result": "[1:7] malformed number near '1u'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1ul", "result": "[1:8] malformed number near '1ul'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1ull", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1ull", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1u", "result": "[1:9] malformed number near '1.1u'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1ul", "result": "[1:10] malformed number near '1.1ul'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1ull", "result": "[1:11] malformed number near '1.1ull'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1i", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 6 } }, "range": [ 4, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1i", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1.1, "raw": "1.1i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1I", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1I", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 6 } }, "range": [ 4, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1I", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 1.1, "raw": "1.1I", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1e1i", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 10, "raw": "1e1i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1e1i", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 11, "raw": "1.1e1i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1e1I", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 10, "raw": "1e1I", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 1.1e1I", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 11, "raw": "1.1e1I", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 0xfi", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 15, "raw": "0xfi", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 0xf.i", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 15, "raw": "0xf.i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 0xf.3i", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 15.1875, "raw": "0xf.3i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 0xfp1i", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 30, "raw": "0xfp1i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 0xf.p1i", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 30, "raw": "0xf.p1i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 11 } }, "range": [ 4, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } }, { "source": "a = 0xf.3p+1i", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 30.375, "raw": "0xf.3p+1i", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 13 } }, "range": [ 4, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "LuaJIT" } } ]; })); luaparse-0.3.1/test/spec/local.js000066400000000000000000002014321405615720100166730ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'local', function (exports) { 'use strict'; exports.name = 'local'; exports.spec = [ { "source": "local", "result": "[1:5] expected near ''" }, { "source": "local;", "result": "[1:5] expected near ';'" }, { "source": "local =", "result": "[1:6] expected near '='" }, { "source": "local end", "result": "[1:6] expected near 'end'" }, { "source": "local a", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [] } }, { "source": "local a;", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [] } }, { "source": "local a, b, c", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ], "comments": [], "globals": [] } }, { "source": "local a; local b local c;", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 16 } }, "range": [ 9, 16 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 23 }, "end": { "line": 1, "column": 24 } }, "range": [ 23, 24 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 24 } }, "range": [ 17, 24 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [] } }, { "source": "local a = 1", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [] } }, { "source": "local a local b = a", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ], "isLocal": true } ], "init": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 19 } }, "range": [ 18, 19 ], "isLocal": true } ], "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 19 } }, "range": [ 8, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ], "comments": [], "globals": [] } }, { "source": "local a, b = 1, 2", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] }, { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [] } }, { "source": "local a, b, c = 1, 2, 3", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] }, { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ] }, { "type": "NumericLiteral", "value": 3, "raw": "3", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 23 } }, "range": [ 22, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ], "comments": [], "globals": [] } }, { "source": "local a, b, c = 1", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [] } }, { "source": "local a = 1, 2, 3", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ] }, { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] }, { "type": "NumericLiteral", "value": 3, "raw": "3", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [] } }, { "source": "local a, local", "result": "[1:9] expected near 'local'" }, { "source": "local 1", "result": "[1:6] expected near '1'" }, { "source": "local \"foo\"", "result": "[1:6] expected near '\"foo\"'" }, { "source": "local a = local", "result": "[1:10] expected near 'local'" }, { "source": "local a, b, =", "result": "[1:12] expected near '='" }, { "source": "local a, b = 1, local", "result": "[1:16] expected near 'local'" }, { "source": "local a, b = , local", "result": "[1:13] expected near ','" }, { "source": "local function", "result": "[1:14] expected near ''" }, { "source": "local function 1", "result": "[1:15] expected near '1'" }, { "source": "local function end", "result": "[1:15] expected near 'end'" }, { "source": "local function a", "result": "[1:16] '(' expected near ''" }, { "source": "local function a end", "result": "[1:17] '(' expected near 'end'" }, { "source": "local function a( end", "result": "[1:18] or '...' expected near 'end'" }, { "source": "local function a() end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [] } }, { "source": "local function a(1", "result": "[1:17] or '...' expected near '1'" }, { "source": "local function a(\"foo\"", "result": "[1:17] or '...' expected near '\"foo\"'" }, { "source": "local function a(p", "result": "[1:18] ')' expected near ''" }, { "source": "local function a(p,)", "result": "[1:19] or '...' expected near ')'" }, { "source": "local function a(p q", "result": "[1:19] ')' expected near 'q'" }, { "source": "local function a(p) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ], "comments": [], "globals": [] } }, { "source": "local function a(p,q) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [] } }, { "source": "local function a(p q) end", "result": "[1:19] ')' expected near 'q'" }, { "source": "local function a(p,q,) end", "result": "[1:21] or '...' expected near ')'" }, { "source": "local function a(p,q,r) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ], "isLocal": true }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 22 } }, "range": [ 21, 22 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] } }, { "source": "local function a(p,q,1", "result": "[1:21] or '...' expected near '1'" }, { "source": "local function a(p) do", "result": "[1:22] 'end' expected near ''" }, { "source": "local function a(p) 1 end", "result": "[1:20] unexpected number '1' near 'end'" }, { "source": "local function a(p) return end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true } ], "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 26 } }, "range": [ 20, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ], "comments": [], "globals": [] } }, { "source": "local function a(p) return return end", "result": "[1:27] 'end' expected near 'return'" }, { "source": "local function a(p) do end end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true } ], "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 26 } }, "range": [ 20, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ], "comments": [], "globals": [] } }, { "source": "local function a.", "result": "[1:16] '(' expected near '.'" }, { "source": "local function a:", "result": "[1:16] '(' expected near ':'" }, { "source": "local function a(...) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [ { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 20 } }, "range": [ 17, 20 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [] } }, { "source": "local function a(...,", "result": "[1:20] ')' expected near ','" }, { "source": "local function a(p,...) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true }, { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 22 } }, "range": [ 19, 22 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] } }, { "source": "local function a(p,q,r,...) end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [ { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ], "isLocal": true }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 22 } }, "range": [ 21, 22 ], "isLocal": true }, { "type": "VarargLiteral", "value": "...", "raw": "...", "loc": { "start": { "line": 1, "column": 23 }, "end": { "line": 1, "column": 26 } }, "range": [ 23, 26 ] } ], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 31 } }, "range": [ 0, 31 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 31 } }, "range": [ 0, 31 ], "comments": [], "globals": [] } }, { "source": "local function a() local a local b end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [], "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 26 } }, "range": [ 25, 26 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 26 } }, "range": [ 19, 26 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 33 }, "end": { "line": 1, "column": 34 } }, "range": [ 33, 34 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 34 } }, "range": [ 27, 34 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 38 } }, "range": [ 0, 38 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 38 } }, "range": [ 0, 38 ], "comments": [], "globals": [] } }, { "source": "local function a() local a; local b; end", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [], "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 26 } }, "range": [ 25, 26 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 26 } }, "range": [ 19, 26 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 34 }, "end": { "line": 1, "column": 35 } }, "range": [ 34, 35 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 35 } }, "range": [ 28, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 40 } }, "range": [ 0, 40 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 40 } }, "range": [ 0, 40 ], "comments": [], "globals": [] } }, { "source": "local function a() end; local function a() end;", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, "isLocal": true, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] }, { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 39 }, "end": { "line": 1, "column": 40 } }, "range": [ 39, 40 ], "isLocal": true }, "isLocal": true, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 46 } }, "range": [ 24, 46 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 47 } }, "range": [ 0, 47 ], "comments": [], "globals": [] } }, { "source": "local a = { b = { z = 1 } }", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableKeyString", "key": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ] }, "value": { "type": "TableConstructorExpression", "fields": [ { "type": "TableKeyString", "key": { "type": "Identifier", "name": "z", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 19 } }, "range": [ 18, 19 ] }, "value": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 23 } }, "range": [ 22, 23 ] }, "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 23 } }, "range": [ 18, 23 ] } ], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 25 } }, "range": [ 16, 25 ] }, "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 25 } }, "range": [ 12, 25 ] } ], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 27 } }, "range": [ 10, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] } }, { "source": "local Дождь = {}", "result": "[1:7] unexpected symbol 'Д' near 'local'" }, { "source": "local Дождь = {}", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "Дождь", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 11 } }, "range": [ 6, 11 ], "isLocal": true } ], "init": [ { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 16 } }, "range": [ 14, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "extendedIdentifiers": true } } ]; })); luaparse-0.3.1/test/spec/misc.js000066400000000000000000000237171405615720100165440ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports // While CommonJS defines `module` as an object, component define it as a // function , freeModule = (typeof module === 'object' || typeof module === 'function') && module && module.exports === freeExports && module; // Detect free variable `global`, from Node.js or Browserified code, and use // it as `root` var freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; // Some AMD build optimizers, like r.js, check for specific condition // patterns like the following: if (typeof define === 'function' && define.amd) { define(['exports'], factory); } // check for `exports` after `define` in case a build optimizer adds an // `exports` object else if (freeExports && !freeExports.nodeType) { // in Node.js or RingoJS v0.8.0+ if (freeModule) factory(freeModule.exports); // in RingoJS v0.7.0- else factory(freeExports); } // in a browser or Rhino else { factory((root[name] = {})); } }(this, 'misc', function (exports) { exports.name = 'misc'; exports.options = { }; exports.spec = { 'function foo.bar:baz(a) goto foo end local function a() local a, b ::c:: for a,b in c.d:e() do end end do while a do end repeat until 0 end for a = 1, 1 do end a = function() end': { options: { "luaVersion": "5.2" }, name: 'should not scope by default', result: { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "baz" }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "bar" }, "base": { "type": "Identifier", "name": "foo" } } }, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "a" } ], "body": [ { "type": "GotoStatement", "label": { "type": "Identifier", "name": "foo" } } ] }, { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "a" }, "isLocal": true, "parameters": [], "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a" }, { "type": "Identifier", "name": "b" } ], "init": [] }, { "type": "LabelStatement", "label": { "type": "Identifier", "name": "c" } }, { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "a" }, { "type": "Identifier", "name": "b" } ], "iterators": [ { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "e" }, "base": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "d" }, "base": { "type": "Identifier", "name": "c" } } }, "arguments": [] } ], "body": [] } ] }, { "type": "DoStatement", "body": [ { "type": "WhileStatement", "condition": { "type": "Identifier", "name": "a" }, "body": [] }, { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0" }, "body": [] } ] }, { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a" }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1" }, "end": { "type": "NumericLiteral", "value": 1, "raw": "1" }, "step": null, "body": [] }, { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a" } ], "init": [ { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [], "body": [] } ] } ], "comments": [] } }, '--comment\nif 1 then elseif 2 then else end': { options: { }, name: 'should not track locations or ranges by default', result: { "type": "Chunk", "body": [ { "type": "IfStatement", "clauses": [ { "type": "IfClause", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1" }, "body": [] }, { "type": "ElseifClause", "condition": { "type": "NumericLiteral", "value": 2, "raw": "2" }, "body": [] }, { "type": "ElseClause", "body": [] } ] } ], "comments": [ { "type": "Comment", "value": "comment", "raw": "--comment" } ] } }, 'foo = 1': { options: { locations: true }, name: 'should be able to track only locations', result: { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 3 } } } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } } } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } } } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "comments": [] } }, 'foo = 2': { options: { ranges: true }, name: 'should be able to track only ranges', result: { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "foo", "range": [ 0, 3 ] } ], "init": [ { "type": "NumericLiteral", "value": 2, "raw": "2", "range": [ 6, 7 ] } ], "range": [ 0, 7 ] } ], "range": [ 0, 7 ], "comments": [] } }, '': { name: 'should produce empty tree on empty input', options: {}, result: { "type": "Chunk", "body": [], "comments": [] } }, '--comment': { name: 'should ignore comments if told to', options: { comments: false }, result: { "type": "Chunk", "body": [] } } }; })); luaparse-0.3.1/test/spec/operators.js000066400000000000000000003227761405615720100176360ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'operators', function (exports) { 'use strict'; exports.name = 'operators'; exports.spec = [ { "source": "a = -\"foo\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "UnaryExpression", "operator": "-", "argument": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 10 } }, "range": [ 5, 10 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = -", "result": "[1:5] expected near ''" }, { "source": "a = not 10", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "UnaryExpression", "operator": "not", "argument": { "type": "NumericLiteral", "value": 10, "raw": "10", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 10 } }, "range": [ 8, 10 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = not", "result": "[1:7] expected near ''" }, { "source": "a = 1 +", "result": "[1:7] expected near ''" }, { "source": "a = 1 ..", "result": "[1:8] expected near ''" }, { "source": "a = 1 * /", "result": "[1:8] expected near '/'" }, { "source": "a = 1 + -2; a = 1 - -2", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "+", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "right": { "type": "UnaryExpression", "operator": "-", "argument": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] }, "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 10 } }, "range": [ 8, 10 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "-", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] }, "right": { "type": "UnaryExpression", "operator": "-", "argument": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 22 } }, "range": [ 21, 22 ] }, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 22 } }, "range": [ 20, 22 ] }, "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 22 } }, "range": [ 16, 22 ] } ], "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 22 } }, "range": [ 12, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1 * -", "result": "[1:9] expected near ''" }, { "source": "a = 1 * not 2; a = 1 / not 2", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "*", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "right": { "type": "UnaryExpression", "operator": "not", "argument": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ] }, "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 13 } }, "range": [ 8, 13 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 13 } }, "range": [ 4, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] }, { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "/", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ] }, "right": { "type": "UnaryExpression", "operator": "not", "argument": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 28 } }, "range": [ 27, 28 ] }, "loc": { "start": { "line": 1, "column": 23 }, "end": { "line": 1, "column": 28 } }, "range": [ 23, 28 ] }, "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 28 } }, "range": [ 19, 28 ] } ], "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 28 } }, "range": [ 15, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1 / not", "result": "[1:11] expected near ''" }, { "source": "a = 1 + 2 - 3 * 4 / 5 ^ 6", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "-", "left": { "type": "BinaryExpression", "operator": "+", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] }, "right": { "type": "BinaryExpression", "operator": "/", "left": { "type": "BinaryExpression", "operator": "*", "left": { "type": "NumericLiteral", "value": 3, "raw": "3", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ] }, "right": { "type": "NumericLiteral", "value": 4, "raw": "4", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] }, "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 17 } }, "range": [ 12, 17 ] }, "right": { "type": "BinaryExpression", "operator": "^", "left": { "type": "NumericLiteral", "value": 5, "raw": "5", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ] }, "right": { "type": "NumericLiteral", "value": 6, "raw": "6", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 25 } }, "range": [ 24, 25 ] }, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 25 } }, "range": [ 20, 25 ] }, "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 25 } }, "range": [ 12, 25 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 25 } }, "range": [ 4, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = ((1", "result": "[1:7] ')' expected near ''" }, { "source": "a = ((1 + 2)", "result": "[1:12] ')' expected near ''" }, { "source": "a = 1)", "result": "[1:5] unexpected symbol ')' near ''" }, { "source": "a = a + b - c", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "-", "left": { "type": "BinaryExpression", "operator": "+", "left": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "right": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] }, "right": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 13 } }, "range": [ 4, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": false } ] } }, { "source": "a = \"foo\" + \"bar\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "+", "left": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] }, "right": { "type": "StringLiteral", "value": null, "raw": "\"bar\"", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 17 } }, "range": [ 12, 17 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 17 } }, "range": [ 4, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = \"foo\"..\"bar\"..\"baz\"", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "..", "left": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] }, "right": { "type": "BinaryExpression", "operator": "..", "left": { "type": "StringLiteral", "value": null, "raw": "\"bar\"", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 16 } }, "range": [ 11, 16 ] }, "right": { "type": "StringLiteral", "value": null, "raw": "\"baz\"", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 23 } }, "range": [ 18, 23 ] }, "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 23 } }, "range": [ 11, 23 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 23 } }, "range": [ 4, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 23 } }, "range": [ 0, 23 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = true + false - nil", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "-", "left": { "type": "BinaryExpression", "operator": "+", "left": { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 8 } }, "range": [ 4, 8 ] }, "right": { "type": "BooleanLiteral", "value": false, "raw": "false", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 16 } }, "range": [ 11, 16 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 16 } }, "range": [ 4, 16 ] }, "right": { "type": "NilLiteral", "value": null, "raw": "nil", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 22 } }, "range": [ 19, 22 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 22 } }, "range": [ 4, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = {} * {}", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "*", "left": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 6 } }, "range": [ 4, 6 ] }, "right": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 11 } }, "range": [ 9, 11 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 11 } }, "range": [ 4, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = function() end / function() end", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "/", "left": { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 18 } }, "range": [ 4, 18 ] }, "right": { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 35 } }, "range": [ 21, 35 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 35 } }, "range": [ 4, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 35 } }, "range": [ 0, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 35 } }, "range": [ 0, 35 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = a() ^ b()", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "^", "left": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] }, "right": { "type": "CallExpression", "base": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": false }, "arguments": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 13 } }, "range": [ 10, 13 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 13 } }, "range": [ 4, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": false } ] } }, { "source": "a = 1 == 2; a = 1 ~= 2", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "==", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "~=", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 22 } }, "range": [ 21, 22 ] }, "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 22 } }, "range": [ 16, 22 ] } ], "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 22 } }, "range": [ 12, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1 < 2 <= 2 > 2 >= 2 == 2", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "==", "left": { "type": "BinaryExpression", "operator": ">=", "left": { "type": "BinaryExpression", "operator": ">", "left": { "type": "BinaryExpression", "operator": "<=", "left": { "type": "BinaryExpression", "operator": "<", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 14 } }, "range": [ 4, 14 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 18 } }, "range": [ 4, 18 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 23 } }, "range": [ 22, 23 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 23 } }, "range": [ 4, 23 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 28 } }, "range": [ 27, 28 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 28 } }, "range": [ 4, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1 ==", "result": "[1:8] expected near ''" }, { "source": "a = `", "result": "[1:5] unexpected symbol '`' near '='" }, { "source": "a = ~", "result": "[1:5] unexpected symbol '~' near '='" }, { "source": "a = ~= 2", "result": "[1:4] expected near '~='" }, { "source": "a = a ~= b", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "~=", "left": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "right": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false } ] } }, { "source": "a = 1 and 2 or 2", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "LogicalExpression", "operator": "or", "left": { "type": "LogicalExpression", "operator": "and", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 11 } }, "range": [ 4, 11 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 16 } }, "range": [ 4, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1 and", "result": "[1:9] expected near ''" }, { "source": "a = or 1", "result": "[1:4] expected near 'or'" }, { "source": "a = {} and {} or {}", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "LogicalExpression", "operator": "or", "left": { "type": "LogicalExpression", "operator": "and", "left": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 6 } }, "range": [ 4, 6 ] }, "right": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 13 } }, "range": [ 11, 13 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 13 } }, "range": [ 4, 13 ] }, "right": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 19 } }, "range": [ 17, 19 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 19 } }, "range": [ 4, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = (1) and (\"foo\") or (nil)", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "LogicalExpression", "operator": "or", "left": { "type": "LogicalExpression", "operator": "and", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 6 } }, "range": [ 5, 6 ] }, "right": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 18 } }, "range": [ 13, 18 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 19 } }, "range": [ 4, 19 ] }, "right": { "type": "NilLiteral", "value": null, "raw": "nil", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 27 } }, "range": [ 24, 27 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 28 } }, "range": [ 4, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = 1 // 0", "result": "[1:7] expected near '/'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = p ~ q", "result": "[1:7] unexpected symbol '~' near 'p'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = p & q", "result": "[1:7] unexpected symbol '&' near 'p'", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "a = 1 // 0", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "//", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ] }, "right": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = p ~ q >> r | s", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "|", "left": { "type": "BinaryExpression", "operator": "~", "left": { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, "right": { "type": "BinaryExpression", "operator": ">>", "left": { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, "right": { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 14 } }, "range": [ 8, 14 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 14 } }, "range": [ 4, 14 ] }, "right": { "type": "Identifier", "name": "s", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 18 } }, "range": [ 4, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ], "isLocal": false }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": false }, { "type": "Identifier", "name": "s", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = ~ p ~ q / r", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "BinaryExpression", "operator": "~", "left": { "type": "UnaryExpression", "operator": "~", "argument": { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 7 } }, "range": [ 4, 7 ] }, "right": { "type": "BinaryExpression", "operator": "/", "left": { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": false }, "right": { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 15 } }, "range": [ 10, 15 ] }, "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 15 } }, "range": [ 4, 15 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 15 } }, "range": [ 0, 15 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 15 } }, "range": [ 0, 15 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "p", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": false }, { "type": "Identifier", "name": "q", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": false }, { "type": "Identifier", "name": "r", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ], "isLocal": false } ] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = a <=", "result": "[1:8] expected near ''", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } }, { "source": "a = a >=", "result": "[1:8] expected near ''", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.3" } } ]; })); luaparse-0.3.1/test/spec/repeat.js000066400000000000000000000650561405615720100170730ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'repeat', function (exports) { 'use strict'; exports.name = 'repeat'; exports.spec = [ { "source": "repeat", "result": "[1:6] 'until' expected near ''" }, { "source": "repeat until", "result": "[1:12] expected near ''" }, { "source": "repeat until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ], "comments": [], "globals": [] } }, { "source": "repeat until false", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "BooleanLiteral", "value": false, "raw": "false", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 18 } }, "range": [ 13, 18 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 18 } }, "range": [ 0, 18 ], "comments": [], "globals": [] } }, { "source": "repeat until local", "result": "[1:13] expected near 'local'" }, { "source": "repeat end", "result": "[1:7] 'until' expected near 'end'" }, { "source": "repeat 1", "result": "[1:7] unexpected number '1' near ''" }, { "source": "repeat =", "result": "[1:7] unexpected symbol '=' near ''" }, { "source": "repeat local a until 1", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 22 } }, "range": [ 21, 22 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 14 } }, "range": [ 7, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [] } }, { "source": "repeat local a local b until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 29 }, "end": { "line": 1, "column": 30 } }, "range": [ 29, 30 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 14 } }, "range": [ 7, 14 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 22 } }, "range": [ 21, 22 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 22 } }, "range": [ 15, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ], "comments": [], "globals": [] } }, { "source": "repeat local a; local b; until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 31 }, "end": { "line": 1, "column": 32 } }, "range": [ 31, 32 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 14 } }, "range": [ 7, 14 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 23 } }, "range": [ 22, 23 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 23 } }, "range": [ 16, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ], "comments": [], "globals": [] } }, { "source": "repeat ; until 1", "result": "[1:7] unexpected symbol ';' near 'until'" }, { "source": "repeat 2 until 1", "result": "[1:7] unexpected number '2' near 'until'" }, { "source": "repeat \"foo\" until 1", "result": "[1:7] unexpected string '\"foo\"' near 'until'" }, { "source": "repeat return until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ] }, "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 13 } }, "range": [ 7, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [] } }, { "source": "repeat return return until 0", "result": "[1:14] 'until' expected near 'return'" }, { "source": "repeat break until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 12 } }, "range": [ 7, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ], "comments": [], "globals": [] } }, { "source": "repeat break break until 0", "result": "[1:13] 'until' expected near 'break'" }, { "source": "repeat do end until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ] }, "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 13 } }, "range": [ 7, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [] } }, { "source": "repeat do return end until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 28 } }, "range": [ 27, 28 ] }, "body": [ { "type": "DoStatement", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 16 } }, "range": [ 10, 16 ] } ], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 20 } }, "range": [ 7, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ], "comments": [], "globals": [] } }, { "source": "repeat do break end until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 27 } }, "range": [ 26, 27 ] }, "body": [ { "type": "DoStatement", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 15 } }, "range": [ 10, 15 ] } ], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 19 } }, "range": [ 7, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] } }, { "source": "repeat ; until 1", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "repeat break break until 0", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 26 } }, "range": [ 25, 26 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 12 } }, "range": [ 7, 12 ] }, { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 18 } }, "range": [ 13, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "range": [ 0, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "range": [ 0, 26 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } } ]; })); luaparse-0.3.1/test/spec/return.js000066400000000000000000000275741405615720100171350ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'return', function (exports) { 'use strict'; exports.name = 'return'; exports.spec = [ { "source": "return return", "result": "[1:7] unexpected keyword 'return' near ''" }, { "source": "return 1", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 8 } }, "range": [ 0, 8 ], "comments": [], "globals": [] } }, { "source": "return local", "result": "[1:7] unexpected keyword 'local' near ''" }, { "source": "return \"foo\"", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [ { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 12 } }, "range": [ 7, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ], "comments": [], "globals": [] } }, { "source": "return 1,", "result": "[1:9] expected near ''" }, { "source": "return 1,2,3", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ] }, { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] }, { "type": "NumericLiteral", "value": 3, "raw": "3", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ], "comments": [], "globals": [] } }, { "source": "return a,b,c,d", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": false } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": false } ] } }, { "source": "return 1,2;", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ] }, { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 11 } }, "range": [ 0, 11 ], "comments": [], "globals": [] } } ]; })); luaparse-0.3.1/test/spec/scope.js000066400000000000000000003027701405615720100167210ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'scope', function (exports) { 'use strict'; exports.name = 'scope'; exports.spec = [ { "source": "local foo = 1 do foo = 2 end", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 9 } }, "range": [ 6, 9 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] }, { "type": "DoStatement", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 20 } }, "range": [ 17, 20 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 23 }, "end": { "line": 1, "column": 24 } }, "range": [ 23, 24 ] } ], "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 24 } }, "range": [ 17, 24 ] } ], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 28 } }, "range": [ 14, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ], "comments": [], "globals": [] } }, { "source": "do local foo = 1 end foo = 2", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 12 } }, "range": [ 9, 12 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ] } ], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 16 } }, "range": [ 3, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] }, { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 24 } }, "range": [ 21, 24 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 28 } }, "range": [ 27, 28 ] } ], "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 28 } }, "range": [ 21, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ], "comments": [], "globals": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 24 } }, "range": [ 21, 24 ], "isLocal": false } ] } }, { "source": "do local foo = 1 end do foo = 2 end", "result": { "type": "Chunk", "body": [ { "type": "DoStatement", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 12 } }, "range": [ 9, 12 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ] } ], "loc": { "start": { "line": 1, "column": 3 }, "end": { "line": 1, "column": 16 } }, "range": [ 3, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] }, { "type": "DoStatement", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 27 } }, "range": [ 24, 27 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 30 }, "end": { "line": 1, "column": 31 } }, "range": [ 30, 31 ] } ], "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 31 } }, "range": [ 24, 31 ] } ], "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 35 } }, "range": [ 21, 35 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 35 } }, "range": [ 0, 35 ], "comments": [], "globals": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 27 } }, "range": [ 24, 27 ], "isLocal": false } ] } }, { "source": "local foo do foo = 1 do foo = 2 end end", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 9 } }, "range": [ 6, 9 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] }, { "type": "DoStatement", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 16 } }, "range": [ 13, 16 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ] } ], "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 20 } }, "range": [ 13, 20 ] }, { "type": "DoStatement", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 27 } }, "range": [ 24, 27 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 30 }, "end": { "line": 1, "column": 31 } }, "range": [ 30, 31 ] } ], "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 31 } }, "range": [ 24, 31 ] } ], "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 35 } }, "range": [ 21, 35 ] } ], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 39 } }, "range": [ 10, 39 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 39 } }, "range": [ 0, 39 ], "comments": [], "globals": [] } }, { "source": "local function foo() end foo()", "result": { "type": "Chunk", "body": [ { "type": "FunctionDeclaration", "identifier": { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 18 } }, "range": [ 15, 18 ], "isLocal": true }, "isLocal": true, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ] }, { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "Identifier", "name": "foo", "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 28 } }, "range": [ 25, 28 ], "isLocal": true }, "arguments": [], "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 30 } }, "range": [ 25, 30 ] }, "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 30 } }, "range": [ 25, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ], "comments": [], "globals": [] } }, { "source": "local a = { a }", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ] } ], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 15 } }, "range": [ 10, 15 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 15 } }, "range": [ 0, 15 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 15 } }, "range": [ 0, 15 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": false } ] } }, { "source": "local b = { b, b.a, b[a], b:a() }", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ] }, { "type": "TableValue", "value": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ] }, "base": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 18 } }, "range": [ 15, 18 ] }, "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 18 } }, "range": [ 15, 18 ] }, { "type": "TableValue", "value": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ], "isLocal": false }, "index": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 23 } }, "range": [ 22, 23 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 24 } }, "range": [ 20, 24 ] }, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 24 } }, "range": [ 20, 24 ] }, { "type": "TableValue", "value": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 29 } }, "range": [ 28, 29 ] }, "base": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 27 } }, "range": [ 26, 27 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 29 } }, "range": [ 26, 29 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 31 } }, "range": [ 26, 31 ] }, "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 31 } }, "range": [ 26, 31 ] } ], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 33 } }, "range": [ 10, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": false }, { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 23 } }, "range": [ 22, 23 ], "isLocal": false } ] } }, { "source": "local b = {} local a = { b, b.a, b[a], b:a() }", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [ { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 12 } }, "range": [ 10, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ], "isLocal": true } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 26 } }, "range": [ 25, 26 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 26 } }, "range": [ 25, 26 ] }, { "type": "TableValue", "value": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 30 }, "end": { "line": 1, "column": 31 } }, "range": [ 30, 31 ] }, "base": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 29 } }, "range": [ 28, 29 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 31 } }, "range": [ 28, 31 ] }, "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 31 } }, "range": [ 28, 31 ] }, { "type": "TableValue", "value": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 33 }, "end": { "line": 1, "column": 34 } }, "range": [ 33, 34 ], "isLocal": true }, "index": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 35 }, "end": { "line": 1, "column": 36 } }, "range": [ 35, 36 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 33 }, "end": { "line": 1, "column": 37 } }, "range": [ 33, 37 ] }, "loc": { "start": { "line": 1, "column": 33 }, "end": { "line": 1, "column": 37 } }, "range": [ 33, 37 ] }, { "type": "TableValue", "value": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 41 }, "end": { "line": 1, "column": 42 } }, "range": [ 41, 42 ] }, "base": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 39 }, "end": { "line": 1, "column": 40 } }, "range": [ 39, 40 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 39 }, "end": { "line": 1, "column": 42 } }, "range": [ 39, 42 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 39 }, "end": { "line": 1, "column": 44 } }, "range": [ 39, 44 ] }, "loc": { "start": { "line": 1, "column": 39 }, "end": { "line": 1, "column": 44 } }, "range": [ 39, 44 ] } ], "loc": { "start": { "line": 1, "column": 23 }, "end": { "line": 1, "column": 46 } }, "range": [ 23, 46 ] } ], "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 46 } }, "range": [ 13, 46 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 46 } }, "range": [ 0, 46 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 35 }, "end": { "line": 1, "column": 36 } }, "range": [ 35, 36 ], "isLocal": false } ] } }, { "source": "local c local a = { b[c] }", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ], "isLocal": true } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ], "isLocal": false }, "index": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 23 } }, "range": [ 22, 23 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 24 } }, "range": [ 20, 24 ] }, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 24 } }, "range": [ 20, 24 ] } ], "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 26 } }, "range": [ 18, 26 ] } ], "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 26 } }, "range": [ 8, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "range": [ 0, 26 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ], "isLocal": false } ] } }, { "source": "local a = function() end a()", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [ { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [], "body": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 24 } }, "range": [ 10, 24 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 24 } }, "range": [ 0, 24 ] }, { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 26 } }, "range": [ 25, 26 ], "isLocal": true }, "arguments": [], "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 28 } }, "range": [ 25, 28 ] }, "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 28 } }, "range": [ 25, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ], "comments": [], "globals": [] } }, { "source": "local a, b = 1, a", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] }, { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": false } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ], "isLocal": false } ] } }, { "source": "local a, b = 1, function() b = 2 end", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true } ], "init": [ { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ] }, { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [], "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 28 } }, "range": [ 27, 28 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 31 }, "end": { "line": 1, "column": 32 } }, "range": [ 31, 32 ] } ], "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 32 } }, "range": [ 27, 32 ] } ], "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 36 } }, "range": [ 16, 36 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 36 } }, "range": [ 0, 36 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 36 } }, "range": [ 0, 36 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 28 } }, "range": [ 27, 28 ], "isLocal": false } ] } }, { "source": "local a (a):b():c()", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] }, { "type": "CallStatement", "expression": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 16 }, "end": { "line": 1, "column": 17 } }, "range": [ 16, 17 ] }, "base": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 13 } }, "range": [ 8, 13 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 15 } }, "range": [ 8, 15 ] }, "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 17 } }, "range": [ 8, 17 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 19 } }, "range": [ 8, 19 ] }, "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 19 } }, "range": [ 8, 19 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ], "comments": [], "globals": [] } }, { "source": "local a, b for i, a, b in c do end", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] }, { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "i", "loc": { "start": { "line": 1, "column": 15 }, "end": { "line": 1, "column": 16 } }, "range": [ 15, 16 ], "isLocal": true }, { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 19 } }, "range": [ 18, 19 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 22 } }, "range": [ 21, 22 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 27 } }, "range": [ 26, 27 ], "isLocal": false } ], "body": [], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 34 } }, "range": [ 11, 34 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 34 } }, "range": [ 0, 34 ], "comments": [], "globals": [ { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 27 } }, "range": [ 26, 27 ], "isLocal": false } ] } }, { "source": "local a, b, c for i, a, b in c do end", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": true }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 13 } }, "range": [ 0, 13 ] }, { "type": "ForGenericStatement", "variables": [ { "type": "Identifier", "name": "i", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 19 } }, "range": [ 18, 19 ], "isLocal": true }, { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 21 }, "end": { "line": 1, "column": 22 } }, "range": [ 21, 22 ], "isLocal": true }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 25 } }, "range": [ 24, 25 ], "isLocal": true } ], "iterators": [ { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 29 }, "end": { "line": 1, "column": 30 } }, "range": [ 29, 30 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 37 } }, "range": [ 14, 37 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 37 } }, "range": [ 0, 37 ], "comments": [], "globals": [] } }, { "source": "local a = {} function a:b() return self end self = nil", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [ { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 12 } }, "range": [ 10, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] }, { "type": "FunctionDeclaration", "identifier": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 25 } }, "range": [ 24, 25 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 23 } }, "range": [ 22, 23 ], "isLocal": true }, "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 25 } }, "range": [ 22, 25 ] }, "isLocal": false, "parameters": [], "body": [ { "type": "ReturnStatement", "arguments": [ { "type": "Identifier", "name": "self", "loc": { "start": { "line": 1, "column": 35 }, "end": { "line": 1, "column": 39 } }, "range": [ 35, 39 ], "isLocal": true } ], "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 39 } }, "range": [ 28, 39 ] } ], "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 43 } }, "range": [ 13, 43 ] }, { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "self", "loc": { "start": { "line": 1, "column": 44 }, "end": { "line": 1, "column": 48 } }, "range": [ 44, 48 ], "isLocal": false } ], "init": [ { "type": "NilLiteral", "value": null, "raw": "nil", "loc": { "start": { "line": 1, "column": 51 }, "end": { "line": 1, "column": 54 } }, "range": [ 51, 54 ] } ], "loc": { "start": { "line": 1, "column": 44 }, "end": { "line": 1, "column": 54 } }, "range": [ 44, 54 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 54 } }, "range": [ 0, 54 ], "comments": [], "globals": [ { "type": "Identifier", "name": "self", "loc": { "start": { "line": 1, "column": 44 }, "end": { "line": 1, "column": 48 } }, "range": [ 44, 48 ], "isLocal": false } ] } }, { "source": "repeat local a = true until a", "result": { "type": "Chunk", "body": [ { "type": "RepeatStatement", "condition": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 28 }, "end": { "line": 1, "column": 29 } }, "range": [ 28, 29 ], "isLocal": true }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": true } ], "init": [ { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 21 } }, "range": [ 17, 21 ] } ], "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 21 } }, "range": [ 7, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 29 } }, "range": [ 0, 29 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 29 } }, "range": [ 0, 29 ], "comments": [], "globals": [] } }, { "source": "local a = function (b) end b = 0", "result": { "type": "Chunk", "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": true } ], "init": [ { "type": "FunctionDeclaration", "identifier": null, "isLocal": false, "parameters": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ], "isLocal": true } ], "body": [], "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 26 } }, "range": [ 10, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "range": [ 0, 26 ] }, { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 28 } }, "range": [ 27, 28 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 31 }, "end": { "line": 1, "column": 32 } }, "range": [ 31, 32 ] } ], "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 32 } }, "range": [ 27, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ], "comments": [], "globals": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 28 } }, "range": [ 27, 28 ], "isLocal": false } ] } }, { "source": "for a = 1, 5 do end a = 0", "result": { "type": "Chunk", "body": [ { "type": "ForNumericStatement", "variable": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 5 } }, "range": [ 4, 5 ], "isLocal": true }, "start": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "end": { "type": "NumericLiteral", "value": 5, "raw": "5", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "step": null, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 19 } }, "range": [ 0, 19 ] }, { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ], "isLocal": false } ], "init": [ { "type": "NumericLiteral", "value": 0, "raw": "0", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 25 } }, "range": [ 24, 25 ] } ], "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 25 } }, "range": [ 20, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ], "isLocal": false } ] } } ]; })); luaparse-0.3.1/test/spec/statements.js000066400000000000000000000102611405615720100177660ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'statements', function (exports) { 'use strict'; exports.name = 'statements'; exports.spec = [ { "source": "return", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [], "globals": [] } }, { "source": "nil", "result": "[1:0] unexpected symbol 'nil' near ''" }, { "source": "return;", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [] } }, { "source": ";", "result": "[1:0] unexpected symbol ';' near ''" }, { "source": "return;", "result": { "type": "Chunk", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 7 } }, "range": [ 0, 7 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "return;;", "result": "[1:7] unexpected symbol ';' near ''", "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": ";", "result": { "type": "Chunk", "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } } ]; })); luaparse-0.3.1/test/spec/tableconstructors.js000066400000000000000000003023561405615720100213700ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'tableconstructors', function (exports) { 'use strict'; exports.name = 'tableconstructors'; exports.spec = [ { "source": "a = {", "result": "[1:5] '}' expected near ''" }, { "source": "a = {}", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 6 } }, "range": [ 4, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 6 } }, "range": [ 0, 6 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = {,}", "result": "[1:5] '}' expected near ','" }, { "source": "a = {;}", "result": "[1:5] '}' expected near ';'" }, { "source": "a = {,,}", "result": "[1:5] '}' expected near ','" }, { "source": "a = {;;}", "result": "[1:5] '}' expected near ';'" }, { "source": "a = {{", "result": "[1:6] '}' expected near ''" }, { "source": "a = {{{}}}", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 8 } }, "range": [ 6, 8 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 8 } }, "range": [ 6, 8 ] } ], "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 9 } }, "range": [ 5, 9 ] }, "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 9 } }, "range": [ 5, 9 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = {{},{},{{}},}", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 7 } }, "range": [ 5, 7 ] }, "loc": { "start": { "line": 1, "column": 5 }, "end": { "line": 1, "column": 7 } }, "range": [ 5, 7 ] }, { "type": "TableValue", "value": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 10 } }, "range": [ 8, 10 ] }, "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 10 } }, "range": [ 8, 10 ] }, { "type": "TableValue", "value": { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 14 } }, "range": [ 12, 14 ] }, "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 14 } }, "range": [ 12, 14 ] } ], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 15 } }, "range": [ 11, 15 ] }, "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 15 } }, "range": [ 11, 15 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 17 } }, "range": [ 4, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { 1 }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 9 } }, "range": [ 4, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 9 } }, "range": [ 0, 9 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { 1, }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { 1; }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 10 } }, "range": [ 4, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 10 } }, "range": [ 0, 10 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { 1, 2 }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, { "type": "TableValue", "value": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 12 } }, "range": [ 4, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { a, b, c, }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, { "type": "TableValue", "value": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] }, { "type": "TableValue", "value": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 16 } }, "range": [ 4, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ], "isLocal": false }, { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ], "isLocal": false } ] } }, { "source": "a = { true; false, nil; }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 10 } }, "range": [ 6, 10 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 10 } }, "range": [ 6, 10 ] }, { "type": "TableValue", "value": { "type": "BooleanLiteral", "value": false, "raw": "false", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 17 } }, "range": [ 12, 17 ] }, "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 17 } }, "range": [ 12, 17 ] }, { "type": "TableValue", "value": { "type": "NilLiteral", "value": null, "raw": "nil", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 22 } }, "range": [ 19, 22 ] }, "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 22 } }, "range": [ 19, 22 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 25 } }, "range": [ 4, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { a.b, a[b]; a:c(), }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "MemberExpression", "indexer": ".", "identifier": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 9 } }, "range": [ 6, 9 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 9 } }, "range": [ 6, 9 ] }, { "type": "TableValue", "value": { "type": "IndexExpression", "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ], "isLocal": false }, "index": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 15 } }, "range": [ 11, 15 ] }, "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 15 } }, "range": [ 11, 15 ] }, { "type": "TableValue", "value": { "type": "CallExpression", "base": { "type": "MemberExpression", "indexer": ":", "identifier": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 20 } }, "range": [ 19, 20 ] }, "base": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 20 } }, "range": [ 17, 20 ] }, "arguments": [], "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 22 } }, "range": [ 17, 22 ] }, "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 22 } }, "range": [ 17, 22 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 25 } }, "range": [ 4, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 25 } }, "range": [ 0, 25 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": false } ] } }, { "source": "a = { 1 + 2, a > b, \"a\" or \"b\" }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "BinaryExpression", "operator": "+", "left": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "right": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 11 } }, "range": [ 6, 11 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 11 } }, "range": [ 6, 11 ] }, { "type": "TableValue", "value": { "type": "BinaryExpression", "operator": ">", "left": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 14 } }, "range": [ 13, 14 ], "isLocal": false }, "right": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 18 } }, "range": [ 13, 18 ] }, "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 18 } }, "range": [ 13, 18 ] }, { "type": "TableValue", "value": { "type": "LogicalExpression", "operator": "or", "left": { "type": "StringLiteral", "value": null, "raw": "\"a\"", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 23 } }, "range": [ 20, 23 ] }, "right": { "type": "StringLiteral", "value": null, "raw": "\"b\"", "loc": { "start": { "line": 1, "column": 27 }, "end": { "line": 1, "column": 30 } }, "range": [ 27, 30 ] }, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 30 } }, "range": [ 20, 30 ] }, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 30 } }, "range": [ 20, 30 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 32 } }, "range": [ 4, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": false } ] } }, { "source": "a = { a=1, }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableKeyString", "key": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "value": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 9 } }, "range": [ 6, 9 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 12 } }, "range": [ 4, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 12 } }, "range": [ 0, 12 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { a=1, b=\"foo\", c=nil }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableKeyString", "key": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "value": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 8 }, "end": { "line": 1, "column": 9 } }, "range": [ 8, 9 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 9 } }, "range": [ 6, 9 ] }, { "type": "TableKeyString", "key": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 12 } }, "range": [ 11, 12 ] }, "value": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 18 } }, "range": [ 13, 18 ] }, "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 18 } }, "range": [ 11, 18 ] }, { "type": "TableKeyString", "key": { "type": "Identifier", "name": "c", "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 21 } }, "range": [ 20, 21 ] }, "value": { "type": "NilLiteral", "value": null, "raw": "nil", "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 25 } }, "range": [ 22, 25 ] }, "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 25 } }, "range": [ 20, 25 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 27 } }, "range": [ 4, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { a", "result": "[1:7] '}' expected near ''" }, { "source": "a = { a=", "result": "[1:8] expected near ''" }, { "source": "a = { a=,", "result": "[1:8] expected near ','" }, { "source": "a = { a=;", "result": "[1:8] expected near ';'" }, { "source": "a = { 1, a=\"foo\"", "result": "[1:16] '}' expected near ''" }, { "source": "a = { 1, a=\"foo\"; b={}, d=true; }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, { "type": "TableKeyString", "key": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 10 } }, "range": [ 9, 10 ] }, "value": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 16 } }, "range": [ 11, 16 ] }, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 16 } }, "range": [ 9, 16 ] }, { "type": "TableKeyString", "key": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 19 } }, "range": [ 18, 19 ] }, "value": { "type": "TableConstructorExpression", "fields": [], "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 22 } }, "range": [ 20, 22 ] }, "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 22 } }, "range": [ 18, 22 ] }, { "type": "TableKeyString", "key": { "type": "Identifier", "name": "d", "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 25 } }, "range": [ 24, 25 ] }, "value": { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 30 } }, "range": [ 26, 30 ] }, "loc": { "start": { "line": 1, "column": 24 }, "end": { "line": 1, "column": 30 } }, "range": [ 24, 30 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 33 } }, "range": [ 4, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { [", "result": "[1:7] expected near ''" }, { "source": "a = { [1", "result": "[1:8] ']' expected near ''" }, { "source": "a = { [1]", "result": "[1:9] '=' expected near ''" }, { "source": "a = { [a]=", "result": "[1:10] expected near ''" }, { "source": "a = { [\"foo\"]=\"bar\" }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableKey", "key": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 12 } }, "range": [ 7, 12 ] }, "value": { "type": "StringLiteral", "value": null, "raw": "\"bar\"", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 19 } }, "range": [ 14, 19 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 19 } }, "range": [ 6, 19 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 21 } }, "range": [ 4, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { [1]=a, [2]=b, }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableKey", "key": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 7 }, "end": { "line": 1, "column": 8 } }, "range": [ 7, 8 ] }, "value": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 10 }, "end": { "line": 1, "column": 11 } }, "range": [ 10, 11 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 11 } }, "range": [ 6, 11 ] }, { "type": "TableKey", "key": { "type": "NumericLiteral", "value": 2, "raw": "2", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ] }, "value": { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": false }, "loc": { "start": { "line": 1, "column": 13 }, "end": { "line": 1, "column": 18 } }, "range": [ 13, 18 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 21 } }, "range": [ 4, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false }, { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": false } ] } }, { "source": "a = { true, a=1; [\"foo\"]=\"bar\", }", "result": { "type": "Chunk", "body": [ { "type": "AssignmentStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ], "init": [ { "type": "TableConstructorExpression", "fields": [ { "type": "TableValue", "value": { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 10 } }, "range": [ 6, 10 ] }, "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 10 } }, "range": [ 6, 10 ] }, { "type": "TableKeyString", "key": { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 13 } }, "range": [ 12, 13 ] }, "value": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 15 } }, "range": [ 14, 15 ] }, "loc": { "start": { "line": 1, "column": 12 }, "end": { "line": 1, "column": 15 } }, "range": [ 12, 15 ] }, { "type": "TableKey", "key": { "type": "StringLiteral", "value": null, "raw": "\"foo\"", "loc": { "start": { "line": 1, "column": 18 }, "end": { "line": 1, "column": 23 } }, "range": [ 18, 23 ] }, "value": { "type": "StringLiteral", "value": null, "raw": "\"bar\"", "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 30 } }, "range": [ 25, 30 ] }, "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 30 } }, "range": [ 17, 30 ] } ], "loc": { "start": { "line": 1, "column": 4 }, "end": { "line": 1, "column": 33 } }, "range": [ 4, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 33 } }, "range": [ 0, 33 ], "comments": [], "globals": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 1 } }, "range": [ 0, 1 ], "isLocal": false } ] } }, { "source": "a = { [] }", "result": "[1:7] expected near ']'" }, { "source": "a = { a= }", "result": "[1:9] expected near '}'" }, { "source": "a = { a.b=1 }", "result": "[1:9] '}' expected near '='" }, { "source": "a = { a[b[c]]=1 }", "result": "[1:13] '}' expected near '='" }, { "source": "a = { 2 3 4 }", "result": "[1:8] '}' expected near '3'" } ]; })); luaparse-0.3.1/test/spec/while.js000066400000000000000000000652431405615720100167210ustar00rootroot00000000000000(function (root, name, factory) { 'use strict'; var freeExports = typeof exports === 'object' && exports , freeModule = typeof module === 'object' && module && module.exports === freeExports && module , freeGlobal = typeof global === 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) root = freeGlobal; if (typeof define === 'function' && define.amd) define(['exports'], factory); else if (freeExports && !freeExports.nodeType) { if (freeModule) factory(freeModule.exports); else factory(freeExports); } else factory((root[name] = {})); }(this, 'while', function (exports) { 'use strict'; exports.name = 'while'; exports.spec = [ { "source": "while", "result": "[1:5] expected near ''" }, { "source": "while do", "result": "[1:6] expected near 'do'" }, { "source": "while =", "result": "[1:6] expected near '='" }, { "source": "while 1 do", "result": "[1:10] 'end' expected near ''" }, { "source": "while 1 do end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 14 } }, "range": [ 0, 14 ], "comments": [], "globals": [] } }, { "source": "while 1 do local a end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 18 } }, "range": [ 11, 18 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 22 } }, "range": [ 0, 22 ], "comments": [], "globals": [] } }, { "source": "while 1 do local a local b end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 18 } }, "range": [ 11, 18 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 25 }, "end": { "line": 1, "column": 26 } }, "range": [ 25, 26 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 19 }, "end": { "line": 1, "column": 26 } }, "range": [ 19, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 30 } }, "range": [ 0, 30 ], "comments": [], "globals": [] } }, { "source": "while 1 do local a; local b; end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "a", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 18 } }, "range": [ 17, 18 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 18 } }, "range": [ 11, 18 ] }, { "type": "LocalStatement", "variables": [ { "type": "Identifier", "name": "b", "loc": { "start": { "line": 1, "column": 26 }, "end": { "line": 1, "column": 27 } }, "range": [ 26, 27 ], "isLocal": true } ], "init": [], "loc": { "start": { "line": 1, "column": 20 }, "end": { "line": 1, "column": 27 } }, "range": [ 20, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "range": [ 0, 32 ], "comments": [], "globals": [] } }, { "source": "while 1 do 2 end", "result": "[1:11] unexpected number '2' near 'end'" }, { "source": "while 1 do \"foo\" end", "result": "[1:11] unexpected string '\"foo\"' near 'end'" }, { "source": "while true do end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "BooleanLiteral", "value": true, "raw": "true", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 10 } }, "range": [ 6, 10 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 17 } }, "range": [ 0, 17 ], "comments": [], "globals": [] } }, { "source": "while 1 do ; end", "result": "[1:11] unexpected symbol ';' near 'end'" }, { "source": "while 1 do while", "result": "[1:16] expected near ''" }, { "source": "while 1 end", "result": "[1:8] 'do' expected near 'end'" }, { "source": "while 1 2 do", "result": "[1:8] 'do' expected near '2'" }, { "source": "while 1 = 2 do", "result": "[1:8] 'do' expected near '='" }, { "source": "while 1 do return end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 17 } }, "range": [ 11, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [] } }, { "source": "while 1 do return return end", "result": "[1:18] 'end' expected near 'return'" }, { "source": "while 1 do do end end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "DoStatement", "body": [], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 17 } }, "range": [ 11, 17 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 21 } }, "range": [ 0, 21 ], "comments": [], "globals": [] } }, { "source": "while 1 do do return end end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "DoStatement", "body": [ { "type": "ReturnStatement", "arguments": [], "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 20 } }, "range": [ 14, 20 ] } ], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 24 } }, "range": [ 11, 24 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 28 } }, "range": [ 0, 28 ], "comments": [], "globals": [] } }, { "source": "while 1 do break end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 16 } }, "range": [ 11, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 20 } }, "range": [ 0, 20 ], "comments": [], "globals": [] } }, { "source": "while 1 do break break end", "result": "[1:17] 'end' expected near 'break'" }, { "source": "while 1 do do break end end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "DoStatement", "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 14 }, "end": { "line": 1, "column": 19 } }, "range": [ 14, 19 ] } ], "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 23 } }, "range": [ 11, 23 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 27 } }, "range": [ 0, 27 ], "comments": [], "globals": [] } }, { "source": "while 1 do ; end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 16 } }, "range": [ 0, 16 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } }, { "source": "while 1 do break break end", "result": { "type": "Chunk", "body": [ { "type": "WhileStatement", "condition": { "type": "NumericLiteral", "value": 1, "raw": "1", "loc": { "start": { "line": 1, "column": 6 }, "end": { "line": 1, "column": 7 } }, "range": [ 6, 7 ] }, "body": [ { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 11 }, "end": { "line": 1, "column": 16 } }, "range": [ 11, 16 ] }, { "type": "BreakStatement", "loc": { "start": { "line": 1, "column": 17 }, "end": { "line": 1, "column": 22 } }, "range": [ 17, 22 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "range": [ 0, 26 ] } ], "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 26 } }, "range": [ 0, 26 ], "comments": [], "globals": [] }, "options": { "comments": true, "locations": true, "ranges": true, "scope": true, "luaVersion": "5.2" } } ]; })); luaparse-0.3.1/testem.yml000066400000000000000000000014551405615720100153610ustar00rootroot00000000000000test_page: test/index.html#testem launchers: node: command: node test/runner.js protocol: tap ringo: command: ringo -o -1 test/runner.js 2>&1 protocol: tap rhino: command: cd test; rhino -opt -1 runner.js protocol: tap rhino1.7R5: command: cd test; rhino-1.7r5-pre -opt -1 runner.js protocol: tap nashorn: command: cd test; nashorn runner.js protocol: tap d8: command: cd test; d8 runner.js protocol: tap duktape: command: cd test; duk runner.js protocol: tap quickjs: command: cd test; qjs --std runner.js protocol: tap launch_in_ci: - node - ringo - rhino - duktape - quickjs launch_in_dev: - Opera - Firefox - Chrome - node - ringo - rhino - rhino1.7R5 - duktape - quickjs - nashorn - d8