o-development / ldo

Monorepo for Linked Data Objects (ldo)
MIT License
23 stars 5 forks source link

Infer `dataType` from value set #31

Open jeswr opened 3 months ago

jeswr commented 3 months ago

For instance I would expect the following to have a boolean datatype

PREFIX sh: <http://www.w3.org/ns/shacl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX shsh: <http://www.w3.org/ns/shacl-shacl#>

shsh:ShapeShape {
      sh:deactivated ["true"^^xsd:boolean "false"^^xsd:boolean]?;
}

rather than erroring with

SyntaxError: Type expected. (27:19)
  25 |         "@id": string;
  26 |     };
> 27 |     deactivated?: ;
     |                   ^
  28 |     class?: {
  29 |         "@id": string;
  30 |     }[];
    at Kq (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:23:498)
    at xz (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:25:794)
    at Object.Cz [as parse] (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:25:1194)
    at parse4 (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/index.mjs:22117:24)
    at async coreFormat (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/index.mjs:22607:7)
    at async formatWithCursor (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/index.mjs:22809:14)
    at async Module.format2 (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/index.mjs:24194:25)
    at async /home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/@ldo/cli/dist/build.js:40:128
    at async Promise.all (index 3)
    at async /home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/@ldo/cli/dist/build.js:33:9 {
  loc: { start: { line: 27, column: 19 }, end: { line: 27, column: 19 } },
  cause: Vm: Type expected.
      at RB (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:21:119402)
      at YB (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:21:122980)
      at YU (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:21:191880)
      at $q (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:21:203680)
      at Xq (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:21:203346)
      at file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:25:1160
      at Zq (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:23:652)
      at Object.Cz [as parse] (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/plugins/typescript.mjs:25:1132)
      at parse4 (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/index.mjs:22117:24)
      at async coreFormat (file:///home/jeswr/Documents/GitHub/jeswr/reasoning-test/shacl2shex/node_modules/prettier/index.mjs:22607:7) {
    fileName: 'estree.ts',
    location: {
      start: { line: 27, column: 18, offset: 592 },
      end: { line: 27, column: 18, offset: 592 }
    }
  },
  codeFrame: '\x1B[0m \x1B[90m 25 |\x1B[39m         \x1B[32m"@id"\x1B[39m\x1B[33m:\x1B[39m string\x1B[33m;\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 26 |\x1B[39m     }\x1B[33m;\x1B[39m\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 27 |\x1B[39m     deactivated\x1B[33m?\x1B[39m\x1B[33m:\x1B[39m \x1B[33m;\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m    |\x1B[39m                   \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 28 |\x1B[39m     \x1B[36mclass\x1B[39m\x1B[33m?\x1B[39m\x1B[33m:\x1B[39m {\x1B[0m\n' +
    '\x1B[0m \x1B[90m 29 |\x1B[39m         \x1B[32m"@id"\x1B[39m\x1B[33m:\x1B[39m string\x1B[33m;\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 30 |\x1B[39m     }[]\x1B[33m;\x1B[39m\x1B[0m'
}