Skip to content

Commit 5eb548c

Browse files
committed
added keyword file, not complete yet i think
1 parent dc94e9c commit 5eb548c

File tree

7 files changed

+222
-86
lines changed

7 files changed

+222
-86
lines changed

src/ModuleManager.ts

Whitespace-only changes.

src/channel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function createLogicalEOLChannel(ch: IChannel<ISimpleToken>, raw:string):
9797
return vCh
9898
}
9999

100-
export function createChannelExcluding(name: string, raw: string, ...ch: IChannel<IToken>[]): IChannel<IRangeToken> {
100+
export function createChannelExcluding(name: string, raw: string, ...ch: IChannel<any>[]): IChannel<IRangeToken> {
101101

102102
if (ch.length === 0) {
103103
throw new Error(`Illegal Arguments, no arguments given`)

src/keywords.ts

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
const keyWordMaps = {
3+
// added
4+
precision: { c: '\u0ff0' },
5+
integer: { c: '\u0ff1' },
6+
logical: { c: '\u0ff2' },
7+
'.true.': { c: '\u0ff3' },
8+
'.eq.': { c: '\u0ff4' },
9+
'.le.': { c: '\u0ff5' },
10+
'.lt.': { c: '\u0ff6' },
11+
'.ne.': { c: '\u0ff7' },
12+
'.and.': { c: '\u0ff8' },
13+
'.or.': { c: '\u0ff9' },
14+
'.ge.': { c: '\u0ffa' },
15+
'.not.': { c: '\u0ffb' },
16+
'.gt.': { c: '\u0ffc' },
17+
18+
// added becaus of this engine
19+
ws: { c: '\u0f00' },
20+
// (not complete) list of keywords from the f77.g4
21+
//
22+
access: { c: '\u0100' },
23+
assign: { c: '\u0101' },
24+
backspace: { c: '\u0102' },
25+
blank: { c: '\u0103' },
26+
block: { c: '\u0104' },
27+
call: { c: '\u0105' },
28+
character: { c: '\u0106' },
29+
close: { c: '\u0107' },
30+
colon: { c: '\u0108' },
31+
comma: { c: '\u0109' },
32+
common: { c: '\u0110' },
33+
continue: { c: '\u0111' },
34+
data: { c: '\u0112' },
35+
dimension: { c: '\u0113' },
36+
do: { c: '\u0114' },
37+
dollar: { c: '\u0115' },
38+
double: { c: '\u0116' },
39+
else: { c: '\u0117' },
40+
elseif: { c: '\u0118' },
41+
end: { c: '\u0119' },
42+
enddo: { c: '\u0120' },
43+
endfile: { c: '\u0121' },
44+
endif: { c: '\u0122' },
45+
entry: { c: '\u0101' },
46+
equivalence: { c: '\u0123' },
47+
err: { c: '\u0124' },
48+
exist: { c: '\u0125' },
49+
external: { c: '\u0126' },
50+
file: { c: '\u0127' },
51+
fmt: { c: '\u0128' },
52+
form: { c: '\u0129' },
53+
format: { c: '\u0130' },
54+
formatted: { c: '\u0131' },
55+
function: { c: '\u0132' },
56+
go: { c: '\u0133' },
57+
goto: { c: '\u0134' },
58+
icon: { c: '\u0135' },
59+
if: { c: '\u0136' },
60+
implicit: { c: '\u0137' },
61+
inquire: { c: '\u0138' },
62+
intrinsic: { c: '\u0139' },
63+
iostart: { c: '\u0140' },
64+
iostat: { c: '\u0141' },
65+
label: { c: '\u0142' },
66+
let: { c: '\u0143' },
67+
lparen: { c: '\u0144' },
68+
minus: { c: '\u0145' },
69+
named: { c: '\u0146' },
70+
name_: { c: '\u0147' },
71+
nextrec: { c: '\u0148' },
72+
none: { c: '\u0149' },
73+
number: { c: '\u0150' },
74+
open: { c: '\u0151' },
75+
opened: { c: '\u0152' },
76+
parameter: { c: '\u0153' },
77+
pause: { c: '\u0154' },
78+
plus: { c: '\u0155' },
79+
pointer: { c: '\u0156' },
80+
position: { c: '\u0157' },
81+
program: { c: '\u0100' },
82+
print: { c: '\u0158' },
83+
read: { c: '\u0159' },
84+
return: { c: '\u0160' },
85+
rewind: { c: '\u0161' },
86+
rparen: { c: '\u0162' },
87+
save: { c: '\u0163' },
88+
sequential: { c: '\u0164' },
89+
status: { c: '\u0165' },
90+
stop: { c: '\u0166' },
91+
subroutine: { c: '\u0167' },
92+
then: { c: '\u0168' },
93+
unformatted: { c: '\u0169' },
94+
unit: { c: '\u0170' },
95+
write: { c: '\u0171' },
96+
}

src/matchers.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
'use strict'
22

33
export type TestFunc = (s: string) => RegExpMatchArray
4-
export const regexp = (s: RegExp) => line => line.match(s)
4+
export const regexp = (s: RegExp) => line => {
5+
const found = line.match(s)
6+
return found
7+
}
8+
59
export const isComment: TestFunc = (line) => {
610
const found = line.match(/^([\*Cc][^\n]*)\n?/)
711
if (found){

src/processors.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
import {
2+
import {
33
ISimpleToken,
44
IRangeToken,
5-
isRangeToken,
6-
isSimpleToken,
7-
Snippet
5+
isRangeToken,
6+
isSimpleToken,
7+
Snippet
88
} from './IToken'
99

1010
import { regexp, TestFunc, isComment } from './matchers'
@@ -84,12 +84,25 @@ export function compose<T, K>(convert: (a: K) => T) {
8484

8585
function* stream(data: T, ...fns: ((s: T) => IterableIterator<K>)[]) {
8686
const [fn, ...others] = fns
87-
for (const elt of fn(data)) {
88-
yield elt
89-
if (others.length) {
90-
yield* stream(convert(elt), ...others)
87+
const gen = fn(data)
88+
let cnt = 0
89+
let done
90+
do {
91+
const it = gen.next()
92+
done = it.done
93+
if (!done) {
94+
yield it.value
95+
if (others.length > 0) {
96+
yield* stream(convert(it.value), ...others)
97+
}
98+
cnt++
9199
}
92-
}
100+
if (cnt === 0) {
101+
if (others.length > 0) {
102+
yield* stream(data, ...others)
103+
}
104+
}
105+
} while (!done)
93106
}
94107

95108
return function* activate(gen: IterableIterator<T>): IterableIterator<K> {

src/test.ts

+22-16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
processLineContinuation,
1111
processComments,
1212
processLf,
13+
processWS,
1314
chain,
1415
// fundamental routines
1516
compose,
@@ -29,35 +30,40 @@ const mod77 = F77.createModule(fullPath)
2930
const lfChannel = createChannel('lf', tokenAsSimple)(chain(processLf))()
3031
const commentsChannel = createChannel('comms', tokenAsRange)(chain(processComments))
3132

33+
3234
export function init() {
3335

3436
mod77.load().then(mod => {
3537
const raw = mod.raw
3638
const lfc = lfChannel(raw)
3739
lfc.process()
38-
const commSprint = () => {
40+
41+
const eol = createLogicalEOLChannel(lfc, raw)
42+
eol.process()
43+
44+
const commSpring = () => {
3945
return {
4046
data:raw,
4147
slicers: lfc.tokens
4248
}
4349
}
44-
const comc = commentsChannel(commSprint)(raw)
50+
const comc = commentsChannel(commSpring)(raw)
4551
comc.process()
46-
const
47-
52+
53+
const src = createChannelExcluding('source',raw, eol, comc)
54+
src.process()
55+
56+
const wsSpring = () => {
57+
return {
58+
data: raw,
59+
slicers: src.tokens
60+
}
61+
}
62+
const ws = createChannel('ws', tokenAsRange)(chain(processLineContinuation, processWS))(wsSpring)(raw)
63+
ws.process()
4864

49-
//wsChannel.process()
50-
//const vlfChannel = createLogicalEOLChannel(lfChannel)
51-
//vlfChannel.process()
52-
//const commChannel = createCommentsChannel(vlfChannel)
53-
//commChannel.process()
54-
//const sourceChannel = createChannelExcluding('source', vlfChannel, commChannel);
55-
//sourceChannel.process()
56-
//const whiteSpaceChannel = createWSChannel(sourceChannel);
57-
//whiteSpaceChannel.process()
58-
//channel = mod.channels.get('lf')
59-
comc.tokens.forEach((v, i, arr) => {
60-
console.log(`${`${i}`.padStart(4, '0')}: ${raw.slice(v.f, v.t + 1)}`)
65+
ws.tokens.forEach((v, i, arr) => {
66+
console.log(`${`${i}`.padStart(4, '0')}: ${raw.slice(v.f, v.t + 1)}<`)
6167
})
6268
})
6369

test.js

+76-59
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,83 @@
1-
const f77 = require('./dist')
2-
const { resolve } = require('path')
1+
const F77 = require('./dist')
32

43
const {
5-
lf,
6-
ws,
7-
createClassMatcher,
8-
createLiteralMatcher,
9-
simpleProducer, rangeProducer,
10-
createTokenEmitter,
11-
createChannel,
12-
aLoad,
13-
createLogicalEOLChannel,
14-
createCommentsChannel,
15-
createChannelExcluding,
16-
createWSChannel,
17-
mergeSort,
18-
binarySearch
19-
} = f77
20-
21-
const mod77 = f77.createModule(resolve('test/dhgeqz.f'))
22-
23-
24-
const wsMatcher = createClassMatcher(ws, '>1')
25-
const wsEmitter = createTokenEmitter(rangeProducer, wsMatcher)
26-
const wsChannel = createChannel('ws')(wsEmitter)(mod77)
27-
28-
const lfMatcher = createClassMatcher(lf)
29-
const lfEmitter = createTokenEmitter(simpleProducer, lfMatcher)
30-
const lfChannel = createChannel('lf')(lfEmitter)(mod77)
31-
32-
33-
mod77.load().then(mod => {
34-
const raw = mod.raw
35-
lfChannel.process()
36-
wsChannel.process()
37-
const vlfChannel = createLogicalEOLChannel(lfChannel)
38-
vlfChannel.process()
39-
const commChannel = createCommentsChannel(vlfChannel)
40-
commChannel.process()
41-
const sourceChannel = createChannelExcluding('source', vlfChannel, commChannel);
42-
sourceChannel.process()
43-
const whiteSpaceChannel = createWSChannel(sourceChannel);
44-
whiteSpaceChannel.process()
45-
//channel = mod.channels.get('lf')
46-
sourceChannel.tokens.forEach((v, i, arr) => {
47-
console.log(`${`${i}`.padStart(4, 0)}: ${raw.slice(v.f, v.t+1)}`)
48-
})
49-
/*
50-
const arr = [
51-
{ a: -5, pl: 'hi' },
52-
{ a: -10, pl: 'world' }
53-
]
54-
55-
const fnSort = (a, b) => a.a - b.a
56-
const sorted = mergeSort(fnSort)(arr)
57-
const found = binarySearch(fnSort)(sorted, { a: -11 })
58-
console.log(JSON.stringify(sorted), found)
59-
*/
60-
})
61-
4+
init
5+
} = F77
626

7+
const keys =`FUNCTION
8+
BLOCK
9+
SUBROUTINE
10+
END
11+
DIMENSION
12+
EQUIVALENCE
13+
COMMON
14+
POINTER
15+
IMPLICIT
16+
NONE
17+
CHARACTER
18+
PARAMETER
19+
EXTERNAL
20+
INTRINSIC
21+
SAVE
22+
DATA
23+
GO
24+
GOTO
25+
IF
26+
THEN
27+
ELSE
28+
ENDIF
29+
ELSEIF
30+
DO
31+
CONTINUE
32+
STOP
33+
ENDDO
34+
PAUSE
35+
WRITE
36+
READ
37+
PRINT
38+
OPEN
39+
FMT
40+
UNIT
41+
ERR
42+
IOSTAT
43+
FORMAT
44+
LET
45+
CALL
46+
RETURN
47+
CLOSE
48+
DOUBLE
49+
IOSTART
50+
SEQUENTIAL
51+
ICON
52+
LABEL
53+
FILE
54+
STATUS
55+
ACCESS
56+
POSITION
57+
FORM
58+
BLANK
59+
EXIST
60+
OPENED
61+
NUMBER
62+
NAMED
63+
NAME_
64+
FORMATTED
65+
UNFORMATTED
66+
NEXTREC
67+
INQUIRE
68+
BACKSPACE
69+
ENDFILE
70+
REWIND
71+
DOLLAR
72+
COMMA
73+
LPAREN
74+
RPAREN
75+
COLON
76+
ASSIGN
77+
MINUS
78+
PLUS`
6379

6480

6581

6682

83+
init()

0 commit comments

Comments
 (0)