aboutsummaryrefslogtreecommitdiffgithub
path: root/bootstrap-parse-table.sh
blob: b0c599ab2421baaa70f72c2b5ae3b42cc1f4ba48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
set -e

[[ $# -eq 1 ]] || {
    printf 'usage: %s <parser>\n' "$0"
    printf '\n'
    printf 'will generate an empty parse table for parser.ts\n'
    exit 1
} >&2

parser=$1

[[ -f novice/assembler/parsers/$parser.ts ]] || {
    printf "error: unknown parser \`%s', sorry bud\n" "$parser" >&2
    exit 1
}

{
    printf '/* tslint:disable */\n'
    printf '// WARNING: GENERATED CODE by bootstrap-parse-table.sh\n'
    printf "import { ParseTable } from '../../lr1';\n"
    printf "import { NT, T } from '../grammars/%s';\n" "$parser"
    printf 'const table: ParseTable<NT, T> = {positions: {}, actionTable: [], gotoTable: []};\n'
    printf 'export default table;\n'
} >"novice/assembler/parsers/tables/$parser.ts"