Browse Source

Begin building parser

master
Forest Belton 3 years ago
parent
commit
6d8e768109
5 changed files with 73 additions and 6 deletions
  1. +1
    -0
      .gitignore
  2. +7
    -4
      Makefile
  3. +23
    -0
      package-lock.json
  4. +15
    -2
      package.json
  5. +27
    -0
      parser.pegjs

+ 1
- 0
.gitignore View File

@ -1,2 +1,3 @@
node_modules/ node_modules/
gbuoy.js gbuoy.js
parser.js

+ 7
- 4
Makefile View File

@ -1,4 +1,7 @@
TSFILES := index.ts $(find lib -type f -name '*.ts')
gbuoy.js: $(TSFILES)
./node_modules/.bin/tsc --outFile $@ $(TSFILES)
TSFILES := index.ts $(find lib -type f -name '*.ts')
gbuoy.js: parser.js $(TSFILES)
./node_modules/.bin/tsc --outFile $@ $(TSFILES)
parser.js: parser.pegjs
./node_modules/.bin/peggy -o $@ $<

+ 23
- 0
package-lock.json View File

@ -1,13 +1,30 @@
{ {
"name": "gbuoy", "name": "gbuoy",
"version": "1.0.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "gbuoy",
"version": "1.0.0",
"license": "MIT",
"devDependencies": { "devDependencies": {
"peggy": "^1.2.0",
"typescript": "^4.4.3" "typescript": "^4.4.3"
} }
}, },
"node_modules/peggy": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/peggy/-/peggy-1.2.0.tgz",
"integrity": "sha512-PQ+NKpAobImfMprYQtc4Egmyi29bidRGEX0kKjCU5uuW09s0Cthwqhfy7mLkwcB4VcgacE5L/ZjruD/kOPCUUw==",
"dev": true,
"bin": {
"peggy": "bin/peggy"
},
"engines": {
"node": ">=10"
}
},
"node_modules/typescript": { "node_modules/typescript": {
"version": "4.4.3", "version": "4.4.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.3.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.3.tgz",
@ -23,6 +40,12 @@
} }
}, },
"dependencies": { "dependencies": {
"peggy": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/peggy/-/peggy-1.2.0.tgz",
"integrity": "sha512-PQ+NKpAobImfMprYQtc4Egmyi29bidRGEX0kKjCU5uuW09s0Cthwqhfy7mLkwcB4VcgacE5L/ZjruD/kOPCUUw==",
"dev": true
},
"typescript": { "typescript": {
"version": "4.4.3", "version": "4.4.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.3.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.3.tgz",

+ 15
- 2
package.json View File

@ -1,5 +1,18 @@
{ {
"devDependencies": { "devDependencies": {
"peggy": "^1.2.0",
"typescript": "^4.4.3" "typescript": "^4.4.3"
}
}
},
"name": "gbuoy",
"version": "1.0.0",
"main": "gbuoy.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Forest Belton <forest@homolo.gy>",
"license": "MIT",
"description": "A 'high-level' language for the Gameboy"
}

+ 27
- 0
parser.pegjs View File

@ -0,0 +1,27 @@
// AST factories
{
const attr = (name, args) => ({ name, args })
}
// Attributes
Attrs = LATTR l:AttrList RATTR { return l }
AttrList = h:Attr t:(COMMA @Attr)* { return [h].concat(t) }
/ '' { return [] }
Attr = name:Ident args:(LPAREN @AttrArgs RPAREN)? { return attr(name, args || []) }
AttrArgs = h:AttrArg t:(COMMA @AttrArg)* { return [h].concat(t) }
/ '' { return [] }
AttrArg = Ident / Number
// Terminals
Ident = h:[a-zA-Z_] t:[0-9a-zA-Z_]* WS { return h + t.join('') }
Number = digits:[0-9]+ WS { return parseInt(digits.join(''), 10) }
// Terminal symbols
LPAREN = '(' WS
RPAREN = ')' WS
COMMA = ',' WS
LATTR = '[[' WS
RATTR = ']]' WS
// Misc
WS = [ \t\r\n]*

Loading…
Cancel
Save