Skip to content
Snippets Groups Projects
Commit c6b6ee35 authored by Fawwaz Anugrah Wiradhika Dharmasatya's avatar Fawwaz Anugrah Wiradhika Dharmasatya
Browse files

fix: handle emoji in code

parent 0a6b5161
No related merge requests found
......@@ -386,62 +386,30 @@ print(cusor.node.parent)
print(cusor.node.parent.parent)
print(cusor.node.parent.parent.parent)
print("teso")
tree = parser.parse(bytes("""
def parse_library(ctx:ElementContext)->Node|None:
# Tentukan jenis import nya
try:
import_type,import_name = ctx.name.split(" ")
if import_type == 'from':
# Import from statement
pass
except ValueErrror:
pass
class A():
def __init__(self) -> None:
pass
""",'utf-8'))
print(tree.root_node.sexp())
cusor = tree.walk()
cusor.goto_first_child()
print(cusor.node.parent)
print(cusor.node.next_sibling)
print(cusor.node)
print(cusor.node.children)
tree = parser.parse(bytes("""
def parse_library(ctx:ElementContext)->Node|None:
# Tentukan jenis import nya
try:
import_type,import_name = ctx.name.split(" ")
if import_type == 'from':
# Import from statement
pass
except ValueErrror:
pass
class A():
def __init__(self) -> None:
pass
""",'utf-8'))
query = PY_LANGUAGE.query("""
(function_definition
name: (identifier) @function.name)
""")
captures = query.captures(tree.root_node)
print("Capt",captures)
tree = parser.parse(bytes("""
@login_required
def profile():
return render_template('profile.html')
from modules import (
Log, # A class for logging messages
abort, # Function to abort the request
Delete, # Function to delete user from the database
request, # Module for handling HTTP requests
sqlite3, # SQLite database module
session, # Session handling module
redirect, # Function to redirect
Blueprint, # Blueprint for defining routes
RECAPTCHA, # Flag indicating whether reCAPTCHA is enabled
requestsPost, # Function to make POST requests
DB_USERS_ROOT, # Path to the users database
render_template, # Function to render HTML templates
RECAPTCHA_SITE_KEY, # reCAPTCHA site key
RECAPTCHA_VERIFY_URL, # reCAPTCHA verification URL
RECAPTCHA_SECRET_KEY, # reCAPTCHA secret key
RECAPTCHA_DELETE_USER, # Flag indicating whether reCAPTCHA is required for deleting user
)
""",'utf-8'))
cursor = tree.walk()
cursor.goto_first_child()
cursor.goto_last_child()
# cursor.goto_last_child()
# cursor.goto_first_child()
print("kimi")
print(cursor.node)
......
......@@ -239,9 +239,20 @@ class CFG():
while self.cursor.node.type=='return':
self.cursor.goto_next_sibling()
return self.cursor.node
elif self.cursor.node.type=='match_statement':
# Ada percabangan
# cari block node
self.cursor.goto_first_child()
# while self.cursor.node.type in ["if",":"]:
while self.cursor.node.type in ['match','comparison_operator',':']:
self.cursor.goto_next_sibling()
node = self.cursor.node
return node
else:
# Expression statement dsb
has_sibling = self.cursor.goto_next_sibling()
has_sibling = self.cursor.goto_next_sibling()
while not has_sibling and self.cursor.node.type in ["match",":"]:
has_sibling = self.cursor.goto_next_sibling()
if(not has_sibling):
# ke branch berikutnya
if not self.next_branch:
......
......@@ -58,8 +58,13 @@ class FileReader:
def search_annotation(self,files:list[str]):
project_info:ProjectInfo = ProjectInfo()
for file in files:
with open(file) as source_code:
lines = source_code.readlines()
with open(file,'rb') as source_code:
# print(file)
# print(source_code.read().decode())
# import time
# time.sleep(20)
lines = source_code.read().decode().split("\n")
# lines = source_code.readlines()
i = 0
while i < len(lines):
is_skipped = False
......
......@@ -76,6 +76,9 @@ class ServiceSanitizationAnalyzer():
# Gak ada dekorator/dekorator gak cocok
# Traverse fungsinya
while node:
# if "search" in route.name:
# print(node)
# print("KOMP",components)
# Cek detail untuk beberapa tipe node
if node.type in ['call','assignment']:
# Cek call method
......@@ -160,6 +163,9 @@ class ServiceSanitizationAnalyzer():
components += flatten_node(child.children)
# Cek tiap componentnya
child_list = flatten_node(node.children)
# if "search" in route.name:
# print(node)
# print("KOMP",components)
fun_name = ""
for child in child_list:
if child in [':',',']:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment