├── .DS_Store ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── __tests__ ├── bean_test.js ├── case_1.java ├── case_1.json ├── case_2.java ├── case_2.json ├── case_3.java ├── case_3.json ├── case_4.java ├── case_4.json ├── case_5.java ├── case_5.json └── run_tests.js ├── package.json └── src ├── jsonbean.js └── jsonbean.pegjs /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huntbao/jsonbean/ae765b051dda27b0b82198a7dc116e54f8f655ad/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | node_modules 3 | __tests__ 4 | gulpfile.js 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 HuntBao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jsonbean 2 | Extract datatypes from java bean files using [pegjs](http://pegjs.org/). 3 | 4 | ## Installation 5 | 6 | Node.js: 7 | 8 | ```bash 9 | $ npm install jsonbean --save 10 | ``` 11 | 12 | ## Usage 13 | ```js 14 | let jsonbean = require('jsonbean') 15 | let beanStr = 'SOME JAVA BEAN String' 16 | let result = jsonbean.parse(beanStr) 17 | ``` 18 | 19 | If you want to use it in browser, download `src/jsonbean.pegjs`, use `pegjs` to compile it. 20 | 21 | First, you should install pegjs: 22 | 23 | ```bash 24 | $ npm install -g pegjs 25 | ``` 26 | 27 | Then, for example, the browser global variable you wanted is `window.jsonbean`, run command as follows: 28 | 29 | ```bash 30 | $ pegjs --format globals jsonbean.pegjs 31 | ``` 32 | 33 | You can run some tests defined in the `__tests__` directory by the command: 34 | 35 | ```bash 36 | $ npm run test 37 | ``` 38 | 39 | 40 | ## Example 41 | Input java bean string: 42 | 43 | ```java 44 | package com.example.test; 45 | 46 | /* 47 | * User bean 48 | */ 49 | public class User { 50 | /* 51 | * user id 52 | */ 53 | private String id; 54 | 55 | public String getId() { 56 | return id; 57 | } 58 | 59 | public void setId(String id) { 60 | this.id = id; 61 | } 62 | } 63 | ``` 64 | 65 | Output json: 66 | 67 | ```json 68 | { 69 | "name": "User", 70 | "description": "User bean", 71 | "attributes": [ 72 | { 73 | "name": "id", 74 | "type": "String", 75 | "isArray": false, 76 | "defaultValue": "", 77 | "description": "user id" 78 | } 79 | ] 80 | } 81 | ``` -------------------------------------------------------------------------------- /__tests__/bean_test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author huntbao 3 | */ 4 | 'use strict' 5 | var fs = require('fs') 6 | var assert = require('assert') 7 | var jsonbean = require('../src/jsonbean.js') 8 | 9 | describe('Java bean parse tests', function () { 10 | 11 | [1,2,3,4,5].forEach(function (i) { 12 | it('case ' + i , function (done) { 13 | var str = fs.readFileSync(`./__tests__/case_${i}.java`, 'utf8'); 14 | var expect = fs.readFileSync(`./__tests__/case_${i}.json`, 'utf8'); 15 | expect = JSON.parse(expect); 16 | var result = jsonbean.parse(str); 17 | assert.deepEqual(result, expect); 18 | done() 19 | }); 20 | }); 21 | }); -------------------------------------------------------------------------------- /__tests__/case_1.java: -------------------------------------------------------------------------------- 1 | package com.netease.test; 2 | 3 | import java.util.List; 4 | 5 | /* 6 | * User bean 7 | */ 8 | public class User { 9 | /* 10 | * user id 11 | */ 12 | private String id = "test"; 13 | 14 | // test ids 15 | @NotNull 16 | private String[] ids = ["test1", "test2", "test3"]; 17 | 18 | private String ids2[] = ["test1", "test2", "test3"]; // test ids2 19 | /* 20 | * user name 21 | */ 22 | private String name; 23 | /* 24 | * user age 25 | */ 26 | private Integer age = 10; 27 | 28 | // test ages 29 | private Integer[] ages = [1,2,3,4]; 30 | 31 | /* 32 | * user privileges 33 | */ 34 | private List privileges; 35 | 36 | public String getId() { 37 | return id; 38 | } 39 | 40 | public void setId(String id) { 41 | this.id = id; 42 | } 43 | 44 | public List getPrivileges() { 45 | return privileges; 46 | } 47 | 48 | public void setPrivileges(List privileges) { 49 | this.privileges = privileges; 50 | } 51 | 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | public Integer getAge() { 61 | return age; 62 | } 63 | 64 | public void setAge(Integer age) { 65 | this.age = age; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /__tests__/case_1.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "User", 3 | "description": "User bean", 4 | "attributes": [ 5 | { 6 | "name": "id", 7 | "type": "String", 8 | "isArray": false, 9 | "defaultValue": "test", 10 | "description": "user id" 11 | }, 12 | { 13 | "name": "ids", 14 | "type": "String", 15 | "isArray": true, 16 | "defaultValue": ["test1", "test2", "test3"], 17 | "description": "test ids" 18 | }, 19 | { 20 | "name": "ids2", 21 | "type": "String", 22 | "isArray": true, 23 | "defaultValue": ["test1", "test2", "test3"], 24 | "description": "test ids2" 25 | }, 26 | 27 | { 28 | "name": "name", 29 | "type": "String", 30 | "isArray": false, 31 | "defaultValue": "", 32 | "description": "user name" 33 | }, 34 | { 35 | "name": "age", 36 | "type": "Integer", 37 | "isArray": false, 38 | "defaultValue": 10, 39 | "description": "user age" 40 | }, 41 | { 42 | "name": "ages", 43 | "type": "Integer", 44 | "isArray": true, 45 | "defaultValue": [1, 2, 3,4], 46 | "description": "test ages" 47 | }, 48 | { 49 | "name": "privileges", 50 | "type": "String", 51 | "isArray": true, 52 | "defaultValue": "", 53 | "description": "user privileges" 54 | } 55 | ] 56 | } 57 | -------------------------------------------------------------------------------- /__tests__/case_2.java: -------------------------------------------------------------------------------- 1 | package com.netease.test; 2 | 3 | import java.util.List; 4 | 5 | // User bean 6 | public class User { 7 | // user id 8 | private String id; 9 | 10 | // user name 11 | private String name; 12 | 13 | // user age 14 | private Integer age = 10; 15 | 16 | // user privileges 17 | private List privileges; 18 | 19 | public String getId() { 20 | return id; 21 | } 22 | 23 | public void setId(String id) { 24 | this.id = id; 25 | } 26 | 27 | public List getPrivileges() { 28 | return privileges; 29 | } 30 | 31 | public void setPrivileges(List privileges) { 32 | this.privileges = privileges; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public Integer getAge() { 44 | return age; 45 | } 46 | 47 | public void setAge(Integer age) { 48 | this.age = age; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /__tests__/case_2.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "User", 3 | "description": "User bean", 4 | "attributes": [ 5 | { 6 | "name": "id", 7 | "type": "String", 8 | "isArray": false, 9 | "defaultValue": "", 10 | "description": "user id" 11 | }, 12 | { 13 | "name": "name", 14 | "type": "String", 15 | "isArray": false, 16 | "defaultValue": "", 17 | "description": "user name" 18 | }, 19 | { 20 | "name": "age", 21 | "type": "Integer", 22 | "isArray": false, 23 | "defaultValue": "10", 24 | "description": "user age" 25 | }, 26 | { 27 | "name": "privileges", 28 | "type": "String", 29 | "isArray": true, 30 | "defaultValue": "", 31 | "description": "user privileges" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /__tests__/case_3.java: -------------------------------------------------------------------------------- 1 | package com.netease.test; 2 | 3 | import java.util.List; 4 | 5 | // User bean 6 | public class User { 7 | 8 | private String id; // user id 9 | 10 | 11 | private String name; // user name 12 | //user age 13 | 14 | 15 | private Integer age = 10; // this one will be overriden by the 'user age' 16 | 17 | //user privileges 18 | private List privileges; /* this one wouldn't appear */ 19 | 20 | public String getId() { 21 | return id; 22 | } 23 | 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | 28 | public List getPrivileges() { 29 | return privileges; 30 | } 31 | 32 | public void setPrivileges(List privileges) { 33 | this.privileges = privileges; 34 | } 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | public void setName(String name) { 41 | this.name = name; 42 | } 43 | 44 | public Integer getAge() { 45 | return age; 46 | } 47 | 48 | public void setAge(Integer age) { 49 | this.age = age; 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /__tests__/case_3.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "User", 3 | "description": "User bean", 4 | "attributes": [ 5 | { 6 | "name": "id", 7 | "type": "String", 8 | "isArray": false, 9 | "defaultValue": "", 10 | "description": "user id" 11 | }, 12 | { 13 | "name": "name", 14 | "type": "String", 15 | "isArray": false, 16 | "defaultValue": "", 17 | "description": "user name" 18 | }, 19 | { 20 | "name": "age", 21 | "type": "Integer", 22 | "isArray": false, 23 | "defaultValue": "10", 24 | "description": "user age" 25 | }, 26 | { 27 | "name": "privileges", 28 | "type": "String", 29 | "isArray": true, 30 | "defaultValue": "", 31 | "description": "user privileges" 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /__tests__/case_4.java: -------------------------------------------------------------------------------- 1 | package com.netease.test; 2 | 3 | import java.util.List; 4 | 5 | // User bean 6 | public class User { 7 | 8 | private String id; /** user id **/ 9 | 10 | 11 | private String name; /** user name **/ 12 | 13 | 14 | private Integer age = 10; /** user age **/ 15 | 16 | 17 | private List privileges; /** user privileges **/ 18 | 19 | public String getId() { 20 | return id; 21 | } 22 | 23 | public void setId(String id) { 24 | this.id = id; 25 | } 26 | 27 | public List getPrivileges() { 28 | return privileges; 29 | } 30 | 31 | public void setPrivileges(List privileges) { 32 | this.privileges = privileges; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public Integer getAge() { 44 | return age; 45 | } 46 | 47 | public void setAge(Integer age) { 48 | this.age = age; 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /__tests__/case_4.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "User", 3 | "description": "User bean", 4 | "attributes": [ 5 | { 6 | "name": "id", 7 | "type": "String", 8 | "isArray": false, 9 | "defaultValue": "", 10 | "description": "user id" 11 | }, 12 | { 13 | "name": "name", 14 | "type": "String", 15 | "isArray": false, 16 | "defaultValue": "", 17 | "description": "user name" 18 | }, 19 | { 20 | "name": "age", 21 | "type": "Integer", 22 | "isArray": false, 23 | "defaultValue": "10", 24 | "description": "user age" 25 | }, 26 | { 27 | "name": "privileges", 28 | "type": "String", 29 | "isArray": true, 30 | "defaultValue": "", 31 | "description": "user privileges" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /__tests__/case_5.java: -------------------------------------------------------------------------------- 1 | /** 2 | * company: 网易云音乐科技有限公司. 3 | */ 4 | 5 | package com.netease.music.store.inventory.model.vo; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | import lombok.Data; 10 | 11 | /** 12 | * author: hzxuwei3. 13 | * date: 2017年7月10日 下午5:42:30 14 | */ 15 | @Data 16 | public class BarCodeVo { 17 | /** 主键. */ 18 | private long id; 19 | 20 | /** 货号. */ 21 | private String goodsNo; 22 | 23 | 24 | /** 条形码. */ @NotNull private String barCode; 25 | 26 | 27 | // 0-不可用,1-可用 28 | @NotNult private int enabled; 29 | 30 | /** 备注. */ 31 | private String memo; 32 | } 33 | -------------------------------------------------------------------------------- /__tests__/case_5.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BarCodeVo", 3 | "description": "author: hzxuwei3., date: 2017年7月10日 下午5:42:30", 4 | "attributes": [ 5 | { 6 | "name": "id", 7 | "type": "long", 8 | "isArray": false, 9 | "defaultValue": "", 10 | "description": "主键." 11 | }, 12 | { 13 | "name": "goodsNo", 14 | "type": "String", 15 | "isArray": false, 16 | "defaultValue": "", 17 | "description": "货号." 18 | }, 19 | { 20 | "name": "barCode", 21 | "type": "String", 22 | "isArray": false, 23 | "defaultValue": "", 24 | "description": "条形码." 25 | }, 26 | { 27 | "name": "enabled", 28 | "type": "int", 29 | "isArray": false, 30 | "defaultValue": "", 31 | "description": "0-不可用,1-可用" 32 | }, 33 | { 34 | "name": "memo", 35 | "type": "String", 36 | "isArray": false, 37 | "defaultValue": "", 38 | "description": "备注." 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /__tests__/run_tests.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author huntbao 3 | */ 4 | 5 | 'use strict' 6 | 7 | var fs = require('fs') 8 | var path = require('path') 9 | var Mocha = require('mocha') 10 | var mocha = new Mocha().ui('bdd').reporter('spec') 11 | 12 | // dump test case 13 | var dumpTestFile = function (dir) { 14 | fs.readdirSync(dir).forEach(function (name) { 15 | var file = dir + name 16 | if (name == 'cases') { 17 | return 18 | } 19 | if (fs.lstatSync(file).isDirectory()) { 20 | dumpTestFile(file + '/') 21 | } else if (name.endsWith('test.js')) { 22 | mocha.addFile(file) 23 | } 24 | }) 25 | } 26 | // run all test case 27 | dumpTestFile( 28 | __dirname + ((process.argv[2] || '').trim() || '/') 29 | ) 30 | mocha.run(function (failed) { 31 | process.on('exit', function () { 32 | process.exit(failed) 33 | }) 34 | }) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jsonbean", 3 | "version": "1.0.5", 4 | "description": "extract datatypes from java bean", 5 | "main": "./src/jsonbean.js", 6 | "scripts": { 7 | "test": "node __tests__/run_tests.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://huntbao@github.com/huntbao/jsonbean.git" 12 | }, 13 | "author": "HuntBao", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/huntbao/jsonbean/issues" 17 | }, 18 | "homepage": "https://github.com/huntbao/jsonbean#readme", 19 | "devDependencies": { 20 | "gulp": "^3.9.1", 21 | "gulp-mocha": "^2.2.0", 22 | "mocha": "^2.4.5" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/jsonbean.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Generated by PEG.js 0.10.0. 3 | * 4 | * http://pegjs.org/ 5 | */ 6 | 7 | (function () { 8 | function jsonBean() { 9 | "use strict"; 10 | 11 | function peg$subclass(child, parent) { 12 | function ctor() { this.constructor = child; } 13 | 14 | ctor.prototype = parent.prototype; 15 | child.prototype = new ctor(); 16 | } 17 | 18 | function peg$SyntaxError(message, expected, found, location) { 19 | this.message = message; 20 | this.expected = expected; 21 | this.found = found; 22 | this.location = location; 23 | this.name = "SyntaxError"; 24 | 25 | if (typeof Error.captureStackTrace === "function") { 26 | Error.captureStackTrace(this, peg$SyntaxError); 27 | } 28 | } 29 | 30 | peg$subclass(peg$SyntaxError, Error); 31 | 32 | peg$SyntaxError.buildMessage = function (expected, found) { 33 | var DESCRIBE_EXPECTATION_FNS = { 34 | literal: function (expectation) { 35 | return "\"" + literalEscape(expectation.text) + "\""; 36 | }, 37 | 38 | "class": function (expectation) { 39 | var escapedParts = "", 40 | i; 41 | 42 | for (i = 0; i < expectation.parts.length; i++) { 43 | escapedParts += expectation.parts[i] instanceof Array 44 | ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) 45 | : classEscape(expectation.parts[i]); 46 | } 47 | 48 | return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; 49 | }, 50 | 51 | any: function (expectation) { 52 | return "any character"; 53 | }, 54 | 55 | end: function (expectation) { 56 | return "end of input"; 57 | }, 58 | 59 | other: function (expectation) { 60 | return expectation.description; 61 | } 62 | }; 63 | 64 | function hex(ch) { 65 | return ch.charCodeAt(0).toString(16).toUpperCase(); 66 | } 67 | 68 | function literalEscape(s) { 69 | return s 70 | .replace(/\\/g, '\\\\') 71 | .replace(/"/g, '\\"') 72 | .replace(/\0/g, '\\0') 73 | .replace(/\t/g, '\\t') 74 | .replace(/\n/g, '\\n') 75 | .replace(/\r/g, '\\r') 76 | .replace(/[\x00-\x0F]/g, function (ch) { return '\\x0' + hex(ch); }) 77 | .replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { return '\\x' + hex(ch); }); 78 | } 79 | 80 | function classEscape(s) { 81 | return s 82 | .replace(/\\/g, '\\\\') 83 | .replace(/\]/g, '\\]') 84 | .replace(/\^/g, '\\^') 85 | .replace(/-/g, '\\-') 86 | .replace(/\0/g, '\\0') 87 | .replace(/\t/g, '\\t') 88 | .replace(/\n/g, '\\n') 89 | .replace(/\r/g, '\\r') 90 | .replace(/[\x00-\x0F]/g, function (ch) { return '\\x0' + hex(ch); }) 91 | .replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { return '\\x' + hex(ch); }); 92 | } 93 | 94 | function describeExpectation(expectation) { 95 | return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); 96 | } 97 | 98 | function describeExpected(expected) { 99 | var descriptions = new Array(expected.length), 100 | i, j; 101 | 102 | for (i = 0; i < expected.length; i++) { 103 | descriptions[i] = describeExpectation(expected[i]); 104 | } 105 | 106 | descriptions.sort(); 107 | 108 | if (descriptions.length > 0) { 109 | for (i = 1, j = 1; i < descriptions.length; i++) { 110 | if (descriptions[i - 1] !== descriptions[i]) { 111 | descriptions[j] = descriptions[i]; 112 | j++; 113 | } 114 | } 115 | descriptions.length = j; 116 | } 117 | 118 | switch (descriptions.length) { 119 | case 1: 120 | return descriptions[0]; 121 | 122 | case 2: 123 | return descriptions[0] + " or " + descriptions[1]; 124 | 125 | default: 126 | return descriptions.slice(0, -1).join(", ") 127 | + ", or " 128 | + descriptions[descriptions.length - 1]; 129 | } 130 | } 131 | 132 | function describeFound(found) { 133 | return found ? "\"" + literalEscape(found) + "\"" : "end of input"; 134 | } 135 | 136 | return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; 137 | }; 138 | 139 | function peg$parse(input, options) { 140 | options = options !== void 0 ? options : {}; 141 | 142 | var peg$FAILED = {}, 143 | 144 | peg$startRuleFunctions = {Start: peg$parseStart}, 145 | peg$startRuleFunction = peg$parseStart, 146 | 147 | peg$c0 = function (items) { 148 | var result = { 149 | name : '', 150 | description: '', 151 | attributes : [] 152 | } 153 | items.forEach(function (item) { 154 | if (item === null) return; 155 | if (item.class) { 156 | result.name = item.class 157 | result.description = item.description 158 | } else if (item.name) { 159 | result.attributes.push(item) 160 | } 161 | }) 162 | return result 163 | }, 164 | peg$c1 = function () { 165 | return "" // ignore 166 | }, 167 | peg$c2 = ";", 168 | peg$c3 = peg$literalExpectation(";", false), 169 | peg$c4 = function (ct, f, dt, name, arr, dv, cl) { 170 | if (f) { 171 | return null; 172 | } 173 | return { 174 | name : name.join(''), 175 | type : dt.name, 176 | isArray : dt.isArray || (arr ? true : false), 177 | defaultValue: dv == null ? "" : dv, 178 | description : ct.join('') || cl 179 | } 180 | }, 181 | peg$c5 = "public", 182 | peg$c6 = peg$literalExpectation("public", false), 183 | peg$c7 = "class", 184 | peg$c8 = peg$literalExpectation("class", false), 185 | peg$c9 = "{", 186 | peg$c10 = peg$literalExpectation("{", false), 187 | peg$c11 = function (ct, clazz) { 188 | return { 189 | description: ct.join(''), 190 | class : clazz 191 | } 192 | }, 193 | peg$c12 = "}", 194 | peg$c13 = peg$literalExpectation("}", false), 195 | peg$c14 = function () { 196 | return null 197 | }, 198 | peg$c15 = function (a) { 199 | return null 200 | }, 201 | peg$c16 = "[", 202 | peg$c17 = peg$literalExpectation("[", false), 203 | peg$c18 = "]", 204 | peg$c19 = peg$literalExpectation("]", false), 205 | peg$c20 = function (i) {return true;}, 206 | peg$c21 = "List", 207 | peg$c22 = peg$literalExpectation("List", false), 208 | peg$c23 = "<", 209 | peg$c24 = peg$literalExpectation("<", false), 210 | peg$c25 = ">", 211 | peg$c26 = peg$literalExpectation(">", false), 212 | peg$c27 = function (w) { 213 | return { 214 | name : w, 215 | isArray: true 216 | } 217 | }, 218 | peg$c28 = function (w, arr) { 219 | return { 220 | name : w, 221 | isArray: true 222 | } 223 | }, 224 | peg$c29 = function (w) { 225 | return { 226 | name : w, 227 | isArray: false 228 | } 229 | }, 230 | peg$c30 = "@", 231 | peg$c31 = peg$literalExpectation("@", false), 232 | peg$c32 = "private", 233 | peg$c33 = peg$literalExpectation("private", false), 234 | peg$c34 = "protected", 235 | peg$c35 = peg$literalExpectation("protected", false), 236 | peg$c36 = "static", 237 | peg$c37 = peg$literalExpectation("static", false), 238 | peg$c38 = "final", 239 | peg$c39 = peg$literalExpectation("final", false), 240 | peg$c40 = "transient", 241 | peg$c41 = peg$literalExpectation("transient", false), 242 | peg$c42 = "volatile", 243 | peg$c43 = peg$literalExpectation("volatile", false), 244 | peg$c44 = function (s, f) { 245 | /* 246 | 如果把一个member定义为final意味着无法改变,此时该member不应导入 247 | 而static则是类的,也不应该导入 248 | 如: 有些时候JavaBean会implements一些interface(如Seriablizable),就需要定义一个static final long 的serialVersionUID,显然这个member是不应该被导入的 249 | */ 250 | return f === "final" || s === 'static'; 251 | }, 252 | peg$c45 = "=", 253 | peg$c46 = peg$literalExpectation("=", false), 254 | peg$c47 = function (d) { 255 | return d; 256 | 257 | }, 258 | peg$c48 = ",", 259 | peg$c49 = peg$literalExpectation(",", false), 260 | peg$c50 = function (s, ss) { 261 | var temp = ss.map(function (item) { return item[2];}); 262 | temp.unshift(s); 263 | return { 264 | notArray: true, 265 | value : temp 266 | }; 267 | }, 268 | peg$c51 = function (v, vv) { 269 | // 支持一下几种: 270 | // [1,2,3] 271 | // [[1,2,3],[4,5,6]] 272 | // ["test", "it",["a", "test]]; parser中对这种差异性不处理,不进行类型检查。 273 | if (v.notArray) { 274 | return v.value; 275 | } else { 276 | var temp = new Array(); 277 | temp.push(v); 278 | if (vv.length == 0) { 279 | return temp; 280 | } else { 281 | var vvTemp = vv.map(function (item) {return item[2]}); 282 | return temp.concat(vvTemp); 283 | } 284 | } 285 | }, 286 | peg$c52 = "//", 287 | peg$c53 = peg$literalExpectation("//", false), 288 | peg$c54 = function (c) { // 因为都是包在一个java class 中, 所以一定有LB 289 | return c.join('') 290 | }, 291 | peg$c55 = function (c) { 292 | return c 293 | }, 294 | peg$c56 = /^[\/]/, 295 | peg$c57 = peg$classExpectation(["/"], false, false), 296 | peg$c58 = /^[*]/, 297 | peg$c59 = peg$classExpectation(["*"], false, false), 298 | peg$c60 = "*/", 299 | peg$c61 = peg$literalExpectation("*/", false), 300 | peg$c62 = peg$anyExpectation(), 301 | peg$c63 = function (c) { 302 | var comments = c.map(function (item) { 303 | return item[1] 304 | }).join('').split('\n') 305 | var result = [] 306 | comments.forEach(function (comment) { 307 | var trimResult = comment.trim().replace(/^\*+|\*+$/g, '').trim() 308 | if (trimResult) { 309 | result.push(trimResult) 310 | } 311 | }) 312 | return result.join(', ') 313 | }, 314 | peg$c64 = "\"", 315 | peg$c65 = peg$literalExpectation("\"", false), 316 | peg$c66 = /^[^"]/, 317 | peg$c67 = peg$classExpectation(["\""], true, false), 318 | peg$c68 = function (s) { 319 | return s.join(''); 320 | }, 321 | peg$c69 = function (f) { 322 | return f.map(function (i) { 323 | if (i instanceof Array) { 324 | return i.join('') 325 | } else return i 326 | }).join(''); 327 | }, 328 | peg$c70 = /^[0-9]/, 329 | peg$c71 = peg$classExpectation([["0", "9"]], false, false), 330 | peg$c72 = /^[eE]/, 331 | peg$c73 = peg$classExpectation(["e", "E"], false, false), 332 | peg$c74 = /^[+\-]/, 333 | peg$c75 = peg$classExpectation(["+", "-"], false, false), 334 | peg$c76 = function (e, s, ds) { 335 | return e + (s == null ? "" : s) + ds.join(''); 336 | }, 337 | peg$c77 = ".", 338 | peg$c78 = peg$literalExpectation(".", false), 339 | peg$c79 = function (s, d) { 340 | return (s == '-' ? -1 : 1) * Number(d.join('')); 341 | }, 342 | peg$c80 = function (l) { 343 | return l.join(''); 344 | }, 345 | peg$c81 = /^[a-zA-Z0-9]/, 346 | peg$c82 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"]], false, false), 347 | peg$c83 = peg$otherExpectation("Whitespace"), 348 | peg$c84 = /^[ \t]/, 349 | peg$c85 = peg$classExpectation([" ", "\t"], false, false), 350 | peg$c86 = peg$otherExpectation("Zero or more whitespaces"), 351 | peg$c87 = peg$otherExpectation("One or more whitespaces"), 352 | peg$c88 = /^[\r\n]/, 353 | peg$c89 = peg$classExpectation(["\r", "\n"], false, false), 354 | peg$c90 = /^[^;{]/, 355 | peg$c91 = peg$classExpectation([";", "{"], true, false), 356 | peg$c92 = /^[^\r\n]/, 357 | peg$c93 = peg$classExpectation(["\r", "\n"], true, false), 358 | 359 | peg$currPos = 0, 360 | peg$savedPos = 0, 361 | peg$posDetailsCache = [{line: 1, column: 1}], 362 | peg$maxFailPos = 0, 363 | peg$maxFailExpected = [], 364 | peg$silentFails = 0, 365 | 366 | peg$result; 367 | 368 | if ("startRule" in options) { 369 | if (!(options.startRule in peg$startRuleFunctions)) { 370 | throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); 371 | } 372 | 373 | peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; 374 | } 375 | 376 | function text() { 377 | return input.substring(peg$savedPos, peg$currPos); 378 | } 379 | 380 | function location() { 381 | return peg$computeLocation(peg$savedPos, peg$currPos); 382 | } 383 | 384 | function expected(description, location) { 385 | location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) 386 | 387 | throw peg$buildStructuredError( 388 | [peg$otherExpectation(description)], 389 | input.substring(peg$savedPos, peg$currPos), 390 | location 391 | ); 392 | } 393 | 394 | function error(message, location) { 395 | location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) 396 | 397 | throw peg$buildSimpleError(message, location); 398 | } 399 | 400 | function peg$literalExpectation(text, ignoreCase) { 401 | return {type: "literal", text: text, ignoreCase: ignoreCase}; 402 | } 403 | 404 | function peg$classExpectation(parts, inverted, ignoreCase) { 405 | return {type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase}; 406 | } 407 | 408 | function peg$anyExpectation() { 409 | return {type: "any"}; 410 | } 411 | 412 | function peg$endExpectation() { 413 | return {type: "end"}; 414 | } 415 | 416 | function peg$otherExpectation(description) { 417 | return {type: "other", description: description}; 418 | } 419 | 420 | function peg$computePosDetails(pos) { 421 | var details = peg$posDetailsCache[pos], p; 422 | 423 | if (details) { 424 | return details; 425 | } else { 426 | p = pos - 1; 427 | while (!peg$posDetailsCache[p]) { 428 | p--; 429 | } 430 | 431 | details = peg$posDetailsCache[p]; 432 | details = { 433 | line : details.line, 434 | column: details.column 435 | }; 436 | 437 | while (p < pos) { 438 | if (input.charCodeAt(p) === 10) { 439 | details.line++; 440 | details.column = 1; 441 | } else { 442 | details.column++; 443 | } 444 | 445 | p++; 446 | } 447 | 448 | peg$posDetailsCache[pos] = details; 449 | return details; 450 | } 451 | } 452 | 453 | function peg$computeLocation(startPos, endPos) { 454 | var startPosDetails = peg$computePosDetails(startPos), 455 | endPosDetails = peg$computePosDetails(endPos); 456 | 457 | return { 458 | start: { 459 | offset: startPos, 460 | line : startPosDetails.line, 461 | column: startPosDetails.column 462 | }, 463 | end : { 464 | offset: endPos, 465 | line : endPosDetails.line, 466 | column: endPosDetails.column 467 | } 468 | }; 469 | } 470 | 471 | function peg$fail(expected) { 472 | if (peg$currPos < peg$maxFailPos) { 473 | return; 474 | } 475 | 476 | if (peg$currPos > peg$maxFailPos) { 477 | peg$maxFailPos = peg$currPos; 478 | peg$maxFailExpected = []; 479 | } 480 | 481 | peg$maxFailExpected.push(expected); 482 | } 483 | 484 | function peg$buildSimpleError(message, location) { 485 | return new peg$SyntaxError(message, null, null, location); 486 | } 487 | 488 | function peg$buildStructuredError(expected, found, location) { 489 | return new peg$SyntaxError( 490 | peg$SyntaxError.buildMessage(expected, found), 491 | expected, 492 | found, 493 | location 494 | ); 495 | } 496 | 497 | function peg$parseStart() { 498 | var s0, s1, s2; 499 | 500 | s0 = peg$currPos; 501 | s1 = []; 502 | s2 = peg$parseStatement(); 503 | if (s2 !== peg$FAILED) { 504 | while (s2 !== peg$FAILED) { 505 | s1.push(s2); 506 | s2 = peg$parseStatement(); 507 | } 508 | } else { 509 | s1 = peg$FAILED; 510 | } 511 | if (s1 !== peg$FAILED) { 512 | peg$savedPos = s0; 513 | s1 = peg$c0(s1); 514 | } 515 | s0 = s1; 516 | 517 | return s0; 518 | } 519 | 520 | function peg$parseCommentOrLB() { 521 | var s0, s1, s2; 522 | 523 | s0 = peg$parseComment(); 524 | if (s0 === peg$FAILED) { 525 | s0 = peg$currPos; 526 | s1 = []; 527 | s2 = peg$parseLB(); 528 | if (s2 !== peg$FAILED) { 529 | while (s2 !== peg$FAILED) { 530 | s1.push(s2); 531 | s2 = peg$parseLB(); 532 | } 533 | } else { 534 | s1 = peg$FAILED; 535 | } 536 | if (s1 !== peg$FAILED) { 537 | peg$savedPos = s0; 538 | s1 = peg$c1(); 539 | } 540 | s0 = s1; 541 | } 542 | 543 | return s0; 544 | } 545 | 546 | function peg$parseStatement() { 547 | var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16; 548 | 549 | s0 = peg$currPos; 550 | s1 = peg$parse_(); 551 | if (s1 !== peg$FAILED) { 552 | s2 = []; 553 | s3 = peg$parseComment(); 554 | while (s3 !== peg$FAILED) { 555 | s2.push(s3); 556 | s3 = peg$parseComment(); 557 | } 558 | if (s2 !== peg$FAILED) { 559 | s3 = peg$parse_(); 560 | if (s3 !== peg$FAILED) { 561 | s4 = peg$parseMarkerAnnotation(); 562 | if (s4 === peg$FAILED) { 563 | s4 = null; 564 | } 565 | if (s4 !== peg$FAILED) { 566 | s5 = peg$parse_(); 567 | if (s5 !== peg$FAILED) { 568 | s6 = peg$parseFieldModifiers(); 569 | if (s6 !== peg$FAILED) { 570 | s7 = peg$parse__(); 571 | if (s7 !== peg$FAILED) { 572 | s8 = peg$parseDataType(); 573 | if (s8 !== peg$FAILED) { 574 | s9 = peg$parse__(); 575 | if (s9 !== peg$FAILED) { 576 | s10 = []; 577 | s11 = peg$parseCharacter(); 578 | if (s11 !== peg$FAILED) { 579 | while (s11 !== peg$FAILED) { 580 | s10.push(s11); 581 | s11 = peg$parseCharacter(); 582 | } 583 | } else { 584 | s10 = peg$FAILED; 585 | } 586 | if (s10 !== peg$FAILED) { 587 | s11 = peg$parse_(); 588 | if (s11 !== peg$FAILED) { 589 | s12 = peg$parseTraditionalArray(); 590 | if (s12 === peg$FAILED) { 591 | s12 = null; 592 | } 593 | if (s12 !== peg$FAILED) { 594 | s13 = peg$parseDefaultValueAssign(); 595 | if (s13 === peg$FAILED) { 596 | s13 = null; 597 | } 598 | if (s13 !== peg$FAILED) { 599 | if (input.charCodeAt(peg$currPos) === 59) { 600 | s14 = peg$c2; 601 | peg$currPos++; 602 | } else { 603 | s14 = peg$FAILED; 604 | if (peg$silentFails === 0) { 605 | peg$fail(peg$c3); 606 | } 607 | } 608 | if (s14 !== peg$FAILED) { 609 | s15 = peg$parse_(); 610 | if (s15 !== peg$FAILED) { 611 | s16 = peg$parseCommentOrLB(); 612 | if (s16 !== peg$FAILED) { 613 | peg$savedPos = s0; 614 | s1 = peg$c4(s2, s6, s8, s10, s12, s13, s16); 615 | s0 = s1; 616 | } else { 617 | peg$currPos = s0; 618 | s0 = peg$FAILED; 619 | } 620 | } else { 621 | peg$currPos = s0; 622 | s0 = peg$FAILED; 623 | } 624 | } else { 625 | peg$currPos = s0; 626 | s0 = peg$FAILED; 627 | } 628 | } else { 629 | peg$currPos = s0; 630 | s0 = peg$FAILED; 631 | } 632 | } else { 633 | peg$currPos = s0; 634 | s0 = peg$FAILED; 635 | } 636 | } else { 637 | peg$currPos = s0; 638 | s0 = peg$FAILED; 639 | } 640 | } else { 641 | peg$currPos = s0; 642 | s0 = peg$FAILED; 643 | } 644 | } else { 645 | peg$currPos = s0; 646 | s0 = peg$FAILED; 647 | } 648 | } else { 649 | peg$currPos = s0; 650 | s0 = peg$FAILED; 651 | } 652 | } else { 653 | peg$currPos = s0; 654 | s0 = peg$FAILED; 655 | } 656 | } else { 657 | peg$currPos = s0; 658 | s0 = peg$FAILED; 659 | } 660 | } else { 661 | peg$currPos = s0; 662 | s0 = peg$FAILED; 663 | } 664 | } else { 665 | peg$currPos = s0; 666 | s0 = peg$FAILED; 667 | } 668 | } else { 669 | peg$currPos = s0; 670 | s0 = peg$FAILED; 671 | } 672 | } else { 673 | peg$currPos = s0; 674 | s0 = peg$FAILED; 675 | } 676 | } else { 677 | peg$currPos = s0; 678 | s0 = peg$FAILED; 679 | } 680 | if (s0 === peg$FAILED) { 681 | s0 = peg$currPos; 682 | s1 = []; 683 | s2 = peg$parseComment(); 684 | while (s2 !== peg$FAILED) { 685 | s1.push(s2); 686 | s2 = peg$parseComment(); 687 | } 688 | if (s1 !== peg$FAILED) { 689 | s2 = peg$parse_(); 690 | if (s2 !== peg$FAILED) { 691 | s3 = peg$parseMarkerAnnotation(); 692 | if (s3 === peg$FAILED) { 693 | s3 = null; 694 | } 695 | if (s3 !== peg$FAILED) { 696 | s4 = peg$parse_(); 697 | if (s4 !== peg$FAILED) { 698 | if (input.substr(peg$currPos, 6) === peg$c5) { 699 | s5 = peg$c5; 700 | peg$currPos += 6; 701 | } else { 702 | s5 = peg$FAILED; 703 | if (peg$silentFails === 0) { 704 | peg$fail(peg$c6); 705 | } 706 | } 707 | if (s5 !== peg$FAILED) { 708 | s6 = peg$parse__(); 709 | if (s6 !== peg$FAILED) { 710 | if (input.substr(peg$currPos, 5) === peg$c7) { 711 | s7 = peg$c7; 712 | peg$currPos += 5; 713 | } else { 714 | s7 = peg$FAILED; 715 | if (peg$silentFails === 0) { 716 | peg$fail(peg$c8); 717 | } 718 | } 719 | if (s7 !== peg$FAILED) { 720 | s8 = peg$parse__(); 721 | if (s8 !== peg$FAILED) { 722 | s9 = peg$parseWord(); 723 | if (s9 !== peg$FAILED) { 724 | s10 = peg$parseAnyWithoutTerminator(); 725 | if (s10 !== peg$FAILED) { 726 | if (input.charCodeAt(peg$currPos) === 123) { 727 | s11 = peg$c9; 728 | peg$currPos++; 729 | } else { 730 | s11 = peg$FAILED; 731 | if (peg$silentFails === 0) { 732 | peg$fail(peg$c10); 733 | } 734 | } 735 | if (s11 !== peg$FAILED) { 736 | s12 = []; 737 | s13 = peg$parseLB(); 738 | while (s13 !== peg$FAILED) { 739 | s12.push(s13); 740 | s13 = peg$parseLB(); 741 | } 742 | if (s12 !== peg$FAILED) { 743 | peg$savedPos = s0; 744 | s1 = peg$c11(s1, s9); 745 | s0 = s1; 746 | } else { 747 | peg$currPos = s0; 748 | s0 = peg$FAILED; 749 | } 750 | } else { 751 | peg$currPos = s0; 752 | s0 = peg$FAILED; 753 | } 754 | } else { 755 | peg$currPos = s0; 756 | s0 = peg$FAILED; 757 | } 758 | } else { 759 | peg$currPos = s0; 760 | s0 = peg$FAILED; 761 | } 762 | } else { 763 | peg$currPos = s0; 764 | s0 = peg$FAILED; 765 | } 766 | } else { 767 | peg$currPos = s0; 768 | s0 = peg$FAILED; 769 | } 770 | } else { 771 | peg$currPos = s0; 772 | s0 = peg$FAILED; 773 | } 774 | } else { 775 | peg$currPos = s0; 776 | s0 = peg$FAILED; 777 | } 778 | } else { 779 | peg$currPos = s0; 780 | s0 = peg$FAILED; 781 | } 782 | } else { 783 | peg$currPos = s0; 784 | s0 = peg$FAILED; 785 | } 786 | } else { 787 | peg$currPos = s0; 788 | s0 = peg$FAILED; 789 | } 790 | } else { 791 | peg$currPos = s0; 792 | s0 = peg$FAILED; 793 | } 794 | if (s0 === peg$FAILED) { 795 | s0 = peg$currPos; 796 | s1 = peg$parse_(); 797 | if (s1 !== peg$FAILED) { 798 | if (input.charCodeAt(peg$currPos) === 125) { 799 | s2 = peg$c12; 800 | peg$currPos++; 801 | } else { 802 | s2 = peg$FAILED; 803 | if (peg$silentFails === 0) { 804 | peg$fail(peg$c13); 805 | } 806 | } 807 | if (s2 !== peg$FAILED) { 808 | s3 = peg$parse_(); 809 | if (s3 !== peg$FAILED) { 810 | s4 = []; 811 | s5 = peg$parseLB(); 812 | while (s5 !== peg$FAILED) { 813 | s4.push(s5); 814 | s5 = peg$parseLB(); 815 | } 816 | if (s4 !== peg$FAILED) { 817 | peg$savedPos = s0; 818 | s1 = peg$c14(); 819 | s0 = s1; 820 | } else { 821 | peg$currPos = s0; 822 | s0 = peg$FAILED; 823 | } 824 | } else { 825 | peg$currPos = s0; 826 | s0 = peg$FAILED; 827 | } 828 | } else { 829 | peg$currPos = s0; 830 | s0 = peg$FAILED; 831 | } 832 | } else { 833 | peg$currPos = s0; 834 | s0 = peg$FAILED; 835 | } 836 | if (s0 === peg$FAILED) { 837 | s0 = peg$currPos; 838 | s1 = peg$parseAnyWithoutLB(); 839 | if (s1 !== peg$FAILED) { 840 | s2 = []; 841 | s3 = peg$parseLB(); 842 | if (s3 !== peg$FAILED) { 843 | while (s3 !== peg$FAILED) { 844 | s2.push(s3); 845 | s3 = peg$parseLB(); 846 | } 847 | } else { 848 | s2 = peg$FAILED; 849 | } 850 | if (s2 !== peg$FAILED) { 851 | peg$savedPos = s0; 852 | s1 = peg$c15(s1); 853 | s0 = s1; 854 | } else { 855 | peg$currPos = s0; 856 | s0 = peg$FAILED; 857 | } 858 | } else { 859 | peg$currPos = s0; 860 | s0 = peg$FAILED; 861 | } 862 | } 863 | } 864 | } 865 | 866 | return s0; 867 | } 868 | 869 | function peg$parseTraditionalArray() { 870 | var s0, s1, s2, s3, s4, s5; 871 | 872 | s0 = peg$currPos; 873 | if (input.charCodeAt(peg$currPos) === 91) { 874 | s1 = peg$c16; 875 | peg$currPos++; 876 | } else { 877 | s1 = peg$FAILED; 878 | if (peg$silentFails === 0) { 879 | peg$fail(peg$c17); 880 | } 881 | } 882 | if (s1 !== peg$FAILED) { 883 | s2 = peg$parse_(); 884 | if (s2 !== peg$FAILED) { 885 | s3 = peg$parseInterger(); 886 | if (s3 === peg$FAILED) { 887 | s3 = null; 888 | } 889 | if (s3 !== peg$FAILED) { 890 | s4 = peg$parse_(); 891 | if (s4 !== peg$FAILED) { 892 | if (input.charCodeAt(peg$currPos) === 93) { 893 | s5 = peg$c18; 894 | peg$currPos++; 895 | } else { 896 | s5 = peg$FAILED; 897 | if (peg$silentFails === 0) { 898 | peg$fail(peg$c19); 899 | } 900 | } 901 | if (s5 !== peg$FAILED) { 902 | peg$savedPos = s0; 903 | s1 = peg$c20(s3); 904 | s0 = s1; 905 | } else { 906 | peg$currPos = s0; 907 | s0 = peg$FAILED; 908 | } 909 | } else { 910 | peg$currPos = s0; 911 | s0 = peg$FAILED; 912 | } 913 | } else { 914 | peg$currPos = s0; 915 | s0 = peg$FAILED; 916 | } 917 | } else { 918 | peg$currPos = s0; 919 | s0 = peg$FAILED; 920 | } 921 | } else { 922 | peg$currPos = s0; 923 | s0 = peg$FAILED; 924 | } 925 | 926 | return s0; 927 | } 928 | 929 | function peg$parseDataType() { 930 | var s0, s1, s2, s3, s4, s5, s6; 931 | 932 | s0 = peg$currPos; 933 | if (input.substr(peg$currPos, 4) === peg$c21) { 934 | s1 = peg$c21; 935 | peg$currPos += 4; 936 | } else { 937 | s1 = peg$FAILED; 938 | if (peg$silentFails === 0) { 939 | peg$fail(peg$c22); 940 | } 941 | } 942 | if (s1 !== peg$FAILED) { 943 | s2 = peg$parse_(); 944 | if (s2 !== peg$FAILED) { 945 | if (input.charCodeAt(peg$currPos) === 60) { 946 | s3 = peg$c23; 947 | peg$currPos++; 948 | } else { 949 | s3 = peg$FAILED; 950 | if (peg$silentFails === 0) { 951 | peg$fail(peg$c24); 952 | } 953 | } 954 | if (s3 !== peg$FAILED) { 955 | s4 = peg$parseWord(); 956 | if (s4 !== peg$FAILED) { 957 | s5 = peg$parse_(); 958 | if (s5 !== peg$FAILED) { 959 | if (input.charCodeAt(peg$currPos) === 62) { 960 | s6 = peg$c25; 961 | peg$currPos++; 962 | } else { 963 | s6 = peg$FAILED; 964 | if (peg$silentFails === 0) { 965 | peg$fail(peg$c26); 966 | } 967 | } 968 | if (s6 !== peg$FAILED) { 969 | peg$savedPos = s0; 970 | s1 = peg$c27(s4); 971 | s0 = s1; 972 | } else { 973 | peg$currPos = s0; 974 | s0 = peg$FAILED; 975 | } 976 | } else { 977 | peg$currPos = s0; 978 | s0 = peg$FAILED; 979 | } 980 | } else { 981 | peg$currPos = s0; 982 | s0 = peg$FAILED; 983 | } 984 | } else { 985 | peg$currPos = s0; 986 | s0 = peg$FAILED; 987 | } 988 | } else { 989 | peg$currPos = s0; 990 | s0 = peg$FAILED; 991 | } 992 | } else { 993 | peg$currPos = s0; 994 | s0 = peg$FAILED; 995 | } 996 | if (s0 === peg$FAILED) { 997 | s0 = peg$currPos; 998 | s1 = peg$parseWord(); 999 | if (s1 !== peg$FAILED) { 1000 | s2 = peg$parseTraditionalArray(); 1001 | if (s2 !== peg$FAILED) { 1002 | peg$savedPos = s0; 1003 | s1 = peg$c28(s1, s2); 1004 | s0 = s1; 1005 | } else { 1006 | peg$currPos = s0; 1007 | s0 = peg$FAILED; 1008 | } 1009 | } else { 1010 | peg$currPos = s0; 1011 | s0 = peg$FAILED; 1012 | } 1013 | if (s0 === peg$FAILED) { 1014 | s0 = peg$currPos; 1015 | s1 = peg$parseWord(); 1016 | if (s1 !== peg$FAILED) { 1017 | peg$savedPos = s0; 1018 | s1 = peg$c29(s1); 1019 | } 1020 | s0 = s1; 1021 | } 1022 | } 1023 | 1024 | return s0; 1025 | } 1026 | 1027 | function peg$parseMarkerAnnotation() { 1028 | var s0, s1, s2, s3, s4, s5, s6; 1029 | 1030 | s0 = peg$currPos; 1031 | s1 = peg$parse_(); 1032 | if (s1 !== peg$FAILED) { 1033 | if (input.charCodeAt(peg$currPos) === 64) { 1034 | s2 = peg$c30; 1035 | peg$currPos++; 1036 | } else { 1037 | s2 = peg$FAILED; 1038 | if (peg$silentFails === 0) { 1039 | peg$fail(peg$c31); 1040 | } 1041 | } 1042 | if (s2 !== peg$FAILED) { 1043 | s3 = peg$parseWord(); 1044 | if (s3 !== peg$FAILED) { 1045 | s4 = peg$parse_(); 1046 | if (s4 !== peg$FAILED) { 1047 | s5 = []; 1048 | s6 = peg$parseLB(); 1049 | while (s6 !== peg$FAILED) { 1050 | s5.push(s6); 1051 | s6 = peg$parseLB(); 1052 | } 1053 | if (s5 !== peg$FAILED) { 1054 | s1 = [s1, s2, s3, s4, s5]; 1055 | s0 = s1; 1056 | } else { 1057 | peg$currPos = s0; 1058 | s0 = peg$FAILED; 1059 | } 1060 | } else { 1061 | peg$currPos = s0; 1062 | s0 = peg$FAILED; 1063 | } 1064 | } else { 1065 | peg$currPos = s0; 1066 | s0 = peg$FAILED; 1067 | } 1068 | } else { 1069 | peg$currPos = s0; 1070 | s0 = peg$FAILED; 1071 | } 1072 | } else { 1073 | peg$currPos = s0; 1074 | s0 = peg$FAILED; 1075 | } 1076 | 1077 | return s0; 1078 | } 1079 | 1080 | function peg$parseDataTypeModifier() { 1081 | var s0; 1082 | 1083 | if (input.substr(peg$currPos, 7) === peg$c32) { 1084 | s0 = peg$c32; 1085 | peg$currPos += 7; 1086 | } else { 1087 | s0 = peg$FAILED; 1088 | if (peg$silentFails === 0) { 1089 | peg$fail(peg$c33); 1090 | } 1091 | } 1092 | if (s0 === peg$FAILED) { 1093 | if (input.substr(peg$currPos, 9) === peg$c34) { 1094 | s0 = peg$c34; 1095 | peg$currPos += 9; 1096 | } else { 1097 | s0 = peg$FAILED; 1098 | if (peg$silentFails === 0) { 1099 | peg$fail(peg$c35); 1100 | } 1101 | } 1102 | if (s0 === peg$FAILED) { 1103 | if (input.substr(peg$currPos, 6) === peg$c5) { 1104 | s0 = peg$c5; 1105 | peg$currPos += 6; 1106 | } else { 1107 | s0 = peg$FAILED; 1108 | if (peg$silentFails === 0) { 1109 | peg$fail(peg$c6); 1110 | } 1111 | } 1112 | } 1113 | } 1114 | 1115 | return s0; 1116 | } 1117 | 1118 | function peg$parseStaticFields() { 1119 | var s0; 1120 | 1121 | if (input.substr(peg$currPos, 6) === peg$c36) { 1122 | s0 = peg$c36; 1123 | peg$currPos += 6; 1124 | } else { 1125 | s0 = peg$FAILED; 1126 | if (peg$silentFails === 0) { 1127 | peg$fail(peg$c37); 1128 | } 1129 | } 1130 | 1131 | return s0; 1132 | } 1133 | 1134 | function peg$parseFinalFields() { 1135 | var s0; 1136 | 1137 | if (input.substr(peg$currPos, 5) === peg$c38) { 1138 | s0 = peg$c38; 1139 | peg$currPos += 5; 1140 | } else { 1141 | s0 = peg$FAILED; 1142 | if (peg$silentFails === 0) { 1143 | peg$fail(peg$c39); 1144 | } 1145 | } 1146 | 1147 | return s0; 1148 | } 1149 | 1150 | function peg$parseTransientFields() { 1151 | var s0; 1152 | 1153 | if (input.substr(peg$currPos, 9) === peg$c40) { 1154 | s0 = peg$c40; 1155 | peg$currPos += 9; 1156 | } else { 1157 | s0 = peg$FAILED; 1158 | if (peg$silentFails === 0) { 1159 | peg$fail(peg$c41); 1160 | } 1161 | } 1162 | 1163 | return s0; 1164 | } 1165 | 1166 | function peg$parseVolatileFields() { 1167 | var s0; 1168 | 1169 | if (input.substr(peg$currPos, 8) === peg$c42) { 1170 | s0 = peg$c42; 1171 | peg$currPos += 8; 1172 | } else { 1173 | s0 = peg$FAILED; 1174 | if (peg$silentFails === 0) { 1175 | peg$fail(peg$c43); 1176 | } 1177 | } 1178 | 1179 | return s0; 1180 | } 1181 | 1182 | function peg$parseFieldModifiers() { 1183 | var s0, s1, s2, s3, s4, s5; 1184 | 1185 | s0 = peg$currPos; 1186 | s1 = peg$parseDataTypeModifier(); 1187 | if (s1 === peg$FAILED) { 1188 | s1 = null; 1189 | } 1190 | if (s1 !== peg$FAILED) { 1191 | s2 = peg$parseStaticFields(); 1192 | if (s2 === peg$FAILED) { 1193 | s2 = null; 1194 | } 1195 | if (s2 !== peg$FAILED) { 1196 | s3 = peg$parseFinalFields(); 1197 | if (s3 === peg$FAILED) { 1198 | s3 = null; 1199 | } 1200 | if (s3 !== peg$FAILED) { 1201 | s4 = peg$parseTransientFields(); 1202 | if (s4 === peg$FAILED) { 1203 | s4 = null; 1204 | } 1205 | if (s4 !== peg$FAILED) { 1206 | s5 = peg$parseVolatileFields(); 1207 | if (s5 === peg$FAILED) { 1208 | s5 = null; 1209 | } 1210 | if (s5 !== peg$FAILED) { 1211 | peg$savedPos = s0; 1212 | s1 = peg$c44(s2, s3); 1213 | s0 = s1; 1214 | } else { 1215 | peg$currPos = s0; 1216 | s0 = peg$FAILED; 1217 | } 1218 | } else { 1219 | peg$currPos = s0; 1220 | s0 = peg$FAILED; 1221 | } 1222 | } else { 1223 | peg$currPos = s0; 1224 | s0 = peg$FAILED; 1225 | } 1226 | } else { 1227 | peg$currPos = s0; 1228 | s0 = peg$FAILED; 1229 | } 1230 | } else { 1231 | peg$currPos = s0; 1232 | s0 = peg$FAILED; 1233 | } 1234 | 1235 | return s0; 1236 | } 1237 | 1238 | function peg$parseDefaultValueAssign() { 1239 | var s0, s1, s2, s3, s4, s5; 1240 | 1241 | s0 = peg$currPos; 1242 | s1 = peg$parse_(); 1243 | if (s1 !== peg$FAILED) { 1244 | if (input.charCodeAt(peg$currPos) === 61) { 1245 | s2 = peg$c45; 1246 | peg$currPos++; 1247 | } else { 1248 | s2 = peg$FAILED; 1249 | if (peg$silentFails === 0) { 1250 | peg$fail(peg$c46); 1251 | } 1252 | } 1253 | if (s2 !== peg$FAILED) { 1254 | s3 = peg$parse_(); 1255 | if (s3 !== peg$FAILED) { 1256 | s4 = peg$parseDefaultValue(); 1257 | if (s4 !== peg$FAILED) { 1258 | s5 = peg$parse_(); 1259 | if (s5 !== peg$FAILED) { 1260 | peg$savedPos = s0; 1261 | s1 = peg$c47(s4); 1262 | s0 = s1; 1263 | } else { 1264 | peg$currPos = s0; 1265 | s0 = peg$FAILED; 1266 | } 1267 | } else { 1268 | peg$currPos = s0; 1269 | s0 = peg$FAILED; 1270 | } 1271 | } else { 1272 | peg$currPos = s0; 1273 | s0 = peg$FAILED; 1274 | } 1275 | } else { 1276 | peg$currPos = s0; 1277 | s0 = peg$FAILED; 1278 | } 1279 | } else { 1280 | peg$currPos = s0; 1281 | s0 = peg$FAILED; 1282 | } 1283 | 1284 | return s0; 1285 | } 1286 | 1287 | function peg$parseArrayEle() { 1288 | var s0; 1289 | 1290 | s0 = peg$parseString(); 1291 | if (s0 === peg$FAILED) { 1292 | s0 = peg$parseNumber(); 1293 | } 1294 | 1295 | return s0; 1296 | } 1297 | 1298 | function peg$parseArrays() { 1299 | var s0, s1, s2, s3, s4, s5, s6, s7; 1300 | 1301 | s0 = peg$currPos; 1302 | s1 = peg$parseArrayEle(); 1303 | if (s1 !== peg$FAILED) { 1304 | s2 = peg$parse_(); 1305 | if (s2 !== peg$FAILED) { 1306 | s3 = []; 1307 | s4 = peg$currPos; 1308 | if (input.charCodeAt(peg$currPos) === 44) { 1309 | s5 = peg$c48; 1310 | peg$currPos++; 1311 | } else { 1312 | s5 = peg$FAILED; 1313 | if (peg$silentFails === 0) { 1314 | peg$fail(peg$c49); 1315 | } 1316 | } 1317 | if (s5 !== peg$FAILED) { 1318 | s6 = peg$parse_(); 1319 | if (s6 !== peg$FAILED) { 1320 | s7 = peg$parseArrayEle(); 1321 | if (s7 !== peg$FAILED) { 1322 | s5 = [s5, s6, s7]; 1323 | s4 = s5; 1324 | } else { 1325 | peg$currPos = s4; 1326 | s4 = peg$FAILED; 1327 | } 1328 | } else { 1329 | peg$currPos = s4; 1330 | s4 = peg$FAILED; 1331 | } 1332 | } else { 1333 | peg$currPos = s4; 1334 | s4 = peg$FAILED; 1335 | } 1336 | if (s4 !== peg$FAILED) { 1337 | while (s4 !== peg$FAILED) { 1338 | s3.push(s4); 1339 | s4 = peg$currPos; 1340 | if (input.charCodeAt(peg$currPos) === 44) { 1341 | s5 = peg$c48; 1342 | peg$currPos++; 1343 | } else { 1344 | s5 = peg$FAILED; 1345 | if (peg$silentFails === 0) { 1346 | peg$fail(peg$c49); 1347 | } 1348 | } 1349 | if (s5 !== peg$FAILED) { 1350 | s6 = peg$parse_(); 1351 | if (s6 !== peg$FAILED) { 1352 | s7 = peg$parseArrayEle(); 1353 | if (s7 !== peg$FAILED) { 1354 | s5 = [s5, s6, s7]; 1355 | s4 = s5; 1356 | } else { 1357 | peg$currPos = s4; 1358 | s4 = peg$FAILED; 1359 | } 1360 | } else { 1361 | peg$currPos = s4; 1362 | s4 = peg$FAILED; 1363 | } 1364 | } else { 1365 | peg$currPos = s4; 1366 | s4 = peg$FAILED; 1367 | } 1368 | } 1369 | } else { 1370 | s3 = peg$FAILED; 1371 | } 1372 | if (s3 !== peg$FAILED) { 1373 | peg$savedPos = s0; 1374 | s1 = peg$c50(s1, s3); 1375 | s0 = s1; 1376 | } else { 1377 | peg$currPos = s0; 1378 | s0 = peg$FAILED; 1379 | } 1380 | } else { 1381 | peg$currPos = s0; 1382 | s0 = peg$FAILED; 1383 | } 1384 | } else { 1385 | peg$currPos = s0; 1386 | s0 = peg$FAILED; 1387 | } 1388 | 1389 | return s0; 1390 | } 1391 | 1392 | function peg$parseDefaultValue() { 1393 | var s0, s1, s2, s3, s4, s5, s6, s7, s8; 1394 | 1395 | s0 = peg$parseArrays(); 1396 | if (s0 === peg$FAILED) { 1397 | s0 = peg$parseArrayEle(); 1398 | if (s0 === peg$FAILED) { 1399 | s0 = peg$currPos; 1400 | if (input.charCodeAt(peg$currPos) === 91) { 1401 | s1 = peg$c16; 1402 | peg$currPos++; 1403 | } else { 1404 | s1 = peg$FAILED; 1405 | if (peg$silentFails === 0) { 1406 | peg$fail(peg$c17); 1407 | } 1408 | } 1409 | if (s1 !== peg$FAILED) { 1410 | s2 = peg$parse_(); 1411 | if (s2 !== peg$FAILED) { 1412 | s3 = peg$parseDefaultValue(); 1413 | if (s3 !== peg$FAILED) { 1414 | s4 = []; 1415 | s5 = peg$currPos; 1416 | if (input.charCodeAt(peg$currPos) === 44) { 1417 | s6 = peg$c48; 1418 | peg$currPos++; 1419 | } else { 1420 | s6 = peg$FAILED; 1421 | if (peg$silentFails === 0) { 1422 | peg$fail(peg$c49); 1423 | } 1424 | } 1425 | if (s6 !== peg$FAILED) { 1426 | s7 = peg$parse_(); 1427 | if (s7 !== peg$FAILED) { 1428 | s8 = peg$parseDefaultValue(); 1429 | if (s8 !== peg$FAILED) { 1430 | s6 = [s6, s7, s8]; 1431 | s5 = s6; 1432 | } else { 1433 | peg$currPos = s5; 1434 | s5 = peg$FAILED; 1435 | } 1436 | } else { 1437 | peg$currPos = s5; 1438 | s5 = peg$FAILED; 1439 | } 1440 | } else { 1441 | peg$currPos = s5; 1442 | s5 = peg$FAILED; 1443 | } 1444 | while (s5 !== peg$FAILED) { 1445 | s4.push(s5); 1446 | s5 = peg$currPos; 1447 | if (input.charCodeAt(peg$currPos) === 44) { 1448 | s6 = peg$c48; 1449 | peg$currPos++; 1450 | } else { 1451 | s6 = peg$FAILED; 1452 | if (peg$silentFails === 0) { 1453 | peg$fail(peg$c49); 1454 | } 1455 | } 1456 | if (s6 !== peg$FAILED) { 1457 | s7 = peg$parse_(); 1458 | if (s7 !== peg$FAILED) { 1459 | s8 = peg$parseDefaultValue(); 1460 | if (s8 !== peg$FAILED) { 1461 | s6 = [s6, s7, s8]; 1462 | s5 = s6; 1463 | } else { 1464 | peg$currPos = s5; 1465 | s5 = peg$FAILED; 1466 | } 1467 | } else { 1468 | peg$currPos = s5; 1469 | s5 = peg$FAILED; 1470 | } 1471 | } else { 1472 | peg$currPos = s5; 1473 | s5 = peg$FAILED; 1474 | } 1475 | } 1476 | if (s4 !== peg$FAILED) { 1477 | s5 = peg$parse_(); 1478 | if (s5 !== peg$FAILED) { 1479 | if (input.charCodeAt(peg$currPos) === 93) { 1480 | s6 = peg$c18; 1481 | peg$currPos++; 1482 | } else { 1483 | s6 = peg$FAILED; 1484 | if (peg$silentFails === 0) { 1485 | peg$fail(peg$c19); 1486 | } 1487 | } 1488 | if (s6 !== peg$FAILED) { 1489 | peg$savedPos = s0; 1490 | s1 = peg$c51(s3, s4); 1491 | s0 = s1; 1492 | } else { 1493 | peg$currPos = s0; 1494 | s0 = peg$FAILED; 1495 | } 1496 | } else { 1497 | peg$currPos = s0; 1498 | s0 = peg$FAILED; 1499 | } 1500 | } else { 1501 | peg$currPos = s0; 1502 | s0 = peg$FAILED; 1503 | } 1504 | } else { 1505 | peg$currPos = s0; 1506 | s0 = peg$FAILED; 1507 | } 1508 | } else { 1509 | peg$currPos = s0; 1510 | s0 = peg$FAILED; 1511 | } 1512 | } else { 1513 | peg$currPos = s0; 1514 | s0 = peg$FAILED; 1515 | } 1516 | } 1517 | } 1518 | 1519 | return s0; 1520 | } 1521 | 1522 | function peg$parseComment() { 1523 | var s0, s1, s2, s3, s4, s5, s6; 1524 | 1525 | s0 = peg$currPos; 1526 | s1 = peg$parse_(); 1527 | if (s1 !== peg$FAILED) { 1528 | if (input.substr(peg$currPos, 2) === peg$c52) { 1529 | s2 = peg$c52; 1530 | peg$currPos += 2; 1531 | } else { 1532 | s2 = peg$FAILED; 1533 | if (peg$silentFails === 0) { 1534 | peg$fail(peg$c53); 1535 | } 1536 | } 1537 | if (s2 !== peg$FAILED) { 1538 | s3 = peg$parse_(); 1539 | if (s3 !== peg$FAILED) { 1540 | s4 = peg$parseAnyWithoutLB(); 1541 | if (s4 !== peg$FAILED) { 1542 | s5 = []; 1543 | s6 = peg$parseLB(); 1544 | if (s6 !== peg$FAILED) { 1545 | while (s6 !== peg$FAILED) { 1546 | s5.push(s6); 1547 | s6 = peg$parseLB(); 1548 | } 1549 | } else { 1550 | s5 = peg$FAILED; 1551 | } 1552 | if (s5 !== peg$FAILED) { 1553 | peg$savedPos = s0; 1554 | s1 = peg$c54(s4); 1555 | s0 = s1; 1556 | } else { 1557 | peg$currPos = s0; 1558 | s0 = peg$FAILED; 1559 | } 1560 | } else { 1561 | peg$currPos = s0; 1562 | s0 = peg$FAILED; 1563 | } 1564 | } else { 1565 | peg$currPos = s0; 1566 | s0 = peg$FAILED; 1567 | } 1568 | } else { 1569 | peg$currPos = s0; 1570 | s0 = peg$FAILED; 1571 | } 1572 | } else { 1573 | peg$currPos = s0; 1574 | s0 = peg$FAILED; 1575 | } 1576 | if (s0 === peg$FAILED) { 1577 | s0 = peg$currPos; 1578 | s1 = peg$parse_(); 1579 | if (s1 !== peg$FAILED) { 1580 | s2 = peg$parseCommentStart(); 1581 | if (s2 !== peg$FAILED) { 1582 | s3 = peg$parseAnyWithoutCommentEnd(); 1583 | if (s3 !== peg$FAILED) { 1584 | s4 = peg$parseCommentEnd(); 1585 | if (s4 !== peg$FAILED) { 1586 | s5 = []; 1587 | s6 = peg$parseLB(); 1588 | while (s6 !== peg$FAILED) { 1589 | s5.push(s6); 1590 | s6 = peg$parseLB(); 1591 | } 1592 | if (s5 !== peg$FAILED) { 1593 | peg$savedPos = s0; 1594 | s1 = peg$c55(s3); 1595 | s0 = s1; 1596 | } else { 1597 | peg$currPos = s0; 1598 | s0 = peg$FAILED; 1599 | } 1600 | } else { 1601 | peg$currPos = s0; 1602 | s0 = peg$FAILED; 1603 | } 1604 | } else { 1605 | peg$currPos = s0; 1606 | s0 = peg$FAILED; 1607 | } 1608 | } else { 1609 | peg$currPos = s0; 1610 | s0 = peg$FAILED; 1611 | } 1612 | } else { 1613 | peg$currPos = s0; 1614 | s0 = peg$FAILED; 1615 | } 1616 | } 1617 | 1618 | return s0; 1619 | } 1620 | 1621 | function peg$parseCommentStart() { 1622 | var s0, s1, s2, s3; 1623 | 1624 | s0 = peg$currPos; 1625 | if (peg$c56.test(input.charAt(peg$currPos))) { 1626 | s1 = input.charAt(peg$currPos); 1627 | peg$currPos++; 1628 | } else { 1629 | s1 = peg$FAILED; 1630 | if (peg$silentFails === 0) { 1631 | peg$fail(peg$c57); 1632 | } 1633 | } 1634 | if (s1 !== peg$FAILED) { 1635 | s2 = []; 1636 | if (peg$c58.test(input.charAt(peg$currPos))) { 1637 | s3 = input.charAt(peg$currPos); 1638 | peg$currPos++; 1639 | } else { 1640 | s3 = peg$FAILED; 1641 | if (peg$silentFails === 0) { 1642 | peg$fail(peg$c59); 1643 | } 1644 | } 1645 | if (s3 !== peg$FAILED) { 1646 | while (s3 !== peg$FAILED) { 1647 | s2.push(s3); 1648 | if (peg$c58.test(input.charAt(peg$currPos))) { 1649 | s3 = input.charAt(peg$currPos); 1650 | peg$currPos++; 1651 | } else { 1652 | s3 = peg$FAILED; 1653 | if (peg$silentFails === 0) { 1654 | peg$fail(peg$c59); 1655 | } 1656 | } 1657 | } 1658 | } else { 1659 | s2 = peg$FAILED; 1660 | } 1661 | if (s2 !== peg$FAILED) { 1662 | s1 = [s1, s2]; 1663 | s0 = s1; 1664 | } else { 1665 | peg$currPos = s0; 1666 | s0 = peg$FAILED; 1667 | } 1668 | } else { 1669 | peg$currPos = s0; 1670 | s0 = peg$FAILED; 1671 | } 1672 | 1673 | return s0; 1674 | } 1675 | 1676 | function peg$parseCommentEnd() { 1677 | var s0, s1, s2; 1678 | 1679 | s0 = peg$currPos; 1680 | s1 = []; 1681 | if (peg$c58.test(input.charAt(peg$currPos))) { 1682 | s2 = input.charAt(peg$currPos); 1683 | peg$currPos++; 1684 | } else { 1685 | s2 = peg$FAILED; 1686 | if (peg$silentFails === 0) { 1687 | peg$fail(peg$c59); 1688 | } 1689 | } 1690 | if (s2 !== peg$FAILED) { 1691 | while (s2 !== peg$FAILED) { 1692 | s1.push(s2); 1693 | if (peg$c58.test(input.charAt(peg$currPos))) { 1694 | s2 = input.charAt(peg$currPos); 1695 | peg$currPos++; 1696 | } else { 1697 | s2 = peg$FAILED; 1698 | if (peg$silentFails === 0) { 1699 | peg$fail(peg$c59); 1700 | } 1701 | } 1702 | } 1703 | } else { 1704 | s1 = peg$FAILED; 1705 | } 1706 | if (s1 !== peg$FAILED) { 1707 | if (peg$c56.test(input.charAt(peg$currPos))) { 1708 | s2 = input.charAt(peg$currPos); 1709 | peg$currPos++; 1710 | } else { 1711 | s2 = peg$FAILED; 1712 | if (peg$silentFails === 0) { 1713 | peg$fail(peg$c57); 1714 | } 1715 | } 1716 | if (s2 !== peg$FAILED) { 1717 | s1 = [s1, s2]; 1718 | s0 = s1; 1719 | } else { 1720 | peg$currPos = s0; 1721 | s0 = peg$FAILED; 1722 | } 1723 | } else { 1724 | peg$currPos = s0; 1725 | s0 = peg$FAILED; 1726 | } 1727 | 1728 | return s0; 1729 | } 1730 | 1731 | function peg$parseAnyWithoutCommentEnd() { 1732 | var s0, s1, s2, s3, s4; 1733 | 1734 | s0 = peg$currPos; 1735 | s1 = []; 1736 | s2 = peg$currPos; 1737 | s3 = peg$currPos; 1738 | peg$silentFails++; 1739 | if (input.substr(peg$currPos, 2) === peg$c60) { 1740 | s4 = peg$c60; 1741 | peg$currPos += 2; 1742 | } else { 1743 | s4 = peg$FAILED; 1744 | if (peg$silentFails === 0) { 1745 | peg$fail(peg$c61); 1746 | } 1747 | } 1748 | peg$silentFails--; 1749 | if (s4 === peg$FAILED) { 1750 | s3 = void 0; 1751 | } else { 1752 | peg$currPos = s3; 1753 | s3 = peg$FAILED; 1754 | } 1755 | if (s3 !== peg$FAILED) { 1756 | if (input.length > peg$currPos) { 1757 | s4 = input.charAt(peg$currPos); 1758 | peg$currPos++; 1759 | } else { 1760 | s4 = peg$FAILED; 1761 | if (peg$silentFails === 0) { 1762 | peg$fail(peg$c62); 1763 | } 1764 | } 1765 | if (s4 !== peg$FAILED) { 1766 | s3 = [s3, s4]; 1767 | s2 = s3; 1768 | } else { 1769 | peg$currPos = s2; 1770 | s2 = peg$FAILED; 1771 | } 1772 | } else { 1773 | peg$currPos = s2; 1774 | s2 = peg$FAILED; 1775 | } 1776 | while (s2 !== peg$FAILED) { 1777 | s1.push(s2); 1778 | s2 = peg$currPos; 1779 | s3 = peg$currPos; 1780 | peg$silentFails++; 1781 | if (input.substr(peg$currPos, 2) === peg$c60) { 1782 | s4 = peg$c60; 1783 | peg$currPos += 2; 1784 | } else { 1785 | s4 = peg$FAILED; 1786 | if (peg$silentFails === 0) { 1787 | peg$fail(peg$c61); 1788 | } 1789 | } 1790 | peg$silentFails--; 1791 | if (s4 === peg$FAILED) { 1792 | s3 = void 0; 1793 | } else { 1794 | peg$currPos = s3; 1795 | s3 = peg$FAILED; 1796 | } 1797 | if (s3 !== peg$FAILED) { 1798 | if (input.length > peg$currPos) { 1799 | s4 = input.charAt(peg$currPos); 1800 | peg$currPos++; 1801 | } else { 1802 | s4 = peg$FAILED; 1803 | if (peg$silentFails === 0) { 1804 | peg$fail(peg$c62); 1805 | } 1806 | } 1807 | if (s4 !== peg$FAILED) { 1808 | s3 = [s3, s4]; 1809 | s2 = s3; 1810 | } else { 1811 | peg$currPos = s2; 1812 | s2 = peg$FAILED; 1813 | } 1814 | } else { 1815 | peg$currPos = s2; 1816 | s2 = peg$FAILED; 1817 | } 1818 | } 1819 | if (s1 !== peg$FAILED) { 1820 | peg$savedPos = s0; 1821 | s1 = peg$c63(s1); 1822 | } 1823 | s0 = s1; 1824 | 1825 | return s0; 1826 | } 1827 | 1828 | function peg$parseString() { 1829 | var s0, s1, s2, s3; 1830 | 1831 | s0 = peg$currPos; 1832 | if (input.charCodeAt(peg$currPos) === 34) { 1833 | s1 = peg$c64; 1834 | peg$currPos++; 1835 | } else { 1836 | s1 = peg$FAILED; 1837 | if (peg$silentFails === 0) { 1838 | peg$fail(peg$c65); 1839 | } 1840 | } 1841 | if (s1 !== peg$FAILED) { 1842 | s2 = []; 1843 | if (peg$c66.test(input.charAt(peg$currPos))) { 1844 | s3 = input.charAt(peg$currPos); 1845 | peg$currPos++; 1846 | } else { 1847 | s3 = peg$FAILED; 1848 | if (peg$silentFails === 0) { 1849 | peg$fail(peg$c67); 1850 | } 1851 | } 1852 | if (s3 !== peg$FAILED) { 1853 | while (s3 !== peg$FAILED) { 1854 | s2.push(s3); 1855 | if (peg$c66.test(input.charAt(peg$currPos))) { 1856 | s3 = input.charAt(peg$currPos); 1857 | peg$currPos++; 1858 | } else { 1859 | s3 = peg$FAILED; 1860 | if (peg$silentFails === 0) { 1861 | peg$fail(peg$c67); 1862 | } 1863 | } 1864 | } 1865 | } else { 1866 | s2 = peg$FAILED; 1867 | } 1868 | if (s2 !== peg$FAILED) { 1869 | if (input.charCodeAt(peg$currPos) === 34) { 1870 | s3 = peg$c64; 1871 | peg$currPos++; 1872 | } else { 1873 | s3 = peg$FAILED; 1874 | if (peg$silentFails === 0) { 1875 | peg$fail(peg$c65); 1876 | } 1877 | } 1878 | if (s3 !== peg$FAILED) { 1879 | peg$savedPos = s0; 1880 | s1 = peg$c68(s2); 1881 | s0 = s1; 1882 | } else { 1883 | peg$currPos = s0; 1884 | s0 = peg$FAILED; 1885 | } 1886 | } else { 1887 | peg$currPos = s0; 1888 | s0 = peg$FAILED; 1889 | } 1890 | } else { 1891 | peg$currPos = s0; 1892 | s0 = peg$FAILED; 1893 | } 1894 | 1895 | return s0; 1896 | } 1897 | 1898 | function peg$parseNumber() { 1899 | var s0, s1; 1900 | 1901 | s0 = peg$currPos; 1902 | s1 = peg$parseFloat(); 1903 | if (s1 !== peg$FAILED) { 1904 | peg$savedPos = s0; 1905 | s1 = peg$c69(s1); 1906 | } 1907 | s0 = s1; 1908 | if (s0 === peg$FAILED) { 1909 | s0 = peg$parseInterger(); 1910 | } 1911 | 1912 | return s0; 1913 | } 1914 | 1915 | function peg$parseDIGIT() { 1916 | var s0; 1917 | 1918 | if (peg$c70.test(input.charAt(peg$currPos))) { 1919 | s0 = input.charAt(peg$currPos); 1920 | peg$currPos++; 1921 | } else { 1922 | s0 = peg$FAILED; 1923 | if (peg$silentFails === 0) { 1924 | peg$fail(peg$c71); 1925 | } 1926 | } 1927 | 1928 | return s0; 1929 | } 1930 | 1931 | function peg$parseFloat_Exponent() { 1932 | var s0, s1, s2, s3, s4; 1933 | 1934 | s0 = peg$currPos; 1935 | if (peg$c72.test(input.charAt(peg$currPos))) { 1936 | s1 = input.charAt(peg$currPos); 1937 | peg$currPos++; 1938 | } else { 1939 | s1 = peg$FAILED; 1940 | if (peg$silentFails === 0) { 1941 | peg$fail(peg$c73); 1942 | } 1943 | } 1944 | if (s1 !== peg$FAILED) { 1945 | if (peg$c74.test(input.charAt(peg$currPos))) { 1946 | s2 = input.charAt(peg$currPos); 1947 | peg$currPos++; 1948 | } else { 1949 | s2 = peg$FAILED; 1950 | if (peg$silentFails === 0) { 1951 | peg$fail(peg$c75); 1952 | } 1953 | } 1954 | if (s2 === peg$FAILED) { 1955 | s2 = null; 1956 | } 1957 | if (s2 !== peg$FAILED) { 1958 | s3 = []; 1959 | s4 = peg$parseDIGIT(); 1960 | if (s4 !== peg$FAILED) { 1961 | while (s4 !== peg$FAILED) { 1962 | s3.push(s4); 1963 | s4 = peg$parseDIGIT(); 1964 | } 1965 | } else { 1966 | s3 = peg$FAILED; 1967 | } 1968 | if (s3 !== peg$FAILED) { 1969 | peg$savedPos = s0; 1970 | s1 = peg$c76(s1, s2, s3); 1971 | s0 = s1; 1972 | } else { 1973 | peg$currPos = s0; 1974 | s0 = peg$FAILED; 1975 | } 1976 | } else { 1977 | peg$currPos = s0; 1978 | s0 = peg$FAILED; 1979 | } 1980 | } else { 1981 | peg$currPos = s0; 1982 | s0 = peg$FAILED; 1983 | } 1984 | 1985 | return s0; 1986 | } 1987 | 1988 | function peg$parseFloat() { 1989 | var s0, s1, s2, s3, s4, s5; 1990 | 1991 | s0 = peg$currPos; 1992 | if (peg$c74.test(input.charAt(peg$currPos))) { 1993 | s1 = input.charAt(peg$currPos); 1994 | peg$currPos++; 1995 | } else { 1996 | s1 = peg$FAILED; 1997 | if (peg$silentFails === 0) { 1998 | peg$fail(peg$c75); 1999 | } 2000 | } 2001 | if (s1 === peg$FAILED) { 2002 | s1 = null; 2003 | } 2004 | if (s1 !== peg$FAILED) { 2005 | s2 = []; 2006 | s3 = peg$parseDIGIT(); 2007 | while (s3 !== peg$FAILED) { 2008 | s2.push(s3); 2009 | s3 = peg$parseDIGIT(); 2010 | } 2011 | if (s2 !== peg$FAILED) { 2012 | if (input.charCodeAt(peg$currPos) === 46) { 2013 | s3 = peg$c77; 2014 | peg$currPos++; 2015 | } else { 2016 | s3 = peg$FAILED; 2017 | if (peg$silentFails === 0) { 2018 | peg$fail(peg$c78); 2019 | } 2020 | } 2021 | if (s3 !== peg$FAILED) { 2022 | s4 = []; 2023 | s5 = peg$parseDIGIT(); 2024 | if (s5 !== peg$FAILED) { 2025 | while (s5 !== peg$FAILED) { 2026 | s4.push(s5); 2027 | s5 = peg$parseDIGIT(); 2028 | } 2029 | } else { 2030 | s4 = peg$FAILED; 2031 | } 2032 | if (s4 !== peg$FAILED) { 2033 | s5 = peg$parseFloat_Exponent(); 2034 | if (s5 === peg$FAILED) { 2035 | s5 = null; 2036 | } 2037 | if (s5 !== peg$FAILED) { 2038 | s1 = [s1, s2, s3, s4, s5]; 2039 | s0 = s1; 2040 | } else { 2041 | peg$currPos = s0; 2042 | s0 = peg$FAILED; 2043 | } 2044 | } else { 2045 | peg$currPos = s0; 2046 | s0 = peg$FAILED; 2047 | } 2048 | } else { 2049 | peg$currPos = s0; 2050 | s0 = peg$FAILED; 2051 | } 2052 | } else { 2053 | peg$currPos = s0; 2054 | s0 = peg$FAILED; 2055 | } 2056 | } else { 2057 | peg$currPos = s0; 2058 | s0 = peg$FAILED; 2059 | } 2060 | if (s0 === peg$FAILED) { 2061 | s0 = peg$currPos; 2062 | if (peg$c74.test(input.charAt(peg$currPos))) { 2063 | s1 = input.charAt(peg$currPos); 2064 | peg$currPos++; 2065 | } else { 2066 | s1 = peg$FAILED; 2067 | if (peg$silentFails === 0) { 2068 | peg$fail(peg$c75); 2069 | } 2070 | } 2071 | if (s1 === peg$FAILED) { 2072 | s1 = null; 2073 | } 2074 | if (s1 !== peg$FAILED) { 2075 | s2 = []; 2076 | s3 = peg$parseDIGIT(); 2077 | if (s3 !== peg$FAILED) { 2078 | while (s3 !== peg$FAILED) { 2079 | s2.push(s3); 2080 | s3 = peg$parseDIGIT(); 2081 | } 2082 | } else { 2083 | s2 = peg$FAILED; 2084 | } 2085 | if (s2 !== peg$FAILED) { 2086 | s3 = peg$parseFloat_Exponent(); 2087 | if (s3 !== peg$FAILED) { 2088 | s1 = [s1, s2, s3]; 2089 | s0 = s1; 2090 | } else { 2091 | peg$currPos = s0; 2092 | s0 = peg$FAILED; 2093 | } 2094 | } else { 2095 | peg$currPos = s0; 2096 | s0 = peg$FAILED; 2097 | } 2098 | } else { 2099 | peg$currPos = s0; 2100 | s0 = peg$FAILED; 2101 | } 2102 | } 2103 | 2104 | return s0; 2105 | } 2106 | 2107 | function peg$parseInterger() { 2108 | var s0, s1, s2, s3; 2109 | 2110 | s0 = peg$currPos; 2111 | if (peg$c74.test(input.charAt(peg$currPos))) { 2112 | s1 = input.charAt(peg$currPos); 2113 | peg$currPos++; 2114 | } else { 2115 | s1 = peg$FAILED; 2116 | if (peg$silentFails === 0) { 2117 | peg$fail(peg$c75); 2118 | } 2119 | } 2120 | if (s1 === peg$FAILED) { 2121 | s1 = null; 2122 | } 2123 | if (s1 !== peg$FAILED) { 2124 | s2 = []; 2125 | s3 = peg$parseDIGIT(); 2126 | if (s3 !== peg$FAILED) { 2127 | while (s3 !== peg$FAILED) { 2128 | s2.push(s3); 2129 | s3 = peg$parseDIGIT(); 2130 | } 2131 | } else { 2132 | s2 = peg$FAILED; 2133 | } 2134 | if (s2 !== peg$FAILED) { 2135 | peg$savedPos = s0; 2136 | s1 = peg$c79(s1, s2); 2137 | s0 = s1; 2138 | } else { 2139 | peg$currPos = s0; 2140 | s0 = peg$FAILED; 2141 | } 2142 | } else { 2143 | peg$currPos = s0; 2144 | s0 = peg$FAILED; 2145 | } 2146 | 2147 | return s0; 2148 | } 2149 | 2150 | function peg$parseWord() { 2151 | var s0, s1, s2; 2152 | 2153 | s0 = peg$currPos; 2154 | s1 = []; 2155 | s2 = peg$parseCharacter(); 2156 | if (s2 !== peg$FAILED) { 2157 | while (s2 !== peg$FAILED) { 2158 | s1.push(s2); 2159 | s2 = peg$parseCharacter(); 2160 | } 2161 | } else { 2162 | s1 = peg$FAILED; 2163 | } 2164 | if (s1 !== peg$FAILED) { 2165 | peg$savedPos = s0; 2166 | s1 = peg$c80(s1); 2167 | } 2168 | s0 = s1; 2169 | 2170 | return s0; 2171 | } 2172 | 2173 | function peg$parseCharacter() { 2174 | var s0; 2175 | 2176 | if (peg$c81.test(input.charAt(peg$currPos))) { 2177 | s0 = input.charAt(peg$currPos); 2178 | peg$currPos++; 2179 | } else { 2180 | s0 = peg$FAILED; 2181 | if (peg$silentFails === 0) { 2182 | peg$fail(peg$c82); 2183 | } 2184 | } 2185 | 2186 | return s0; 2187 | } 2188 | 2189 | function peg$parseWS() { 2190 | var s0, s1; 2191 | 2192 | peg$silentFails++; 2193 | if (peg$c84.test(input.charAt(peg$currPos))) { 2194 | s0 = input.charAt(peg$currPos); 2195 | peg$currPos++; 2196 | } else { 2197 | s0 = peg$FAILED; 2198 | if (peg$silentFails === 0) { 2199 | peg$fail(peg$c85); 2200 | } 2201 | } 2202 | peg$silentFails--; 2203 | if (s0 === peg$FAILED) { 2204 | s1 = peg$FAILED; 2205 | if (peg$silentFails === 0) { 2206 | peg$fail(peg$c83); 2207 | } 2208 | } 2209 | 2210 | return s0; 2211 | } 2212 | 2213 | function peg$parse_() { 2214 | var s0, s1; 2215 | 2216 | peg$silentFails++; 2217 | s0 = []; 2218 | s1 = peg$parseWS(); 2219 | while (s1 !== peg$FAILED) { 2220 | s0.push(s1); 2221 | s1 = peg$parseWS(); 2222 | } 2223 | peg$silentFails--; 2224 | if (s0 === peg$FAILED) { 2225 | s1 = peg$FAILED; 2226 | if (peg$silentFails === 0) { 2227 | peg$fail(peg$c86); 2228 | } 2229 | } 2230 | 2231 | return s0; 2232 | } 2233 | 2234 | function peg$parse__() { 2235 | var s0, s1; 2236 | 2237 | peg$silentFails++; 2238 | s0 = []; 2239 | s1 = peg$parseWS(); 2240 | if (s1 !== peg$FAILED) { 2241 | while (s1 !== peg$FAILED) { 2242 | s0.push(s1); 2243 | s1 = peg$parseWS(); 2244 | } 2245 | } else { 2246 | s0 = peg$FAILED; 2247 | } 2248 | peg$silentFails--; 2249 | if (s0 === peg$FAILED) { 2250 | s1 = peg$FAILED; 2251 | if (peg$silentFails === 0) { 2252 | peg$fail(peg$c87); 2253 | } 2254 | } 2255 | 2256 | return s0; 2257 | } 2258 | 2259 | function peg$parseLB() { 2260 | var s0; 2261 | 2262 | if (peg$c88.test(input.charAt(peg$currPos))) { 2263 | s0 = input.charAt(peg$currPos); 2264 | peg$currPos++; 2265 | } else { 2266 | s0 = peg$FAILED; 2267 | if (peg$silentFails === 0) { 2268 | peg$fail(peg$c89); 2269 | } 2270 | } 2271 | 2272 | return s0; 2273 | } 2274 | 2275 | function peg$parseAnyWithoutTerminator() { 2276 | var s0, s1; 2277 | 2278 | s0 = []; 2279 | if (peg$c90.test(input.charAt(peg$currPos))) { 2280 | s1 = input.charAt(peg$currPos); 2281 | peg$currPos++; 2282 | } else { 2283 | s1 = peg$FAILED; 2284 | if (peg$silentFails === 0) { 2285 | peg$fail(peg$c91); 2286 | } 2287 | } 2288 | while (s1 !== peg$FAILED) { 2289 | s0.push(s1); 2290 | if (peg$c90.test(input.charAt(peg$currPos))) { 2291 | s1 = input.charAt(peg$currPos); 2292 | peg$currPos++; 2293 | } else { 2294 | s1 = peg$FAILED; 2295 | if (peg$silentFails === 0) { 2296 | peg$fail(peg$c91); 2297 | } 2298 | } 2299 | } 2300 | 2301 | return s0; 2302 | } 2303 | 2304 | function peg$parseAnyWithoutLB() { 2305 | var s0, s1; 2306 | 2307 | s0 = []; 2308 | if (peg$c92.test(input.charAt(peg$currPos))) { 2309 | s1 = input.charAt(peg$currPos); 2310 | peg$currPos++; 2311 | } else { 2312 | s1 = peg$FAILED; 2313 | if (peg$silentFails === 0) { 2314 | peg$fail(peg$c93); 2315 | } 2316 | } 2317 | while (s1 !== peg$FAILED) { 2318 | s0.push(s1); 2319 | if (peg$c92.test(input.charAt(peg$currPos))) { 2320 | s1 = input.charAt(peg$currPos); 2321 | peg$currPos++; 2322 | } else { 2323 | s1 = peg$FAILED; 2324 | if (peg$silentFails === 0) { 2325 | peg$fail(peg$c93); 2326 | } 2327 | } 2328 | } 2329 | 2330 | return s0; 2331 | } 2332 | 2333 | function peg$parseAny() { 2334 | var s0, s1; 2335 | 2336 | s0 = []; 2337 | if (input.length > peg$currPos) { 2338 | s1 = input.charAt(peg$currPos); 2339 | peg$currPos++; 2340 | } else { 2341 | s1 = peg$FAILED; 2342 | if (peg$silentFails === 0) { 2343 | peg$fail(peg$c62); 2344 | } 2345 | } 2346 | while (s1 !== peg$FAILED) { 2347 | s0.push(s1); 2348 | if (input.length > peg$currPos) { 2349 | s1 = input.charAt(peg$currPos); 2350 | peg$currPos++; 2351 | } else { 2352 | s1 = peg$FAILED; 2353 | if (peg$silentFails === 0) { 2354 | peg$fail(peg$c62); 2355 | } 2356 | } 2357 | } 2358 | 2359 | return s0; 2360 | } 2361 | 2362 | peg$result = peg$startRuleFunction(); 2363 | 2364 | if (peg$result !== peg$FAILED && peg$currPos === input.length) { 2365 | return peg$result; 2366 | } else { 2367 | if (peg$result !== peg$FAILED && peg$currPos < input.length) { 2368 | peg$fail(peg$endExpectation()); 2369 | } 2370 | 2371 | throw peg$buildStructuredError( 2372 | peg$maxFailExpected, 2373 | peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, 2374 | peg$maxFailPos < input.length 2375 | ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) 2376 | : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) 2377 | ); 2378 | } 2379 | } 2380 | 2381 | return { 2382 | SyntaxError: peg$SyntaxError, 2383 | parse : peg$parse 2384 | }; 2385 | }; 2386 | if (typeof NEJ !== 'undefined') { 2387 | NEJ.define(jsonBean); 2388 | } else if (typeof(module) !== 'undefined') { 2389 | module.exports = jsonBean(); 2390 | } else { 2391 | return jsonBean(); 2392 | } 2393 | 2394 | })(); 2395 | -------------------------------------------------------------------------------- /src/jsonbean.pegjs: -------------------------------------------------------------------------------- 1 | Start 2 | = items:(Statement)+ { 3 | var result = { 4 | name: '', 5 | description: '', 6 | attributes: [] 7 | } 8 | items.forEach(function(item){ 9 | if (item === null) return; 10 | if (item.class) { 11 | result.name = item.class 12 | result.description = item.description 13 | } else if (item.name) { 14 | result.attributes.push(item) 15 | } 16 | }) 17 | return result 18 | } 19 | 20 | CommentOrLB = Comment / LB+ { 21 | return "" // ignore 22 | } 23 | 24 | Statement 25 | = _ ct:(Comment*) _ Annotations? _ f:(FieldModifiers) __ dt:(DataType) __ name:(Character+) _ arr:TraditionalArray? dv:(DefaultValueAssign?) ";" _ cl:CommentOrLB { 26 | if(f){ 27 | return null; 28 | } 29 | return { 30 | name: name.join(''), 31 | typeName: dt.name, 32 | isArray: dt.isArray || (arr?true:false), 33 | defaultValue: dv == null?"":dv, 34 | description: ct.join('') || cl 35 | } 36 | } 37 | / ct:(Comment*) _ Annotations? _ "public" __ "class" __ clazz:(Word) AnyWithoutTerminator "{" LB* { 38 | return { 39 | description: ct.join(''), 40 | class: clazz 41 | } 42 | } 43 | / _ "}" _ LB* { 44 | return null 45 | } 46 | / a:(AnyWithoutLB) LB+ { 47 | return null 48 | } 49 | 50 | TraditionalArray = "[" _ i:Interger? _ "]" {return true;} 51 | 52 | DataType 53 | = "List" _ "<" w:(Word) _ ">" { 54 | return { 55 | name: w, 56 | isArray: true 57 | } 58 | } 59 | / w:(Word) arr:TraditionalArray { 60 | return { 61 | name: w, 62 | isArray: true 63 | } 64 | } 65 | / w:(Word) { 66 | return { 67 | name: w, 68 | isArray: false 69 | } 70 | } 71 | 72 | // Annotations, now only support MarkerAnnotation, see https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-Annotation 73 | Annotations 74 | = MarkerAnnotation 75 | 76 | MarkerAnnotation 77 | = _ "@" AnyWithoutLB _ LB* 78 | 79 | 80 | // Consistent with https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.3.1.1 81 | DataTypeModifier 82 | = "private" 83 | / "protected" 84 | / "public" 85 | 86 | StaticFields 87 | = "static" 88 | 89 | FinalFields 90 | = "final" 91 | 92 | TransientFields 93 | = "transient" 94 | 95 | VolatileFields 96 | = "volatile" 97 | 98 | FieldModifiers 99 | = DataTypeModifier? s:(StaticFields?) f:(FinalFields?) TransientFields? VolatileFields?{ 100 | /* 101 | 如果把一个member定义为final意味着无法改变,此时该member不应导入 102 | 而static则是类的,也不应该导入 103 | 如: 有些时候JavaBean会implements一些interface(如Seriablizable),就需要定义一个static final long 的serialVersionUID,显然这个member是不应该被导入的 104 | */ 105 | return f === "final" || s === 'static'; 106 | } 107 | 108 | 109 | 110 | DefaultValueAssign 111 | = _ "=" _ d:DefaultValue _ { 112 | return d; 113 | 114 | } 115 | 116 | ArrayEle = String/Number 117 | 118 | Arrays = 119 | s:(ArrayEle) _ ss:("," _ (ArrayEle))+ { 120 | var temp = ss.map(function(item){ return item[2];}); 121 | temp.unshift(s); 122 | return { 123 | notArray: true, 124 | value:temp 125 | }; 126 | } 127 | 128 | DefaultValue 129 | = 130 | Arrays //Pegjs 有bug。 没有回溯,所以数组类型必须在元素之前 131 | / ArrayEle 132 | / "[" _ v:DefaultValue vv:("," _ DefaultValue)* _ "]"{ 133 | // 支持一下几种: 134 | // [1,2,3] 135 | // [[1,2,3],[4,5,6]] 136 | // ["test", "it",["a", "test]]; parser中对这种差异性不处理,不进行类型检查。 137 | if(v.notArray){ 138 | return v.value; 139 | }else{ 140 | var temp = new Array(); 141 | temp.push(v); 142 | if(vv.length == 0){ 143 | return temp; 144 | }else{ 145 | var vvTemp = vv.map(function(item){return item[2]}); 146 | return temp.concat(vvTemp); 147 | } 148 | } 149 | } 150 | / [^;]*{ 151 | return ""; 152 | } 153 | 154 | 155 | Comment 156 | = _ "//" _ c:(AnyWithoutLB) LB+ { // 因为都是包在一个java class 中, 所以一定有LB 157 | return c.join('') 158 | } 159 | / _ CommentStart c:(AnyWithoutCommentEnd) CommentEnd LB* { 160 | return c 161 | } 162 | 163 | CommentStart 164 | = [/][*]+ 165 | 166 | CommentEnd 167 | = [*]+[/] 168 | 169 | AnyWithoutCommentEnd 170 | = c:(!"*/" .)* { 171 | var comments = c.map(function(item){ 172 | return item[1] 173 | }).join('').split('\n') 174 | var result = [] 175 | comments.forEach(function(comment){ 176 | var trimResult = comment.trim().replace(/^\*+|\*+$/g, '').trim() 177 | if (trimResult) { 178 | result.push(trimResult) 179 | } 180 | }) 181 | return result.join(', ') 182 | } 183 | 184 | String = '"' s:[^\"]+ '"'{ 185 | return s.join(''); 186 | } 187 | 188 | Number = f:Float{ 189 | return f.map(function(i){ if(i instanceof Array) {return i.join('')} else return i}).join(''); 190 | } 191 | / Interger 192 | 193 | DIGIT = [0-9] 194 | 195 | Float_Exponent = e:[eE] s:[+-]? ds:DIGIT+ { 196 | return e + (s==null? "" : s) + ds.join(''); 197 | } 198 | 199 | Float = [+-]? i:DIGIT* "." ds:DIGIT+ e:Float_Exponent? 200 | / [+-]? d:DIGIT+ e:Float_Exponent 201 | 202 | Interger = s:([+-])? d:(DIGIT+){ 203 | return (s=='-' ? -1: 1) * Number(d.join('')); 204 | } 205 | 206 | Word 207 | = l:(Character+) { 208 | return l.join(''); 209 | } 210 | 211 | 212 | Character 213 | = [a-zA-Z0-9] 214 | 215 | WS "Whitespace" 216 | = [ \t] 217 | 218 | _ "Zero or more whitespaces" 219 | = WS* 220 | 221 | __ "One or more whitespaces" 222 | = WS+ 223 | 224 | LB 225 | = [\r\n] 226 | 227 | AnyWithoutTerminator 228 | = [^;{]* 229 | 230 | AnyWithoutLB 231 | = [^\r\n]* 232 | Any 233 | = .* 234 | --------------------------------------------------------------------------------