+公園
+@1+2==3;
+
+console.log("122");@
+
+山頂
+`;
+const PROG = p.rule();
+const SEGMENT = p.rule();
+const IMPORT = p.rule();
+const IMPORTS = p.rule();
+const SEMICOLON = p.rule();
+const EXCAPE_AT = p.rule();
+const NOT_AT_TEXT = p.rule();
+const CONTENT = p.rule();
+let doubleMinus = { type: 'Punctuator', value: '--' };
+let doubleMinus2 = p.str('--');
+const TERM = p.rule();
+function applySegment(input) {
+ let unpackedInnerExprs = input[1].map((x) => { return x.text; });
+ return ["%exprs", unpackedInnerExprs];
+}
+function applySemiColon(value) {
+ return value.text;
+}
+function applyParts(first, second) {
+ return ["%clo", first, second[1]];
+}
+function applyComment(value) {
+ return [value.text];
+}
+function applyImport(input) {
+ let importTail = input[1].map(x => x.text);
+ return ["import"].concat(importTail);
+}
+;
+/*
+function applyImportComment(input: [Token<TokenKind>,Token<TokenKind>[],
+ tkTree, Token<TokenKind.Comment>]) : tkTree{
+ let importTail = input[1].map(x=>x.text);
+ let comment = [input[3].text];
+ return ["import"].concat(importTail).concat(comment);
+};*/
+function applyImports(input) {
+ let resultBody = [input[0]].concat(input[1]);
+ let resultWrapper = ["%import", resultBody];
+ return resultWrapper;
+}
+;
+function applyNotAtText(value) {
+ if (value.text == "\\\@") {
+ return '@';
+ }
+ else {
+ return value.text;
+ }
+}
+;
+function applyText(input) {
+ return ["%text", input];
+}
+;
+function applyContent(input) {
+ return ["%content", input];
+}
+;
+function applySpaceNL(value) {
+ return value.text;
+}
+/**
+ * IMPORTEE: Number, Op, Paren, Id, Str, Comment,
+ */
+let IMPORTEE = p.alt(p.tok(TokenKind.Number), p.tok(TokenKind.Op), p.tok(TokenKind.Paren), p.tok(TokenKind.Id), p.tok(TokenKind.Str), p.tok(TokenKind.SpaceNL), p.tok(TokenKind.Comment));
+let NOT_AT = p.alt(p.tok(TokenKind.Seperator), p.tok(TokenKind.Semicolon), p.tok(TokenKind.Number), p.tok(TokenKind.ExcapeAt), p.tok(TokenKind.Op), p.tok(TokenKind.Paren), p.tok(TokenKind.SpaceNL), p.tok(TokenKind.Id), p.tok(TokenKind.Str), p.tok(TokenKind.Comment));
+/**
+ * PROG : IMPORTS '---' CONTENT;
+ */
+PROG.setPattern(p.lrec_sc(IMPORTS, p.seq(p.str('---'), CONTENT), applyParts));
+/**
+ * NOT_AT_TEXT : NOT_AT
+ */
+NOT_AT_TEXT.setPattern(p.apply(NOT_AT, applyNotAtText));
+IMPORTS.setPattern(p.apply(p.seq(IMPORT, p.rep(IMPORT)), applyImports));
+/**
+ * IMPORT :
+ * 'import' IMPORTEE* SEMICOLON |
+ * COMMENT |
+ */
+IMPORT.setPattern(p.alt(p.apply(p.seq(p.str('import'), p.rep_sc(IMPORTEE), SEMICOLON), applyImport), p.apply(p.tok(TokenKind.Comment), applyComment), p.apply(p.tok(TokenKind.SpaceNL), applySpaceNL)));
+/**
+ * SEMICOLON : ';';
+ */
+SEMICOLON.setPattern(p.apply(p.tok(TokenKind.Semicolon), applySemiColon));
+/**
+ * SEGMENT : '@' NOT_AT* '@' |
+ * (NOT_AT_TEXT | EXCAPE_AT)*
+ */
+SEGMENT.setPattern(p.alt(p.apply(p.rep_sc(NOT_AT_TEXT), applyText), p.apply(p.seq(p.str('@'), p.rep(NOT_AT), p.str('@')), applySegment)));
+/**
+ * CONTENT : SEGMENT*
+ */
+CONTENT.setPattern(p.apply(p.rep(SEGMENT), applyContent));
+let tree = p.expectSingleResult(p.expectEOF(PROG.parse(lexer.parse(inputTxt))));
+console.log("RESULT=" + tkTreeToSExp(tree));