Skip to content

Commit

Permalink
Merge pull request #1929 from kujirahand/error_report_string_close_tag
Browse files Browse the repository at this point in the history
文字列終端記号を忘れてもエラーが表示されない問題を修正 #1925
  • Loading branch information
kujirahand authored Feb 6, 2025
2 parents 3bdb776 + 5aadc58 commit 27ea63c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 1 addition & 2 deletions core/src/nako3.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Ast, AstBlocks } from './nako_ast.mjs'
// parser / lexer
import { NakoParser } from './nako_parser3.mjs'
import { NakoLexer } from './nako_lexer.mjs'
import { NakoPrepare } from './nako_prepare.mjs'
import { NakoPrepare, ConvertResult } from './nako_prepare.mjs'
import { NakoGen, generateJS, NakoGenOptions, NakoGenResult } from './nako_gen.mjs'
import { convertInlineIndent, convertIndentSyntax } from './nako_indent_inline.mjs'
import { convertDNCL } from './nako_from_dncl.mjs'
Expand Down Expand Up @@ -396,7 +396,6 @@ export class NakoCompiler {
const tokenizationSourceMapping = new SourceMappingOfTokenization(code.length, preprocessed)
const indentationSyntaxSourceMapping = new SourceMappingOfIndentSyntax(code, [], [])
const offsetToLineColumn = new OffsetToLineColumn(code)

// トークン分割
let tokens: Token[]
try {
Expand Down
1 change: 1 addition & 0 deletions core/src/nako_lex_rules.mts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ function cbString (beginTag: string, closeTag: string, src: string): NakoLexPars
if (i < 0) { // not found
res = src
src = ''
throw new Error(`『${beginTag}』で始めた文字列の終端記号『${closeTag}』が見つかりません。`)
} else {
res = src.substring(0, i)
src = src.substring(i + closeTag.length)
Expand Down
12 changes: 9 additions & 3 deletions core/src/nako_prepare.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ReplaceHistory {
}
}

class ConvertResult {
export class ConvertResult {
public text: string
public sourcePosition: number
constructor (text: string, sourcePosition: number) {
Expand Down Expand Up @@ -186,7 +186,7 @@ export class NakoPrepare {
let i = 0
while (i < src.getText().length) {
const c = src.getText().charAt(i)
const ch2 = src.getText().substr(i, 2)
const ch2 = src.getText().substring(i, i + 2)
// 文字列のとき
if (flagStr) {
if (c === endOfStr) {
Expand Down Expand Up @@ -308,7 +308,13 @@ export class NakoPrepare {
left = i
}
if (flagStr || flagStr2) {
res.push(new ConvertResult(str + endOfStr, src.getSourcePosition(left)))
if (endOfStr === '"' || endOfStr === '\'' || endOfStr === '」' || endOfStr === '』') {
// throw new Error(`(${startLineOfStr+1}行目) 文字列が記号『${endOfStr}』で閉じられていません。`)
// ここではエラーはリポートしない nako_lex_rule.js でエラーをリポートする
} else {
// 文字列以外のコメントなどは自動で閉じる
res.push(new ConvertResult(str + endOfStr, src.getSourcePosition(left)))
}
}
return res
}
Expand Down

0 comments on commit 27ea63c

Please sign in to comment.