Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CBM BASIC V2 analyze text logic #1607

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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