-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,154 additions
and
746 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const app = require('./dist/app.js'); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
import { TypeScript } from './grammars'; | ||
import { NGrammar } from './parser/grammarNormalized'; | ||
import { normalizeGrammar } from './parser/grammarNormalizer'; | ||
import * as path from 'path'; | ||
import { promises as fs } from 'fs'; | ||
import { parseDocument } from './parser/parser'; | ||
|
||
const grammars: Record<string, NGrammar | undefined> = { | ||
'.ts': normalizeGrammar(TypeScript.grammar), | ||
}; | ||
|
||
/** | ||
* Run simple parser | ||
* @param args -- command line arguments | ||
* @returns Promise | ||
*/ | ||
export async function run(args: string[]): Promise<void> { | ||
console.log('args: %o', args); | ||
// early out if there are not enough arguments | ||
if (args.length < 3) { | ||
console.log('usage...'); | ||
return; | ||
} | ||
|
||
const filename = args.slice(2).filter((p) => !p.startsWith('-'))[0]; | ||
if (!filename) { | ||
console.log('filename missing'); | ||
return; | ||
} | ||
|
||
const ext = path.extname(filename); | ||
const g = grammars[ext]; | ||
if (!g) { | ||
console.log(`No grammar for ${path.basename(filename)}`); | ||
return; | ||
} | ||
|
||
console.log(`File: ${path.basename(filename)} Grammar: ${g.name || g.scopeName}`); | ||
const content = await fs.readFile(filename, 'utf-8'); | ||
|
||
parseDocument(g, filename, content); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface MappedText { | ||
text: string; | ||
/** | ||
* | ||
*/ | ||
map: number[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { mapRawString } from './typescript'; | ||
|
||
describe('mappers typescript', () => { | ||
// cspell:ignore Fingerspitzengef Fingerspitzengefühl ˈfɪŋɐˌʃpɪtsənɡəˌfyːl | ||
const sample = { | ||
text: 'Fingerspitzengefühl is a German term.\nIt’s pronounced as follows: [ˈfɪŋɐˌʃpɪtsənɡəˌfyːl]', | ||
hex: '\\x46\\x69\\x6E\\x67\\x65\\x72\\x73\\x70\\x69\\x74\\x7A\\x65\\x6E\\x67\\x65\\x66\\xFC\\x68\\x6C\\x20\\x69\\x73\\x20\ | ||
\\x61\\x20\\x47\\x65\\x72\\x6D\\x61\\x6E\\x20\\x74\\x65\\x72\\x6D\\x2E\n\\x49\\x74\\u2019\\x73\\x20\\x70\\x72\\x6F\\x6E\\x6F\\x75\\x6E\ | ||
\\x63\\x65\\x64\\x20\\x61\\x73\\x20\\x66\\x6F\\x6C\\x6C\\x6F\\x77\\x73\\x3A\\x20\\x5B\\u02C8\\x66\\u026A\\u014B\\u0250\\u02CC\\u0283\ | ||
\\x70\\u026A\\x74\\x73\\u0259\\x6E\\u0261\\u0259\\u02CC\\x66\\x79\\u02D0\\x6C\\x5D', | ||
mixed: 'Fingerspitzengef\\xFChl is a German term.\nIt\\u2019s pronounced as follows: \ | ||
[\\u02C8f\\u026A\\u014B\\u0250\\u02CC\\u0283p\\u026Ats\\u0259n\\u0261\\u0259\\u02CCfy\\u02D0l]', | ||
}; | ||
|
||
const emojis = { | ||
text: 'Emojis 😁🥳🙈🙉🙊', | ||
unicode: 'Emojis \\uD83D\\uDE01\\uD83E\\uDD73\\uD83D\\uDE48\\uD83D\\uDE49\\uD83D\\uDE4A', | ||
codePoint: 'Emojis \\u{1F601}\\u{1F973}\\u{1F648}\\u{1F649}\\u{1F64A}', | ||
}; | ||
|
||
test.each` | ||
text | expected | ||
${''} | ${''} | ||
${'hello'} | ${'hello'} | ||
${'hello\\x20there'} | ${'hello\x20there'} | ||
${'hello\\u0020there'} | ${'hello\u0020there'} | ||
${'hello\\u{020}there'} | ${'hello\u{020}there'} | ||
${'a\\tb'} | ${'a\tb'} | ||
${'a\\rb'} | ${'a\rb'} | ||
${'a\\nb'} | ${'a\nb'} | ||
${'a\\dd'} | ${'add'} | ||
${'a\\x'} | ${'ax'} | ||
${'a\\xy'} | ${'axy'} | ||
${'a\\x9h'} | ${'ax9h'} | ||
${'a\\u9h'} | ${'au9h'} | ||
${'a\\u{9h}'} | ${'au{9h}'} | ||
${sample.text} | ${sample.text} | ||
${sample.hex} | ${sample.text} | ||
${sample.mixed} | ${sample.text} | ||
${emojis.text} | ${emojis.text} | ||
${emojis.unicode} | ${emojis.text} | ||
${emojis.codePoint} | ${emojis.text} | ||
`('mapRawString $# [$text]', ({ text, expected }) => { | ||
const r = mapRawString(text); | ||
expect(toCharCodes(r.text)).toBe(toCharCodes(expected)); | ||
expect(r.text).toBe(expected); | ||
}); | ||
|
||
test.each` | ||
text | expected | ||
${''} | ${[]} | ||
${'hello'} | ${[]} | ||
${'hello\\x20there'} | ${[5, 5, 9, 6, 14, 11]} | ||
${'hello\\u0020there'} | ${[5, 5, 11, 6, 16, 11]} | ||
${'hello\\u{020}there'} | ${[5, 5, 12, 6, 17, 11]} | ||
`('mapRawString map $# [$text]', ({ text, expected }) => { | ||
const r = mapRawString(text); | ||
expect(r.map).toEqual(expected); | ||
}); | ||
}); | ||
|
||
function toCharCodes(s: string): string { | ||
return s | ||
.split('') | ||
.map((a) => ('000' + a.charCodeAt(0).toString(16)).slice(-4)) | ||
.join(', '); | ||
} |
Oops, something went wrong.