1 module pegged.examples.json; 2 3 import pegged.grammar; 4 5 mixin(grammar(` 6 JSON: 7 JSONObject < :'{' (Pair (:',' Pair)*)? :'}' 8 Pair < String :':' Value 9 Array < :'[' (Value (:',' Value)* )? :']' 10 11 Value < String 12 / Number 13 / JSONObject 14 / Array 15 / True 16 / False 17 / Null 18 True <- "true" 19 False <- "false" 20 Null <- "null" 21 22 String <~ :doublequote Char* :doublequote 23 Char <~ backslash doublequote 24 / backslash backslash 25 / backslash [bfnrt] 26 / backslash 'u' Hex Hex Hex Hex 27 / (!doublequote .) 28 29 Number <~ '0' 30 / [1-9] Digit* ('.' Digit*)? 31 Digit <- [0-9] 32 Hex <- [0-9A-Fa-f] 33 `)); 34 enum example2 = ` 35 { 36 "Number": 42, 37 "Decimal": 123.456, 38 "String": "abc", 39 "NullString": "", 40 "Escape": "\uAAAA\n\\Hello", 41 "Array" : [0,1,2], 42 "Array2": [0, [0,1,2], "abc"], 43 "Obj" : { "Member":0, "Member":[0,1,2] }, 44 "True" : true, 45 "False" : false, 46 "Null" : null, 47 "Empty" : {} 48 }`; 49 50 enum example3 = 51 `{ 52 "glossary": { 53 "title": "example glossary", 54 "GlossDiv": { 55 "title": "S", 56 "GlossList": { 57 "GlossEntry": { 58 "ID": "SGML", 59 "SortAs": "SGML", 60 "GlossTerm": "Standard Generalized Markup Language", 61 "Acronym": "SGML", 62 "Abbrev": "ISO 8879:1986", 63 "GlossDef": { 64 "para": "A meta-markup language, used to create markup languages such as DocBook.", 65 "GlossSeeAlso": ["GML", "XML"] 66 }, 67 "GlossSee": "markup" 68 } 69 } 70 } 71 } 72 }`; 73 74 enum example4 = 75 `{"web-app": { 76 "servlet": [ 77 { 78 "servlet-name": "cofaxCDS", 79 "servlet-class": "org.cofax.cds.CDSServlet", 80 "init-param": { 81 "configGlossary:installationAt": "Philadelphia, PA", 82 "configGlossary:adminEmail": "ksm@pobox.com", 83 "configGlossary:poweredBy": "Cofax", 84 "configGlossary:poweredByIcon": "/images/cofax.gif", 85 "configGlossary:staticPath": "/content/static", 86 "templateProcessorClass": "org.cofax.WysiwygTemplate", 87 "templateLoaderClass": "org.cofax.FilesTemplateLoader", 88 "templatePath": "templates", 89 "templateOverridePath": "", 90 "defaultListTemplate": "listTemplate.htm", 91 "defaultFileTemplate": "articleTemplate.htm", 92 "useJSP": false, 93 "jspListTemplate": "listTemplate.jsp", 94 "jspFileTemplate": "articleTemplate.jsp", 95 "cachePackageTagsTrack": 200, 96 "cachePackageTagsStore": 200, 97 "cachePackageTagsRefresh": 60, 98 "cacheTemplatesTrack": 100, 99 "cacheTemplatesStore": 50, 100 "cacheTemplatesRefresh": 15, 101 "cachePagesTrack": 200, 102 "cachePagesStore": 100, 103 "cachePagesRefresh": 10, 104 "cachePagesDirtyRead": 10, 105 "searchEngineListTemplate": "forSearchEnginesList.htm", 106 "searchEngineFileTemplate": "forSearchEngines.htm", 107 "searchEngineRobotsDb": "WEB-INF/robots.db", 108 "useDataStore": true, 109 "dataStoreClass": "org.cofax.SqlDataStore", 110 "redirectionClass": "org.cofax.SqlRedirection", 111 "dataStoreName": "cofax", 112 "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver", 113 "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon", 114 "dataStoreUser": "sa", 115 "dataStorePassword": "dataStoreTestQuery", 116 "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';", 117 "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log", 118 "dataStoreInitConns": 10, 119 "dataStoreMaxConns": 100, 120 "dataStoreConnUsageLimit": 100, 121 "dataStoreLogLevel": "debug", 122 "maxUrlLength": 500}}, 123 { 124 "servlet-name": "cofaxEmail", 125 "servlet-class": "org.cofax.cds.EmailServlet", 126 "init-param": { 127 "mailHost": "mail1", 128 "mailHostOverride": "mail2"}}, 129 { 130 "servlet-name": "cofaxAdmin", 131 "servlet-class": "org.cofax.cds.AdminServlet"}, 132 133 { 134 "servlet-name": "fileServlet", 135 "servlet-class": "org.cofax.cds.FileServlet"}, 136 { 137 "servlet-name": "cofaxTools", 138 "servlet-class": "org.cofax.cms.CofaxToolsServlet", 139 "init-param": { 140 "templatePath": "toolstemplates/", 141 "log": 1, 142 "logLocation": "/usr/local/tomcat/logs/CofaxTools.log", 143 "logMaxSize": "", 144 "dataLog": 1, 145 "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log", 146 "dataLogMaxSize": "", 147 "removePageCache": "/content/admin/remove?cache=pages&id=", 148 "removeTemplateCache": "/content/admin/remove?cache=templates&id=", 149 "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder", 150 "lookInContext": 1, 151 "adminGroupID": 4, 152 "betaServer": true}}], 153 "servlet-mapping": { 154 "cofaxCDS": "/", 155 "cofaxEmail": "/cofaxutil/aemail/*", 156 "cofaxAdmin": "/admin/*", 157 "fileServlet": "/static/*", 158 "cofaxTools": "/tools/*"}, 159 160 "taglib": { 161 "taglib-uri": "cofax.tld", 162 "taglib-location": "/WEB-INF/tlds/cofax.tld"}}} 163 `; 164 165 unittest 166 { 167 assert(JSON(example2).successful); 168 assert(JSON(example3).successful); 169 assert(JSON(example4).successful); 170 }