Skip to content

Commit

Permalink
Fix CBM BASIC V2 analyze text logic (#1607)
Browse files Browse the repository at this point in the history
  • Loading branch information
gandarez committed Feb 12, 2021
1 parent 9348b60 commit aa0c35b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pygments/lexers/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ class CbmBasicV2Lexer(RegexLexer):
]
}

def analyse_text(self, text):
def analyse_text(text):
# if it starts with a line number, it shouldn't be a "modern" Basic
# like VB.net
if re.match(r'\d+', text):
if re.match(r'^\d+', text):
return 0.2


Expand Down
2 changes: 1 addition & 1 deletion pygments/lexers/forth.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ def analyse_text(text):
"""Forth uses : COMMAND ; quite a lot in a single line, so we're trying
to find that."""
if re.search('\n:[^\n]+;\n', text):
return 0.1
return 0.3
14 changes: 0 additions & 14 deletions tests/test_ecl.py

This file was deleted.

16 changes: 16 additions & 0 deletions tests/test_guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import pytest

from pygments.lexers import guess_lexer, get_lexer_by_name
from pygments.lexers.basic import CbmBasicV2Lexer
from pygments.lexers.ecl import ECLLexer

TESTDIR = Path(__file__).resolve().parent

Expand Down Expand Up @@ -166,3 +168,17 @@ def test_guess_c_lexer():
'''
lexer = guess_lexer(code)
assert lexer.__class__.__name__ == 'CLexer'


def test_cbmbasicv2_analyse_text():
text = "10 PRINT \"PART 1\""
res = CbmBasicV2Lexer.analyse_text(text)
assert res == 0.2


def test_ecl_analyze_text():
text = r"""
STRING ABC -> size32_t lenAbc, const char * abc;
"""
res = ECLLexer.analyse_text(text)
assert res == 0.01

0 comments on commit aa0c35b

Please sign in to comment.