-export function match1token(t: tk.Token): (m: TokenMatcheePair) => tk.Maybe<TokenMatcheePair> {
- return (m: TokenMatcheePair) => {
- if (m.remained.length == 0) {
- return { _tag: "None" };
- }
- const tokenToBeMatched = m.remained[0];
- if (tokenToBeMatched === t) {
- m.matched.push(tokenToBeMatched);
- return {
- _tag: "Some", value: {
- matched: m.matched,
- remained: m.remained.slice(1)
- }
- };
- }
- else {
- return { _tag: "None" };
- }
- }
+const lexer = p.buildLexer([
+ [true, /^\d+(\.\d+)?/g, TokenKind.Number],
+ [true, /^\;/g, TokenKind.Semicolon],
+ [true, /^[-][-][-]/g, TokenKind.Seperator],
+ [true, /^[\+\-\*\/\&\|\!\^\<\>\~\=\?]+/g, TokenKind.Op],
+ [true, /^\@+/g, TokenKind.ExprMark],
+ [true, /^[()\[\]{}]/g, TokenKind.Paren],
+ [true, /^["]([\"]|[\\].)*["]/g, TokenKind.Str],
+ [true, /^[']([\']|[\\].)*[']/g, TokenKind.Str],
+ [true, /^[()\[\]{}]/g, TokenKind.Paren],
+ [true, /^[^\s\n\t\r;]+/g, TokenKind.Id],
+ [false, /^(\s|\n|\r|\t)+/g, TokenKind.SpaceNL]
+]);
+
+/**
+ *
+ * # TEST
+ */
+const inputTxt=
+`import ast;
+---
+122`;
+
+
+const PROG = p.rule<TokenKind, tkTree>();
+const UNIT = p.rule<TokenKind, tkTree>();
+const IMPORTS = p.rule<TokenKind, tkTree>();
+const SEMICOLON = p.rule<TokenKind, tkTree>();
+
+
+let doubleMinus = { type: 'Punctuator', value: '--' };
+let doubleMinus2 = p.str('--');
+const TERM = p.rule<TokenKind, tkTree>();
+
+function applyUnit(value: Token<TokenKind.Number>): tkTree{
+ return value.text;
+}
+
+function applySemiColon(value: Token<TokenKind.Semicolon>): tkTree{
+ return value.text;
+}
+
+function applyParts(first: tkTree,
+ second: [Token<TokenKind>, tkTree]):tkTree {
+ return ["%clo", first , second[1]];
+}
+
+
+
+
+function applyImports(input: [Token<TokenKind>,Token<TokenKind>[], tkTree]):tkTree{
+ let importTail = input[1].map(x=>x.text);
+ return ["import"].concat(importTail);